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 | fe676ee | 2013-11-18 13:03:38 +0000 | [diff] [blame] | 21 | % Copyright 1999-2014 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" |
| 53 | #include "MagickCore/cache-view.h" |
cristy | 6a2180c | 2013-05-27 10:28:36 +0000 | [diff] [blame] | 54 | #include "MagickCore/channel.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 55 | #include "MagickCore/color.h" |
cristy | 9b7a4fc | 2012-04-08 22:26:56 +0000 | [diff] [blame] | 56 | #include "MagickCore/colorspace-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 57 | #include "MagickCore/composite.h" |
| 58 | #include "MagickCore/composite-private.h" |
| 59 | #include "MagickCore/constitute.h" |
| 60 | #include "MagickCore/draw.h" |
| 61 | #include "MagickCore/draw-private.h" |
| 62 | #include "MagickCore/enhance.h" |
| 63 | #include "MagickCore/exception.h" |
| 64 | #include "MagickCore/exception-private.h" |
| 65 | #include "MagickCore/gem.h" |
| 66 | #include "MagickCore/geometry.h" |
| 67 | #include "MagickCore/image-private.h" |
| 68 | #include "MagickCore/list.h" |
| 69 | #include "MagickCore/log.h" |
| 70 | #include "MagickCore/monitor.h" |
| 71 | #include "MagickCore/monitor-private.h" |
| 72 | #include "MagickCore/option.h" |
| 73 | #include "MagickCore/paint.h" |
| 74 | #include "MagickCore/pixel-accessor.h" |
cristy | 35f1530 | 2012-06-07 14:59:02 +0000 | [diff] [blame] | 75 | #include "MagickCore/pixel-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 76 | #include "MagickCore/property.h" |
| 77 | #include "MagickCore/resample.h" |
| 78 | #include "MagickCore/resample-private.h" |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 79 | #include "MagickCore/resource_.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 80 | #include "MagickCore/string_.h" |
| 81 | #include "MagickCore/string-private.h" |
| 82 | #include "MagickCore/thread-private.h" |
| 83 | #include "MagickCore/token.h" |
| 84 | #include "MagickCore/transform.h" |
| 85 | #include "MagickCore/utility.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 86 | |
| 87 | /* |
| 88 | Define declarations. |
| 89 | */ |
| 90 | #define BezierQuantum 200 |
| 91 | |
| 92 | /* |
| 93 | Typedef declarations. |
| 94 | */ |
| 95 | typedef struct _EdgeInfo |
| 96 | { |
| 97 | SegmentInfo |
| 98 | bounds; |
| 99 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 100 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | scanline; |
| 102 | |
| 103 | PointInfo |
| 104 | *points; |
| 105 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 106 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 107 | number_points; |
| 108 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 109 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 110 | direction; |
| 111 | |
| 112 | MagickBooleanType |
| 113 | ghostline; |
| 114 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 115 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 116 | highwater; |
| 117 | } EdgeInfo; |
| 118 | |
| 119 | typedef struct _ElementInfo |
| 120 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 121 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 122 | cx, |
| 123 | cy, |
| 124 | major, |
| 125 | minor, |
| 126 | angle; |
| 127 | } ElementInfo; |
| 128 | |
| 129 | typedef struct _PolygonInfo |
| 130 | { |
| 131 | EdgeInfo |
| 132 | *edges; |
| 133 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 134 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 135 | number_edges; |
| 136 | } PolygonInfo; |
| 137 | |
| 138 | typedef enum |
| 139 | { |
| 140 | MoveToCode, |
| 141 | OpenCode, |
| 142 | GhostlineCode, |
| 143 | LineToCode, |
| 144 | EndCode |
| 145 | } PathInfoCode; |
| 146 | |
| 147 | typedef struct _PathInfo |
| 148 | { |
| 149 | PointInfo |
| 150 | point; |
| 151 | |
| 152 | PathInfoCode |
| 153 | code; |
| 154 | } PathInfo; |
| 155 | |
| 156 | /* |
| 157 | Forward declarations. |
| 158 | */ |
| 159 | static MagickBooleanType |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 160 | DrawStrokePolygon(Image *,const DrawInfo *,const PrimitiveInfo *, |
| 161 | ExceptionInfo *); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 162 | |
| 163 | static PrimitiveInfo |
| 164 | *TraceStrokePolygon(const DrawInfo *,const PrimitiveInfo *); |
| 165 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 166 | static size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 167 | TracePath(PrimitiveInfo *,const char *); |
| 168 | |
| 169 | static void |
| 170 | TraceArc(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), |
| 171 | TraceArcPath(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 172 | const double,const MagickBooleanType,const MagickBooleanType), |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 173 | TraceBezier(PrimitiveInfo *,const size_t), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 174 | TraceCircle(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 175 | TraceEllipse(PrimitiveInfo *,const PointInfo,const PointInfo,const PointInfo), |
| 176 | TraceLine(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 177 | TraceRectangle(PrimitiveInfo *,const PointInfo,const PointInfo), |
| 178 | TraceRoundRectangle(PrimitiveInfo *,const PointInfo,const PointInfo, |
| 179 | PointInfo), |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 180 | TraceSquareLinecap(PrimitiveInfo *,const size_t,const double); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | |
| 182 | /* |
| 183 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 184 | % % |
| 185 | % % |
| 186 | % % |
| 187 | % A c q u i r e D r a w I n f o % |
| 188 | % % |
| 189 | % % |
| 190 | % % |
| 191 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 192 | % |
| 193 | % AcquireDrawInfo() returns a DrawInfo structure properly initialized. |
| 194 | % |
| 195 | % The format of the AcquireDrawInfo method is: |
| 196 | % |
| 197 | % DrawInfo *AcquireDrawInfo(void) |
| 198 | % |
| 199 | */ |
| 200 | MagickExport DrawInfo *AcquireDrawInfo(void) |
| 201 | { |
| 202 | DrawInfo |
| 203 | *draw_info; |
| 204 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 205 | draw_info=(DrawInfo *) AcquireMagickMemory(sizeof(*draw_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 206 | if (draw_info == (DrawInfo *) NULL) |
| 207 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 208 | GetDrawInfo((ImageInfo *) NULL,draw_info); |
| 209 | return(draw_info); |
| 210 | } |
| 211 | |
| 212 | /* |
| 213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 214 | % % |
| 215 | % % |
| 216 | % % |
| 217 | % C l o n e D r a w I n f o % |
| 218 | % % |
| 219 | % % |
| 220 | % % |
| 221 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 222 | % |
anthony | 36fe175 | 2011-09-29 11:28:37 +0000 | [diff] [blame] | 223 | % CloneDrawInfo() makes a copy of the given draw_info structure. If NULL |
cristy | 430522c | 2012-09-03 00:07:16 +0000 | [diff] [blame] | 224 | % is specified, a new DrawInfo structure is created initialized to default |
| 225 | % values. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 226 | % |
| 227 | % The format of the CloneDrawInfo method is: |
| 228 | % |
| 229 | % DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 230 | % const DrawInfo *draw_info) |
| 231 | % |
| 232 | % A description of each parameter follows: |
| 233 | % |
| 234 | % o image_info: the image info. |
| 235 | % |
| 236 | % o draw_info: the draw info. |
| 237 | % |
| 238 | */ |
| 239 | MagickExport DrawInfo *CloneDrawInfo(const ImageInfo *image_info, |
| 240 | const DrawInfo *draw_info) |
| 241 | { |
| 242 | DrawInfo |
| 243 | *clone_info; |
| 244 | |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 245 | ExceptionInfo |
| 246 | *exception; |
| 247 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 248 | clone_info=(DrawInfo *) AcquireMagickMemory(sizeof(*clone_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 249 | if (clone_info == (DrawInfo *) NULL) |
| 250 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 251 | GetDrawInfo(image_info,clone_info); |
| 252 | if (draw_info == (DrawInfo *) NULL) |
| 253 | return(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 254 | exception=AcquireExceptionInfo(); |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 255 | (void) CloneString(&clone_info->primitive,draw_info->primitive); |
| 256 | (void) CloneString(&clone_info->geometry,draw_info->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | clone_info->viewbox=draw_info->viewbox; |
| 258 | clone_info->affine=draw_info->affine; |
| 259 | clone_info->gravity=draw_info->gravity; |
| 260 | clone_info->fill=draw_info->fill; |
| 261 | clone_info->stroke=draw_info->stroke; |
| 262 | clone_info->stroke_width=draw_info->stroke_width; |
| 263 | if (draw_info->fill_pattern != (Image *) NULL) |
| 264 | clone_info->fill_pattern=CloneImage(draw_info->fill_pattern,0,0,MagickTrue, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 265 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 266 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 267 | clone_info->stroke_pattern=CloneImage(draw_info->stroke_pattern,0,0, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 268 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 269 | clone_info->stroke_antialias=draw_info->stroke_antialias; |
| 270 | clone_info->text_antialias=draw_info->text_antialias; |
| 271 | clone_info->fill_rule=draw_info->fill_rule; |
| 272 | clone_info->linecap=draw_info->linecap; |
| 273 | clone_info->linejoin=draw_info->linejoin; |
| 274 | clone_info->miterlimit=draw_info->miterlimit; |
| 275 | clone_info->dash_offset=draw_info->dash_offset; |
| 276 | clone_info->decorate=draw_info->decorate; |
| 277 | clone_info->compose=draw_info->compose; |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 278 | (void) CloneString(&clone_info->text,draw_info->text); |
| 279 | (void) CloneString(&clone_info->font,draw_info->font); |
| 280 | (void) CloneString(&clone_info->metrics,draw_info->metrics); |
| 281 | (void) CloneString(&clone_info->family,draw_info->family); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 282 | clone_info->style=draw_info->style; |
| 283 | clone_info->stretch=draw_info->stretch; |
| 284 | clone_info->weight=draw_info->weight; |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 285 | (void) CloneString(&clone_info->encoding,draw_info->encoding); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 286 | clone_info->pointsize=draw_info->pointsize; |
| 287 | clone_info->kerning=draw_info->kerning; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 288 | clone_info->interline_spacing=draw_info->interline_spacing; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 289 | clone_info->interword_spacing=draw_info->interword_spacing; |
cristy | c9b1295 | 2010-03-28 01:12:28 +0000 | [diff] [blame] | 290 | clone_info->direction=draw_info->direction; |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 291 | (void) CloneString(&clone_info->density,draw_info->density); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 292 | clone_info->align=draw_info->align; |
| 293 | clone_info->undercolor=draw_info->undercolor; |
| 294 | clone_info->border_color=draw_info->border_color; |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 295 | (void) CloneString(&clone_info->server_name,draw_info->server_name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 296 | if (draw_info->dash_pattern != (double *) NULL) |
| 297 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 298 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 299 | x; |
| 300 | |
| 301 | for (x=0; draw_info->dash_pattern[x] != 0.0; x++) ; |
| 302 | clone_info->dash_pattern=(double *) AcquireQuantumMemory((size_t) x+1UL, |
| 303 | sizeof(*clone_info->dash_pattern)); |
| 304 | if (clone_info->dash_pattern == (double *) NULL) |
| 305 | ThrowFatalException(ResourceLimitFatalError, |
| 306 | "UnableToAllocateDashPattern"); |
| 307 | (void) CopyMagickMemory(clone_info->dash_pattern,draw_info->dash_pattern, |
| 308 | (size_t) (x+1)*sizeof(*clone_info->dash_pattern)); |
| 309 | } |
| 310 | clone_info->gradient=draw_info->gradient; |
| 311 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 312 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 313 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 314 | number_stops; |
| 315 | |
| 316 | number_stops=clone_info->gradient.number_stops; |
| 317 | clone_info->gradient.stops=(StopInfo *) AcquireQuantumMemory((size_t) |
| 318 | number_stops,sizeof(*clone_info->gradient.stops)); |
| 319 | if (clone_info->gradient.stops == (StopInfo *) NULL) |
| 320 | ThrowFatalException(ResourceLimitFatalError, |
| 321 | "UnableToAllocateDashPattern"); |
| 322 | (void) CopyMagickMemory(clone_info->gradient.stops, |
| 323 | draw_info->gradient.stops,(size_t) number_stops* |
| 324 | sizeof(*clone_info->gradient.stops)); |
| 325 | } |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 326 | (void) CloneString(&clone_info->clip_mask,draw_info->clip_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 327 | clone_info->bounds=draw_info->bounds; |
| 328 | clone_info->clip_units=draw_info->clip_units; |
| 329 | clone_info->render=draw_info->render; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 330 | clone_info->alpha=draw_info->alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 331 | clone_info->element_reference=draw_info->element_reference; |
| 332 | clone_info->debug=IsEventLogging(); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 333 | exception=DestroyExceptionInfo(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 334 | return(clone_info); |
| 335 | } |
| 336 | |
| 337 | /* |
| 338 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 339 | % % |
| 340 | % % |
| 341 | % % |
| 342 | + C o n v e r t P a t h T o P o l y g o n % |
| 343 | % % |
| 344 | % % |
| 345 | % % |
| 346 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 347 | % |
| 348 | % ConvertPathToPolygon() converts a path to the more efficient sorted |
| 349 | % rendering form. |
| 350 | % |
| 351 | % The format of the ConvertPathToPolygon method is: |
| 352 | % |
| 353 | % PolygonInfo *ConvertPathToPolygon(const DrawInfo *draw_info, |
| 354 | % const PathInfo *path_info) |
| 355 | % |
| 356 | % A description of each parameter follows: |
| 357 | % |
| 358 | % o Method ConvertPathToPolygon returns the path in a more efficient sorted |
| 359 | % rendering form of type PolygonInfo. |
| 360 | % |
| 361 | % o draw_info: Specifies a pointer to an DrawInfo structure. |
| 362 | % |
| 363 | % o path_info: Specifies a pointer to an PathInfo structure. |
| 364 | % |
| 365 | % |
| 366 | */ |
| 367 | |
| 368 | #if defined(__cplusplus) || defined(c_plusplus) |
| 369 | extern "C" { |
| 370 | #endif |
| 371 | |
| 372 | static int CompareEdges(const void *x,const void *y) |
| 373 | { |
| 374 | register const EdgeInfo |
| 375 | *p, |
| 376 | *q; |
| 377 | |
| 378 | /* |
| 379 | Compare two edges. |
| 380 | */ |
| 381 | p=(const EdgeInfo *) x; |
| 382 | q=(const EdgeInfo *) y; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 383 | if ((p->points[0].y-MagickEpsilon) > q->points[0].y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 384 | return(1); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 385 | if ((p->points[0].y+MagickEpsilon) < q->points[0].y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 386 | return(-1); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 387 | if ((p->points[0].x-MagickEpsilon) > q->points[0].x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 388 | return(1); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 389 | if ((p->points[0].x+MagickEpsilon) < q->points[0].x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 390 | return(-1); |
| 391 | if (((p->points[1].x-p->points[0].x)*(q->points[1].y-q->points[0].y)- |
| 392 | (p->points[1].y-p->points[0].y)*(q->points[1].x-q->points[0].x)) > 0.0) |
| 393 | return(1); |
| 394 | return(-1); |
| 395 | } |
| 396 | |
| 397 | #if defined(__cplusplus) || defined(c_plusplus) |
| 398 | } |
| 399 | #endif |
| 400 | |
| 401 | static void LogPolygonInfo(const PolygonInfo *polygon_info) |
| 402 | { |
| 403 | register EdgeInfo |
| 404 | *p; |
| 405 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 406 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 407 | i, |
| 408 | j; |
| 409 | |
| 410 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin active-edge"); |
| 411 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 412 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 413 | { |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 414 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," edge %.20g:", |
| 415 | (double) i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 416 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," direction: %s", |
| 417 | p->direction != MagickFalse ? "down" : "up"); |
| 418 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," ghostline: %s", |
| 419 | p->ghostline != MagickFalse ? "transparent" : "opaque"); |
| 420 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 421 | " bounds: %g %g - %g %g",p->bounds.x1,p->bounds.y1, |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 422 | p->bounds.x2,p->bounds.y2); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 423 | for (j=0; j < (ssize_t) p->number_points; j++) |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 424 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %g %g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 425 | p->points[j].x,p->points[j].y); |
| 426 | p++; |
| 427 | } |
| 428 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end active-edge"); |
| 429 | } |
| 430 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 431 | static void ReversePoints(PointInfo *points,const size_t number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 432 | { |
| 433 | PointInfo |
| 434 | point; |
| 435 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 436 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 437 | i; |
| 438 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 439 | for (i=0; i < (ssize_t) (number_points >> 1); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 440 | { |
| 441 | point=points[i]; |
| 442 | points[i]=points[number_points-(i+1)]; |
| 443 | points[number_points-(i+1)]=point; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | static PolygonInfo *ConvertPathToPolygon( |
| 448 | const DrawInfo *magick_unused(draw_info),const PathInfo *path_info) |
| 449 | { |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 450 | long |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | direction, |
| 452 | next_direction; |
| 453 | |
| 454 | PointInfo |
| 455 | point, |
| 456 | *points; |
| 457 | |
| 458 | PolygonInfo |
| 459 | *polygon_info; |
| 460 | |
| 461 | SegmentInfo |
| 462 | bounds; |
| 463 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 464 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 465 | i, |
| 466 | n; |
| 467 | |
| 468 | MagickBooleanType |
| 469 | ghostline; |
| 470 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 471 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 472 | edge, |
| 473 | number_edges, |
| 474 | number_points; |
| 475 | |
| 476 | /* |
| 477 | Convert a path to the more efficient sorted rendering form. |
| 478 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 479 | polygon_info=(PolygonInfo *) AcquireMagickMemory(sizeof(*polygon_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 480 | if (polygon_info == (PolygonInfo *) NULL) |
| 481 | return((PolygonInfo *) NULL); |
| 482 | number_edges=16; |
| 483 | polygon_info->edges=(EdgeInfo *) AcquireQuantumMemory((size_t) number_edges, |
| 484 | sizeof(*polygon_info->edges)); |
| 485 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 486 | return((PolygonInfo *) NULL); |
| 487 | direction=0; |
| 488 | edge=0; |
| 489 | ghostline=MagickFalse; |
| 490 | n=0; |
| 491 | number_points=0; |
| 492 | points=(PointInfo *) NULL; |
| 493 | (void) ResetMagickMemory(&point,0,sizeof(point)); |
| 494 | (void) ResetMagickMemory(&bounds,0,sizeof(bounds)); |
| 495 | for (i=0; path_info[i].code != EndCode; i++) |
| 496 | { |
| 497 | if ((path_info[i].code == MoveToCode) || (path_info[i].code == OpenCode) || |
| 498 | (path_info[i].code == GhostlineCode)) |
| 499 | { |
| 500 | /* |
| 501 | Move to. |
| 502 | */ |
| 503 | if ((points != (PointInfo *) NULL) && (n >= 2)) |
| 504 | { |
| 505 | if (edge == number_edges) |
| 506 | { |
| 507 | number_edges<<=1; |
| 508 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 509 | polygon_info->edges,(size_t) number_edges, |
| 510 | sizeof(*polygon_info->edges)); |
| 511 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 512 | return((PolygonInfo *) NULL); |
| 513 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 514 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 515 | polygon_info->edges[edge].scanline=(-1.0); |
| 516 | polygon_info->edges[edge].highwater=0; |
| 517 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 518 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 519 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 520 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 521 | polygon_info->edges[edge].points=points; |
| 522 | polygon_info->edges[edge].bounds=bounds; |
| 523 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 524 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 525 | points=(PointInfo *) NULL; |
| 526 | ghostline=MagickFalse; |
| 527 | edge++; |
| 528 | } |
| 529 | if (points == (PointInfo *) NULL) |
| 530 | { |
| 531 | number_points=16; |
| 532 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 533 | sizeof(*points)); |
| 534 | if (points == (PointInfo *) NULL) |
| 535 | return((PolygonInfo *) NULL); |
| 536 | } |
| 537 | ghostline=path_info[i].code == GhostlineCode ? MagickTrue : MagickFalse; |
| 538 | point=path_info[i].point; |
| 539 | points[0]=point; |
| 540 | bounds.x1=point.x; |
| 541 | bounds.x2=point.x; |
| 542 | direction=0; |
| 543 | n=1; |
| 544 | continue; |
| 545 | } |
| 546 | /* |
| 547 | Line to. |
| 548 | */ |
| 549 | next_direction=((path_info[i].point.y > point.y) || |
| 550 | ((path_info[i].point.y == point.y) && |
| 551 | (path_info[i].point.x > point.x))) ? 1 : -1; |
| 552 | if ((direction != 0) && (direction != next_direction)) |
| 553 | { |
| 554 | /* |
| 555 | New edge. |
| 556 | */ |
| 557 | point=points[n-1]; |
| 558 | if (edge == number_edges) |
| 559 | { |
| 560 | number_edges<<=1; |
| 561 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 562 | polygon_info->edges,(size_t) number_edges, |
| 563 | sizeof(*polygon_info->edges)); |
| 564 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 565 | return((PolygonInfo *) NULL); |
| 566 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 567 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 568 | polygon_info->edges[edge].scanline=(-1.0); |
| 569 | polygon_info->edges[edge].highwater=0; |
| 570 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 571 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 572 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 573 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 574 | polygon_info->edges[edge].points=points; |
| 575 | polygon_info->edges[edge].bounds=bounds; |
| 576 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 577 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 578 | number_points=16; |
| 579 | points=(PointInfo *) AcquireQuantumMemory((size_t) number_points, |
| 580 | sizeof(*points)); |
| 581 | if (points == (PointInfo *) NULL) |
| 582 | return((PolygonInfo *) NULL); |
| 583 | n=1; |
| 584 | ghostline=MagickFalse; |
| 585 | points[0]=point; |
| 586 | bounds.x1=point.x; |
| 587 | bounds.x2=point.x; |
| 588 | edge++; |
| 589 | } |
| 590 | direction=next_direction; |
| 591 | if (points == (PointInfo *) NULL) |
| 592 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 593 | if (n == (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 594 | { |
| 595 | number_points<<=1; |
| 596 | points=(PointInfo *) ResizeQuantumMemory(points,(size_t) number_points, |
| 597 | sizeof(*points)); |
| 598 | if (points == (PointInfo *) NULL) |
| 599 | return((PolygonInfo *) NULL); |
| 600 | } |
| 601 | point=path_info[i].point; |
| 602 | points[n]=point; |
| 603 | if (point.x < bounds.x1) |
| 604 | bounds.x1=point.x; |
| 605 | if (point.x > bounds.x2) |
| 606 | bounds.x2=point.x; |
| 607 | n++; |
| 608 | } |
| 609 | if (points != (PointInfo *) NULL) |
| 610 | { |
| 611 | if (n < 2) |
| 612 | points=(PointInfo *) RelinquishMagickMemory(points); |
| 613 | else |
| 614 | { |
| 615 | if (edge == number_edges) |
| 616 | { |
| 617 | number_edges<<=1; |
| 618 | polygon_info->edges=(EdgeInfo *) ResizeQuantumMemory( |
| 619 | polygon_info->edges,(size_t) number_edges, |
| 620 | sizeof(*polygon_info->edges)); |
| 621 | if (polygon_info->edges == (EdgeInfo *) NULL) |
| 622 | return((PolygonInfo *) NULL); |
| 623 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 624 | polygon_info->edges[edge].number_points=(size_t) n; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 625 | polygon_info->edges[edge].scanline=(-1.0); |
| 626 | polygon_info->edges[edge].highwater=0; |
| 627 | polygon_info->edges[edge].ghostline=ghostline; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 628 | polygon_info->edges[edge].direction=(ssize_t) (direction > 0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | if (direction < 0) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 630 | ReversePoints(points,(size_t) n); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 631 | polygon_info->edges[edge].points=points; |
| 632 | polygon_info->edges[edge].bounds=bounds; |
| 633 | polygon_info->edges[edge].bounds.y1=points[0].y; |
| 634 | polygon_info->edges[edge].bounds.y2=points[n-1].y; |
| 635 | ghostline=MagickFalse; |
| 636 | edge++; |
| 637 | } |
| 638 | } |
| 639 | polygon_info->number_edges=edge; |
| 640 | qsort(polygon_info->edges,(size_t) polygon_info->number_edges, |
| 641 | sizeof(*polygon_info->edges),CompareEdges); |
| 642 | if (IsEventLogging() != MagickFalse) |
| 643 | LogPolygonInfo(polygon_info); |
| 644 | return(polygon_info); |
| 645 | } |
| 646 | |
| 647 | /* |
| 648 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 649 | % % |
| 650 | % % |
| 651 | % % |
| 652 | + C o n v e r t P r i m i t i v e T o P a t h % |
| 653 | % % |
| 654 | % % |
| 655 | % % |
| 656 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 657 | % |
| 658 | % ConvertPrimitiveToPath() converts a PrimitiveInfo structure into a vector |
| 659 | % path structure. |
| 660 | % |
| 661 | % The format of the ConvertPrimitiveToPath method is: |
| 662 | % |
| 663 | % PathInfo *ConvertPrimitiveToPath(const DrawInfo *draw_info, |
| 664 | % const PrimitiveInfo *primitive_info) |
| 665 | % |
| 666 | % A description of each parameter follows: |
| 667 | % |
| 668 | % o Method ConvertPrimitiveToPath returns a vector path structure of type |
| 669 | % PathInfo. |
| 670 | % |
| 671 | % o draw_info: a structure of type DrawInfo. |
| 672 | % |
| 673 | % o primitive_info: Specifies a pointer to an PrimitiveInfo structure. |
| 674 | % |
| 675 | % |
| 676 | */ |
| 677 | |
| 678 | static void LogPathInfo(const PathInfo *path_info) |
| 679 | { |
| 680 | register const PathInfo |
| 681 | *p; |
| 682 | |
| 683 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin vector-path"); |
| 684 | for (p=path_info; p->code != EndCode; p++) |
| 685 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 686 | " %g %g %s",p->point.x,p->point.y,p->code == GhostlineCode ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 687 | "moveto ghostline" : p->code == OpenCode ? "moveto open" : |
| 688 | p->code == MoveToCode ? "moveto" : p->code == LineToCode ? "lineto" : |
| 689 | "?"); |
| 690 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end vector-path"); |
| 691 | } |
| 692 | |
| 693 | static PathInfo *ConvertPrimitiveToPath( |
| 694 | const DrawInfo *magick_unused(draw_info),const PrimitiveInfo *primitive_info) |
| 695 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 696 | PathInfo |
| 697 | *path_info; |
| 698 | |
| 699 | PathInfoCode |
| 700 | code; |
| 701 | |
| 702 | PointInfo |
| 703 | p, |
| 704 | q; |
| 705 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 706 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 707 | i, |
| 708 | n; |
| 709 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 710 | ssize_t |
| 711 | coordinates, |
| 712 | start; |
| 713 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 714 | /* |
| 715 | Converts a PrimitiveInfo structure into a vector path structure. |
| 716 | */ |
| 717 | switch (primitive_info->primitive) |
| 718 | { |
| 719 | case PointPrimitive: |
| 720 | case ColorPrimitive: |
| 721 | case MattePrimitive: |
| 722 | case TextPrimitive: |
| 723 | case ImagePrimitive: |
| 724 | return((PathInfo *) NULL); |
| 725 | default: |
| 726 | break; |
| 727 | } |
| 728 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 729 | path_info=(PathInfo *) AcquireQuantumMemory((size_t) (2UL*i+3UL), |
| 730 | sizeof(*path_info)); |
| 731 | if (path_info == (PathInfo *) NULL) |
| 732 | return((PathInfo *) NULL); |
| 733 | coordinates=0; |
| 734 | n=0; |
| 735 | p.x=(-1.0); |
| 736 | p.y=(-1.0); |
| 737 | q.x=(-1.0); |
| 738 | q.y=(-1.0); |
| 739 | start=0; |
| 740 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 741 | { |
| 742 | code=LineToCode; |
| 743 | if (coordinates <= 0) |
| 744 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 745 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 746 | p=primitive_info[i].point; |
| 747 | start=n; |
| 748 | code=MoveToCode; |
| 749 | } |
| 750 | coordinates--; |
| 751 | /* |
| 752 | Eliminate duplicate points. |
| 753 | */ |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 754 | if ((i == 0) || (fabs(q.x-primitive_info[i].point.x) >= MagickEpsilon) || |
| 755 | (fabs(q.y-primitive_info[i].point.y) >= MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 756 | { |
| 757 | path_info[n].code=code; |
| 758 | path_info[n].point=primitive_info[i].point; |
| 759 | q=primitive_info[i].point; |
| 760 | n++; |
| 761 | } |
| 762 | if (coordinates > 0) |
| 763 | continue; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 764 | if ((fabs(p.x-primitive_info[i].point.x) < MagickEpsilon) && |
| 765 | (fabs(p.y-primitive_info[i].point.y) < MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 766 | continue; |
| 767 | /* |
| 768 | Mark the p point as open if it does not match the q. |
| 769 | */ |
| 770 | path_info[start].code=OpenCode; |
| 771 | path_info[n].code=GhostlineCode; |
| 772 | path_info[n].point=primitive_info[i].point; |
| 773 | n++; |
| 774 | path_info[n].code=LineToCode; |
| 775 | path_info[n].point=p; |
| 776 | n++; |
| 777 | } |
| 778 | path_info[n].code=EndCode; |
| 779 | path_info[n].point.x=0.0; |
| 780 | path_info[n].point.y=0.0; |
| 781 | if (IsEventLogging() != MagickFalse) |
| 782 | LogPathInfo(path_info); |
| 783 | return(path_info); |
| 784 | } |
| 785 | |
| 786 | /* |
| 787 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 788 | % % |
| 789 | % % |
| 790 | % % |
| 791 | % D e s t r o y D r a w I n f o % |
| 792 | % % |
| 793 | % % |
| 794 | % % |
| 795 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 796 | % |
| 797 | % DestroyDrawInfo() deallocates memory associated with an DrawInfo |
| 798 | % structure. |
| 799 | % |
| 800 | % The format of the DestroyDrawInfo method is: |
| 801 | % |
| 802 | % DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 803 | % |
| 804 | % A description of each parameter follows: |
| 805 | % |
| 806 | % o draw_info: the draw info. |
| 807 | % |
| 808 | */ |
| 809 | MagickExport DrawInfo *DestroyDrawInfo(DrawInfo *draw_info) |
| 810 | { |
| 811 | if (draw_info->debug != MagickFalse) |
| 812 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 813 | assert(draw_info != (DrawInfo *) NULL); |
| 814 | assert(draw_info->signature == MagickSignature); |
| 815 | if (draw_info->primitive != (char *) NULL) |
| 816 | draw_info->primitive=DestroyString(draw_info->primitive); |
| 817 | if (draw_info->text != (char *) NULL) |
| 818 | draw_info->text=DestroyString(draw_info->text); |
| 819 | if (draw_info->geometry != (char *) NULL) |
| 820 | draw_info->geometry=DestroyString(draw_info->geometry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 821 | if (draw_info->fill_pattern != (Image *) NULL) |
| 822 | draw_info->fill_pattern=DestroyImage(draw_info->fill_pattern); |
| 823 | if (draw_info->stroke_pattern != (Image *) NULL) |
| 824 | draw_info->stroke_pattern=DestroyImage(draw_info->stroke_pattern); |
| 825 | if (draw_info->font != (char *) NULL) |
| 826 | draw_info->font=DestroyString(draw_info->font); |
| 827 | if (draw_info->metrics != (char *) NULL) |
| 828 | draw_info->metrics=DestroyString(draw_info->metrics); |
| 829 | if (draw_info->family != (char *) NULL) |
| 830 | draw_info->family=DestroyString(draw_info->family); |
| 831 | if (draw_info->encoding != (char *) NULL) |
| 832 | draw_info->encoding=DestroyString(draw_info->encoding); |
| 833 | if (draw_info->density != (char *) NULL) |
| 834 | draw_info->density=DestroyString(draw_info->density); |
| 835 | if (draw_info->server_name != (char *) NULL) |
| 836 | draw_info->server_name=(char *) |
| 837 | RelinquishMagickMemory(draw_info->server_name); |
| 838 | if (draw_info->dash_pattern != (double *) NULL) |
| 839 | draw_info->dash_pattern=(double *) RelinquishMagickMemory( |
| 840 | draw_info->dash_pattern); |
| 841 | if (draw_info->gradient.stops != (StopInfo *) NULL) |
| 842 | draw_info->gradient.stops=(StopInfo *) RelinquishMagickMemory( |
| 843 | draw_info->gradient.stops); |
| 844 | if (draw_info->clip_mask != (char *) NULL) |
| 845 | draw_info->clip_mask=DestroyString(draw_info->clip_mask); |
| 846 | draw_info->signature=(~MagickSignature); |
| 847 | draw_info=(DrawInfo *) RelinquishMagickMemory(draw_info); |
| 848 | return(draw_info); |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 853 | % % |
| 854 | % % |
| 855 | % % |
| 856 | + D e s t r o y E d g e % |
| 857 | % % |
| 858 | % % |
| 859 | % % |
| 860 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 861 | % |
| 862 | % DestroyEdge() destroys the specified polygon edge. |
| 863 | % |
| 864 | % The format of the DestroyEdge method is: |
| 865 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 866 | % ssize_t DestroyEdge(PolygonInfo *polygon_info,const int edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 867 | % |
| 868 | % A description of each parameter follows: |
| 869 | % |
| 870 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 871 | % |
| 872 | % o edge: the polygon edge number to destroy. |
| 873 | % |
| 874 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 875 | static size_t DestroyEdge(PolygonInfo *polygon_info, |
| 876 | const size_t edge) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 877 | { |
| 878 | assert(edge < polygon_info->number_edges); |
| 879 | polygon_info->edges[edge].points=(PointInfo *) RelinquishMagickMemory( |
| 880 | polygon_info->edges[edge].points); |
| 881 | polygon_info->number_edges--; |
| 882 | if (edge < polygon_info->number_edges) |
| 883 | (void) CopyMagickMemory(polygon_info->edges+edge,polygon_info->edges+edge+1, |
| 884 | (size_t) (polygon_info->number_edges-edge)*sizeof(*polygon_info->edges)); |
| 885 | return(polygon_info->number_edges); |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 890 | % % |
| 891 | % % |
| 892 | % % |
| 893 | + D e s t r o y P o l y g o n I n f o % |
| 894 | % % |
| 895 | % % |
| 896 | % % |
| 897 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 898 | % |
| 899 | % DestroyPolygonInfo() destroys the PolygonInfo data structure. |
| 900 | % |
| 901 | % The format of the DestroyPolygonInfo method is: |
| 902 | % |
| 903 | % PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 904 | % |
| 905 | % A description of each parameter follows: |
| 906 | % |
| 907 | % o polygon_info: Specifies a pointer to an PolygonInfo structure. |
| 908 | % |
| 909 | */ |
| 910 | static PolygonInfo *DestroyPolygonInfo(PolygonInfo *polygon_info) |
| 911 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 912 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 913 | i; |
| 914 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 915 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 916 | polygon_info->edges[i].points=(PointInfo *) |
| 917 | RelinquishMagickMemory(polygon_info->edges[i].points); |
| 918 | polygon_info->edges=(EdgeInfo *) RelinquishMagickMemory(polygon_info->edges); |
| 919 | return((PolygonInfo *) RelinquishMagickMemory(polygon_info)); |
| 920 | } |
| 921 | |
| 922 | /* |
| 923 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 924 | % % |
| 925 | % % |
| 926 | % % |
| 927 | % D r a w A f f i n e I m a g e % |
| 928 | % % |
| 929 | % % |
| 930 | % % |
| 931 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 932 | % |
| 933 | % DrawAffineImage() composites the source over the destination image as |
| 934 | % dictated by the affine transform. |
| 935 | % |
| 936 | % The format of the DrawAffineImage method is: |
| 937 | % |
| 938 | % MagickBooleanType DrawAffineImage(Image *image,const Image *source, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 939 | % const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | % |
| 941 | % A description of each parameter follows: |
| 942 | % |
| 943 | % o image: the image. |
| 944 | % |
| 945 | % o source: the source image. |
| 946 | % |
| 947 | % o affine: the affine transform. |
| 948 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 949 | % o exception: return any errors or warnings in this structure. |
| 950 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 951 | */ |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 952 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 953 | static SegmentInfo AffineEdge(const Image *image,const AffineMatrix *affine, |
| 954 | const double y,const SegmentInfo *edge) |
| 955 | { |
| 956 | double |
| 957 | intercept, |
| 958 | z; |
| 959 | |
| 960 | register double |
| 961 | x; |
| 962 | |
| 963 | SegmentInfo |
| 964 | inverse_edge; |
| 965 | |
| 966 | /* |
| 967 | Determine left and right edges. |
| 968 | */ |
| 969 | inverse_edge.x1=edge->x1; |
| 970 | inverse_edge.y1=edge->y1; |
| 971 | inverse_edge.x2=edge->x2; |
| 972 | inverse_edge.y2=edge->y2; |
| 973 | z=affine->ry*y+affine->tx; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 974 | if (affine->sx >= MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 975 | { |
| 976 | intercept=(-z/affine->sx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 977 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 978 | if (x > inverse_edge.x1) |
| 979 | inverse_edge.x1=x; |
| 980 | intercept=(-z+(double) image->columns)/affine->sx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 981 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 982 | if (x < inverse_edge.x2) |
| 983 | inverse_edge.x2=x; |
| 984 | } |
| 985 | else |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 986 | if (affine->sx < -MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 987 | { |
| 988 | intercept=(-z+(double) image->columns)/affine->sx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 989 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 990 | if (x > inverse_edge.x1) |
| 991 | inverse_edge.x1=x; |
| 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.x2) |
| 995 | inverse_edge.x2=x; |
| 996 | } |
| 997 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 998 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->columns)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 999 | { |
| 1000 | inverse_edge.x2=edge->x1; |
| 1001 | return(inverse_edge); |
| 1002 | } |
| 1003 | /* |
| 1004 | Determine top and bottom edges. |
| 1005 | */ |
| 1006 | z=affine->sy*y+affine->ty; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 1007 | if (affine->rx >= MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1008 | { |
| 1009 | intercept=(-z/affine->rx); |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1010 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1011 | if (x > inverse_edge.x1) |
| 1012 | inverse_edge.x1=x; |
| 1013 | intercept=(-z+(double) image->rows)/affine->rx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1014 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1015 | if (x < inverse_edge.x2) |
| 1016 | inverse_edge.x2=x; |
| 1017 | } |
| 1018 | else |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 1019 | if (affine->rx < -MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1020 | { |
| 1021 | intercept=(-z+(double) image->rows)/affine->rx; |
cristy | efa9e8a | 2011-11-07 01:56:51 +0000 | [diff] [blame] | 1022 | x=intercept; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1023 | if (x > inverse_edge.x1) |
| 1024 | inverse_edge.x1=x; |
| 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.x2) |
| 1028 | inverse_edge.x2=x; |
| 1029 | } |
| 1030 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1031 | if ((z < 0.0) || ((size_t) floor(z+0.5) >= image->rows)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1032 | { |
| 1033 | inverse_edge.x2=edge->x2; |
| 1034 | return(inverse_edge); |
| 1035 | } |
| 1036 | return(inverse_edge); |
| 1037 | } |
| 1038 | |
| 1039 | static AffineMatrix InverseAffineMatrix(const AffineMatrix *affine) |
| 1040 | { |
| 1041 | AffineMatrix |
| 1042 | inverse_affine; |
| 1043 | |
| 1044 | double |
| 1045 | determinant; |
| 1046 | |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 1047 | determinant=PerceptibleReciprocal(affine->sx*affine->sy-affine->rx* |
cristy | 35f1530 | 2012-06-07 14:59:02 +0000 | [diff] [blame] | 1048 | affine->ry); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1049 | inverse_affine.sx=determinant*affine->sy; |
| 1050 | inverse_affine.rx=determinant*(-affine->rx); |
| 1051 | inverse_affine.ry=determinant*(-affine->ry); |
| 1052 | inverse_affine.sy=determinant*affine->sx; |
| 1053 | inverse_affine.tx=(-affine->tx)*inverse_affine.sx-affine->ty* |
| 1054 | inverse_affine.ry; |
| 1055 | inverse_affine.ty=(-affine->tx)*inverse_affine.rx-affine->ty* |
| 1056 | inverse_affine.sy; |
| 1057 | return(inverse_affine); |
| 1058 | } |
| 1059 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1060 | static inline ssize_t MagickAbsoluteValue(const ssize_t x) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | { |
| 1062 | if (x < 0) |
| 1063 | return(-x); |
| 1064 | return(x); |
| 1065 | } |
| 1066 | |
| 1067 | static inline double MagickMax(const double x,const double y) |
| 1068 | { |
| 1069 | if (x > y) |
| 1070 | return(x); |
| 1071 | return(y); |
| 1072 | } |
| 1073 | |
| 1074 | static inline double MagickMin(const double x,const double y) |
| 1075 | { |
| 1076 | if (x < y) |
| 1077 | return(x); |
| 1078 | return(y); |
| 1079 | } |
| 1080 | |
| 1081 | MagickExport MagickBooleanType DrawAffineImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1082 | const Image *source,const AffineMatrix *affine,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1083 | { |
| 1084 | AffineMatrix |
| 1085 | inverse_affine; |
| 1086 | |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 1087 | CacheView |
| 1088 | *image_view, |
| 1089 | *source_view; |
| 1090 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1091 | MagickBooleanType |
| 1092 | status; |
| 1093 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1094 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1095 | zero; |
| 1096 | |
| 1097 | PointInfo |
| 1098 | extent[4], |
| 1099 | min, |
| 1100 | max, |
| 1101 | point; |
| 1102 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1103 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1104 | i; |
| 1105 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1106 | SegmentInfo |
| 1107 | edge; |
| 1108 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1109 | ssize_t |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1110 | start, |
| 1111 | stop, |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1112 | y; |
| 1113 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1114 | /* |
| 1115 | Determine bounding box. |
| 1116 | */ |
| 1117 | assert(image != (Image *) NULL); |
| 1118 | assert(image->signature == MagickSignature); |
| 1119 | if (image->debug != MagickFalse) |
| 1120 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1121 | assert(source != (const Image *) NULL); |
| 1122 | assert(source->signature == MagickSignature); |
| 1123 | assert(affine != (AffineMatrix *) NULL); |
| 1124 | extent[0].x=0.0; |
| 1125 | extent[0].y=0.0; |
| 1126 | extent[1].x=(double) source->columns-1.0; |
| 1127 | extent[1].y=0.0; |
| 1128 | extent[2].x=(double) source->columns-1.0; |
| 1129 | extent[2].y=(double) source->rows-1.0; |
| 1130 | extent[3].x=0.0; |
| 1131 | extent[3].y=(double) source->rows-1.0; |
| 1132 | for (i=0; i < 4; i++) |
| 1133 | { |
| 1134 | point=extent[i]; |
| 1135 | extent[i].x=point.x*affine->sx+point.y*affine->ry+affine->tx; |
| 1136 | extent[i].y=point.x*affine->rx+point.y*affine->sy+affine->ty; |
| 1137 | } |
| 1138 | min=extent[0]; |
| 1139 | max=extent[0]; |
| 1140 | for (i=1; i < 4; i++) |
| 1141 | { |
| 1142 | if (min.x > extent[i].x) |
| 1143 | min.x=extent[i].x; |
| 1144 | if (min.y > extent[i].y) |
| 1145 | min.y=extent[i].y; |
| 1146 | if (max.x < extent[i].x) |
| 1147 | max.x=extent[i].x; |
| 1148 | if (max.y < extent[i].y) |
| 1149 | max.y=extent[i].y; |
| 1150 | } |
| 1151 | /* |
| 1152 | Affine transform image. |
| 1153 | */ |
cristy | 574cc26 | 2011-08-05 01:23:58 +0000 | [diff] [blame] | 1154 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1155 | return(MagickFalse); |
| 1156 | status=MagickTrue; |
| 1157 | edge.x1=MagickMax(min.x,0.0); |
| 1158 | edge.y1=MagickMax(min.y,0.0); |
| 1159 | edge.x2=MagickMin(max.x,(double) image->columns-1.0); |
| 1160 | edge.y2=MagickMin(max.y,(double) image->rows-1.0); |
| 1161 | inverse_affine=InverseAffineMatrix(affine); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1162 | GetPixelInfo(image,&zero); |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1163 | start=(ssize_t) ceil(edge.y1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 1164 | stop=(ssize_t) floor(edge.y2+0.5); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 1165 | source_view=AcquireVirtualCacheView(source,exception); |
| 1166 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 1167 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 1168 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 1169 | magick_threads(source,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1170 | #endif |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 1171 | for (y=start; y <= stop; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1172 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1173 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1174 | composite, |
| 1175 | pixel; |
| 1176 | |
| 1177 | PointInfo |
| 1178 | point; |
| 1179 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1180 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1181 | x; |
| 1182 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1183 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 1184 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1185 | |
| 1186 | SegmentInfo |
| 1187 | inverse_edge; |
| 1188 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1189 | ssize_t |
| 1190 | x_offset; |
| 1191 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | inverse_edge=AffineEdge(source,&inverse_affine,(double) y,&edge); |
| 1193 | if (inverse_edge.x2 < inverse_edge.x1) |
| 1194 | continue; |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 1195 | q=GetCacheViewAuthenticPixels(image_view,(ssize_t) ceil(inverse_edge.x1- |
cristy | 592aefd | 2013-02-03 15:41:39 +0000 | [diff] [blame] | 1196 | 0.5),y,(size_t) (floor(inverse_edge.x2+0.5)-ceil(inverse_edge.x1-0.5)+1), |
| 1197 | 1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1198 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1199 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1200 | pixel=zero; |
| 1201 | composite=zero; |
| 1202 | x_offset=0; |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 1203 | 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] | 1204 | { |
| 1205 | point.x=(double) x*inverse_affine.sx+y*inverse_affine.ry+ |
| 1206 | inverse_affine.tx; |
| 1207 | point.y=(double) x*inverse_affine.rx+y*inverse_affine.sy+ |
| 1208 | inverse_affine.ty; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1209 | (void) InterpolatePixelInfo(source,source_view,UndefinedInterpolatePixel, |
| 1210 | point.x,point.y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 1211 | GetPixelInfoPixel(image,q,&composite); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 1212 | CompositePixelInfoOver(&pixel,pixel.alpha,&composite,composite.alpha, |
| 1213 | &composite); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 1214 | SetPixelInfoPixel(image,&composite,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1215 | x_offset++; |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 1216 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1217 | } |
| 1218 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 1219 | status=MagickFalse; |
| 1220 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1221 | source_view=DestroyCacheView(source_view); |
| 1222 | image_view=DestroyCacheView(image_view); |
| 1223 | return(status); |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1228 | % % |
| 1229 | % % |
| 1230 | % % |
| 1231 | + D r a w B o u n d i n g R e c t a n g l e s % |
| 1232 | % % |
| 1233 | % % |
| 1234 | % % |
| 1235 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1236 | % |
| 1237 | % DrawBoundingRectangles() draws the bounding rectangles on the image. This |
| 1238 | % is only useful for developers debugging the rendering algorithm. |
| 1239 | % |
| 1240 | % The format of the DrawBoundingRectangles method is: |
| 1241 | % |
| 1242 | % void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1243 | % PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1244 | % |
| 1245 | % A description of each parameter follows: |
| 1246 | % |
| 1247 | % o image: the image. |
| 1248 | % |
| 1249 | % o draw_info: the draw info. |
| 1250 | % |
| 1251 | % o polygon_info: Specifies a pointer to a PolygonInfo structure. |
| 1252 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1253 | % o exception: return any errors or warnings in this structure. |
| 1254 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1255 | */ |
| 1256 | static void DrawBoundingRectangles(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1257 | const PolygonInfo *polygon_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1258 | { |
| 1259 | DrawInfo |
| 1260 | *clone_info; |
| 1261 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1262 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1263 | mid; |
| 1264 | |
| 1265 | PointInfo |
| 1266 | end, |
| 1267 | resolution, |
| 1268 | start; |
| 1269 | |
| 1270 | PrimitiveInfo |
| 1271 | primitive_info[6]; |
| 1272 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1273 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1274 | i; |
| 1275 | |
| 1276 | SegmentInfo |
| 1277 | bounds; |
| 1278 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1279 | ssize_t |
| 1280 | coordinates; |
| 1281 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1282 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 1283 | (void) QueryColorCompliance("#0000",AllCompliance,&clone_info->fill, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1284 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1285 | resolution.x=DefaultResolution; |
| 1286 | resolution.y=DefaultResolution; |
| 1287 | if (clone_info->density != (char *) NULL) |
| 1288 | { |
| 1289 | GeometryInfo |
| 1290 | geometry_info; |
| 1291 | |
| 1292 | MagickStatusType |
| 1293 | flags; |
| 1294 | |
| 1295 | flags=ParseGeometry(clone_info->density,&geometry_info); |
| 1296 | resolution.x=geometry_info.rho; |
| 1297 | resolution.y=geometry_info.sigma; |
| 1298 | if ((flags & SigmaValue) == MagickFalse) |
| 1299 | resolution.y=resolution.x; |
| 1300 | } |
| 1301 | mid=(resolution.x/72.0)*ExpandAffine(&clone_info->affine)* |
| 1302 | clone_info->stroke_width/2.0; |
| 1303 | bounds.x1=0.0; |
| 1304 | bounds.y1=0.0; |
| 1305 | bounds.x2=0.0; |
| 1306 | bounds.y2=0.0; |
| 1307 | if (polygon_info != (PolygonInfo *) NULL) |
| 1308 | { |
| 1309 | bounds=polygon_info->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1310 | for (i=1; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1311 | { |
| 1312 | if (polygon_info->edges[i].bounds.x1 < (double) bounds.x1) |
| 1313 | bounds.x1=polygon_info->edges[i].bounds.x1; |
| 1314 | if (polygon_info->edges[i].bounds.y1 < (double) bounds.y1) |
| 1315 | bounds.y1=polygon_info->edges[i].bounds.y1; |
| 1316 | if (polygon_info->edges[i].bounds.x2 > (double) bounds.x2) |
| 1317 | bounds.x2=polygon_info->edges[i].bounds.x2; |
| 1318 | if (polygon_info->edges[i].bounds.y2 > (double) bounds.y2) |
| 1319 | bounds.y2=polygon_info->edges[i].bounds.y2; |
| 1320 | } |
| 1321 | bounds.x1-=mid; |
| 1322 | bounds.x1=bounds.x1 < 0.0 ? 0.0 : bounds.x1 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1323 | image->columns ? (double) image->columns-1 : bounds.x1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1324 | bounds.y1-=mid; |
| 1325 | bounds.y1=bounds.y1 < 0.0 ? 0.0 : bounds.y1 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1326 | image->rows ? (double) image->rows-1 : bounds.y1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1327 | bounds.x2+=mid; |
| 1328 | bounds.x2=bounds.x2 < 0.0 ? 0.0 : bounds.x2 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1329 | image->columns ? (double) image->columns-1 : bounds.x2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1330 | bounds.y2+=mid; |
| 1331 | bounds.y2=bounds.y2 < 0.0 ? 0.0 : bounds.y2 >= (double) |
cristy | 6c5494a | 2012-09-22 00:30:37 +0000 | [diff] [blame] | 1332 | image->rows ? (double) image->rows-1 : bounds.y2; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1333 | for (i=0; i < (ssize_t) polygon_info->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1334 | { |
| 1335 | if (polygon_info->edges[i].direction != 0) |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1336 | (void) QueryColorCompliance("red",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 | else |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1339 | (void) QueryColorCompliance("green",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1340 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1341 | start.x=(double) (polygon_info->edges[i].bounds.x1-mid); |
| 1342 | start.y=(double) (polygon_info->edges[i].bounds.y1-mid); |
| 1343 | end.x=(double) (polygon_info->edges[i].bounds.x2+mid); |
| 1344 | end.y=(double) (polygon_info->edges[i].bounds.y2+mid); |
| 1345 | primitive_info[0].primitive=RectanglePrimitive; |
| 1346 | TraceRectangle(primitive_info,start,end); |
| 1347 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1348 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1349 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1350 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1351 | } |
| 1352 | } |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1353 | (void) QueryColorCompliance("blue",AllCompliance,&clone_info->stroke, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1354 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | start.x=(double) (bounds.x1-mid); |
| 1356 | start.y=(double) (bounds.y1-mid); |
| 1357 | end.x=(double) (bounds.x2+mid); |
| 1358 | end.y=(double) (bounds.y2+mid); |
| 1359 | primitive_info[0].primitive=RectanglePrimitive; |
| 1360 | TraceRectangle(primitive_info,start,end); |
| 1361 | primitive_info[0].method=ReplaceMethod; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1362 | coordinates=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1363 | primitive_info[coordinates].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1364 | (void) DrawPrimitive(image,clone_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1365 | clone_info=DestroyDrawInfo(clone_info); |
| 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1370 | % % |
| 1371 | % % |
| 1372 | % % |
| 1373 | % D r a w C l i p P a t h % |
| 1374 | % % |
| 1375 | % % |
| 1376 | % % |
| 1377 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1378 | % |
| 1379 | % DrawClipPath() draws the clip path on the image mask. |
| 1380 | % |
| 1381 | % The format of the DrawClipPath method is: |
| 1382 | % |
| 1383 | % MagickBooleanType DrawClipPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1384 | % const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1385 | % |
| 1386 | % A description of each parameter follows: |
| 1387 | % |
| 1388 | % o image: the image. |
| 1389 | % |
| 1390 | % o draw_info: the draw info. |
| 1391 | % |
| 1392 | % o name: the name of the clip path. |
| 1393 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1394 | % o exception: return any errors or warnings in this structure. |
| 1395 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1396 | */ |
| 1397 | MagickExport MagickBooleanType DrawClipPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1398 | const DrawInfo *draw_info,const char *name,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1399 | { |
| 1400 | char |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1401 | filename[MaxTextExtent]; |
| 1402 | |
| 1403 | Image |
| 1404 | *clip_mask; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1405 | |
| 1406 | const char |
| 1407 | *value; |
| 1408 | |
| 1409 | DrawInfo |
| 1410 | *clone_info; |
| 1411 | |
| 1412 | MagickStatusType |
| 1413 | status; |
| 1414 | |
| 1415 | assert(image != (Image *) NULL); |
| 1416 | assert(image->signature == MagickSignature); |
| 1417 | if (image->debug != MagickFalse) |
| 1418 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1419 | assert(draw_info != (const DrawInfo *) NULL); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1420 | (void) FormatLocaleString(filename,MaxTextExtent,"%s",name); |
| 1421 | value=GetImageArtifact(image,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1422 | if (value == (const char *) NULL) |
| 1423 | return(MagickFalse); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1424 | clip_mask=CloneImage(image,image->columns,image->rows,MagickTrue,exception); |
| 1425 | if (clip_mask == (Image *) NULL) |
| 1426 | return(MagickFalse); |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 1427 | (void) QueryColorCompliance("#0000",AllCompliance, |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1428 | &clip_mask->background_color,exception); |
| 1429 | clip_mask->background_color.alpha=(Quantum) TransparentAlpha; |
| 1430 | (void) SetImageBackgroundColor(clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1431 | if (image->debug != MagickFalse) |
| 1432 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"\nbegin clip-path %s", |
| 1433 | draw_info->clip_mask); |
| 1434 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1435 | (void) CloneString(&clone_info->primitive,value); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1436 | (void) QueryColorCompliance("#ffffff",AllCompliance,&clone_info->fill, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 1437 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1438 | clone_info->clip_mask=(char *) NULL; |
cristy | 0c90188 | 2012-01-30 15:58:59 +0000 | [diff] [blame] | 1439 | status=NegateImage(clip_mask,MagickFalse,exception); |
cristy | 10a6c61 | 2012-01-29 21:41:05 +0000 | [diff] [blame] | 1440 | (void) SetImageMask(image,clip_mask,exception); |
| 1441 | clip_mask=DestroyImage(clip_mask); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1442 | status&=DrawImage(image,clone_info,exception); |
cristy | 8e50818 | 2012-09-22 00:21:17 +0000 | [diff] [blame] | 1443 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1444 | if (image->debug != MagickFalse) |
| 1445 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end clip-path"); |
| 1446 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1451 | % % |
| 1452 | % % |
| 1453 | % % |
| 1454 | + D r a w D a s h P o l y g o n % |
| 1455 | % % |
| 1456 | % % |
| 1457 | % % |
| 1458 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1459 | % |
| 1460 | % DrawDashPolygon() draws a dashed polygon (line, rectangle, ellipse) on the |
| 1461 | % image while respecting the dash offset and dash pattern attributes. |
| 1462 | % |
| 1463 | % The format of the DrawDashPolygon method is: |
| 1464 | % |
| 1465 | % MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1466 | % const PrimitiveInfo *primitive_info,Image *image, |
| 1467 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1468 | % |
| 1469 | % A description of each parameter follows: |
| 1470 | % |
| 1471 | % o draw_info: the draw info. |
| 1472 | % |
| 1473 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 1474 | % |
| 1475 | % o image: the image. |
| 1476 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1477 | % o exception: return any errors or warnings in this structure. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1478 | % |
| 1479 | */ |
| 1480 | static MagickBooleanType DrawDashPolygon(const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1481 | const PrimitiveInfo *primitive_info,Image *image,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1482 | { |
| 1483 | DrawInfo |
| 1484 | *clone_info; |
| 1485 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1486 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1487 | length, |
| 1488 | maximum_length, |
| 1489 | offset, |
| 1490 | scale, |
| 1491 | total_length; |
| 1492 | |
| 1493 | MagickStatusType |
| 1494 | status; |
| 1495 | |
| 1496 | PrimitiveInfo |
| 1497 | *dash_polygon; |
| 1498 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1499 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | i; |
| 1501 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1502 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1503 | dx, |
| 1504 | dy; |
| 1505 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1506 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1507 | number_vertices; |
| 1508 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1509 | ssize_t |
| 1510 | j, |
| 1511 | n; |
| 1512 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1513 | assert(draw_info != (const DrawInfo *) NULL); |
| 1514 | if (image->debug != MagickFalse) |
| 1515 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-dash"); |
| 1516 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1517 | clone_info->miterlimit=0; |
| 1518 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1519 | number_vertices=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1520 | dash_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 1521 | (2UL*number_vertices+1UL),sizeof(*dash_polygon)); |
| 1522 | if (dash_polygon == (PrimitiveInfo *) NULL) |
| 1523 | return(MagickFalse); |
| 1524 | dash_polygon[0]=primitive_info[0]; |
| 1525 | scale=ExpandAffine(&draw_info->affine); |
| 1526 | length=scale*(draw_info->dash_pattern[0]-0.5); |
| 1527 | offset=draw_info->dash_offset != 0.0 ? scale*draw_info->dash_offset : 0.0; |
| 1528 | j=1; |
| 1529 | for (n=0; offset > 0.0; j=0) |
| 1530 | { |
| 1531 | if (draw_info->dash_pattern[n] <= 0.0) |
| 1532 | break; |
| 1533 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1534 | if (offset > length) |
| 1535 | { |
| 1536 | offset-=length; |
| 1537 | n++; |
| 1538 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1539 | continue; |
| 1540 | } |
| 1541 | if (offset < length) |
| 1542 | { |
| 1543 | length-=offset; |
| 1544 | offset=0.0; |
| 1545 | break; |
| 1546 | } |
| 1547 | offset=0.0; |
| 1548 | n++; |
| 1549 | } |
| 1550 | status=MagickTrue; |
| 1551 | maximum_length=0.0; |
| 1552 | total_length=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1553 | for (i=1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1554 | { |
| 1555 | dx=primitive_info[i].point.x-primitive_info[i-1].point.x; |
| 1556 | dy=primitive_info[i].point.y-primitive_info[i-1].point.y; |
| 1557 | maximum_length=hypot((double) dx,dy); |
| 1558 | if (length == 0.0) |
| 1559 | { |
| 1560 | n++; |
| 1561 | if (draw_info->dash_pattern[n] == 0.0) |
| 1562 | n=0; |
| 1563 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1564 | } |
cristy | cbda611 | 2012-05-27 20:57:16 +0000 | [diff] [blame] | 1565 | for (total_length=0.0; (total_length+length) <= maximum_length; ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1566 | { |
| 1567 | total_length+=length; |
| 1568 | if ((n & 0x01) != 0) |
| 1569 | { |
| 1570 | dash_polygon[0]=primitive_info[0]; |
| 1571 | dash_polygon[0].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1572 | total_length/maximum_length); |
| 1573 | dash_polygon[0].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1574 | total_length/maximum_length); |
| 1575 | j=1; |
| 1576 | } |
| 1577 | else |
| 1578 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1579 | if ((j+1) > (ssize_t) (2*number_vertices)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1580 | break; |
| 1581 | dash_polygon[j]=primitive_info[i-1]; |
| 1582 | dash_polygon[j].point.x=(double) (primitive_info[i-1].point.x+dx* |
| 1583 | total_length/maximum_length); |
| 1584 | dash_polygon[j].point.y=(double) (primitive_info[i-1].point.y+dy* |
| 1585 | total_length/maximum_length); |
| 1586 | dash_polygon[j].coordinates=1; |
| 1587 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1588 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1589 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1590 | status&=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1591 | } |
| 1592 | n++; |
| 1593 | if (draw_info->dash_pattern[n] == 0.0) |
| 1594 | n=0; |
| 1595 | length=scale*(draw_info->dash_pattern[n]+(n == 0 ? -0.5 : 0.5)); |
| 1596 | } |
| 1597 | length-=(maximum_length-total_length); |
| 1598 | if ((n & 0x01) != 0) |
| 1599 | continue; |
| 1600 | dash_polygon[j]=primitive_info[i]; |
| 1601 | dash_polygon[j].coordinates=1; |
| 1602 | j++; |
| 1603 | } |
cristy | cbda611 | 2012-05-27 20:57:16 +0000 | [diff] [blame] | 1604 | if ((total_length <= maximum_length) && ((n & 0x01) == 0) && (j > 1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1605 | { |
| 1606 | dash_polygon[j]=primitive_info[i-1]; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 1607 | dash_polygon[j].point.x+=MagickEpsilon; |
| 1608 | dash_polygon[j].point.y+=MagickEpsilon; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1609 | dash_polygon[j].coordinates=1; |
| 1610 | j++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1611 | dash_polygon[0].coordinates=(size_t) j; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1612 | dash_polygon[j].primitive=UndefinedPrimitive; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1613 | status&=DrawStrokePolygon(image,clone_info,dash_polygon,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1614 | } |
| 1615 | dash_polygon=(PrimitiveInfo *) RelinquishMagickMemory(dash_polygon); |
| 1616 | clone_info=DestroyDrawInfo(clone_info); |
| 1617 | if (image->debug != MagickFalse) |
| 1618 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-dash"); |
| 1619 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1620 | } |
| 1621 | |
| 1622 | /* |
| 1623 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1624 | % % |
| 1625 | % % |
| 1626 | % % |
| 1627 | % D r a w I m a g e % |
| 1628 | % % |
| 1629 | % % |
| 1630 | % % |
| 1631 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1632 | % |
| 1633 | % DrawImage() draws a graphic primitive on your image. The primitive |
| 1634 | % may be represented as a string or filename. Precede the filename with an |
| 1635 | % "at" sign (@) and the contents of the file are drawn on the image. You |
| 1636 | % can affect how text is drawn by setting one or more members of the draw |
| 1637 | % info structure. |
| 1638 | % |
| 1639 | % The format of the DrawImage method is: |
| 1640 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1641 | % MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1642 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1643 | % |
| 1644 | % A description of each parameter follows: |
| 1645 | % |
| 1646 | % o image: the image. |
| 1647 | % |
| 1648 | % o draw_info: the draw info. |
| 1649 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1650 | % o exception: return any errors or warnings in this structure. |
| 1651 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1652 | */ |
| 1653 | |
| 1654 | static inline MagickBooleanType IsPoint(const char *point) |
| 1655 | { |
| 1656 | char |
| 1657 | *p; |
| 1658 | |
| 1659 | double |
| 1660 | value; |
| 1661 | |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1662 | value=StringToDouble(point,&p); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1663 | return((value == 0.0) && (p == point) ? MagickFalse : MagickTrue); |
| 1664 | } |
| 1665 | |
| 1666 | static inline void TracePoint(PrimitiveInfo *primitive_info, |
| 1667 | const PointInfo point) |
| 1668 | { |
| 1669 | primitive_info->coordinates=1; |
| 1670 | primitive_info->point=point; |
| 1671 | } |
| 1672 | |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1673 | MagickExport MagickBooleanType DrawImage(Image *image,const DrawInfo *draw_info, |
| 1674 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1675 | { |
| 1676 | #define RenderImageTag "Render/Image" |
| 1677 | |
| 1678 | AffineMatrix |
| 1679 | affine, |
| 1680 | current; |
| 1681 | |
| 1682 | char |
| 1683 | key[2*MaxTextExtent], |
| 1684 | keyword[MaxTextExtent], |
| 1685 | geometry[MaxTextExtent], |
| 1686 | name[MaxTextExtent], |
| 1687 | pattern[MaxTextExtent], |
| 1688 | *primitive, |
| 1689 | *token; |
| 1690 | |
| 1691 | const char |
| 1692 | *q; |
| 1693 | |
| 1694 | DrawInfo |
| 1695 | **graphic_context; |
| 1696 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1697 | MagickBooleanType |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1698 | proceed; |
| 1699 | |
| 1700 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1701 | status; |
| 1702 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1703 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1704 | angle, |
| 1705 | factor, |
| 1706 | primitive_extent; |
| 1707 | |
| 1708 | PointInfo |
| 1709 | point; |
| 1710 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 1711 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1712 | start_color; |
| 1713 | |
| 1714 | PrimitiveInfo |
| 1715 | *primitive_info; |
| 1716 | |
| 1717 | PrimitiveType |
| 1718 | primitive_type; |
| 1719 | |
| 1720 | register const char |
| 1721 | *p; |
| 1722 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1723 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1724 | i, |
| 1725 | x; |
| 1726 | |
| 1727 | SegmentInfo |
| 1728 | bounds; |
| 1729 | |
| 1730 | size_t |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1731 | length, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1732 | number_points; |
| 1733 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 1734 | ssize_t |
| 1735 | j, |
| 1736 | k, |
| 1737 | n; |
| 1738 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1739 | /* |
| 1740 | Ensure the annotation info is valid. |
| 1741 | */ |
| 1742 | assert(image != (Image *) NULL); |
| 1743 | assert(image->signature == MagickSignature); |
| 1744 | if (image->debug != MagickFalse) |
| 1745 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1746 | assert(draw_info != (DrawInfo *) NULL); |
| 1747 | assert(draw_info->signature == MagickSignature); |
| 1748 | if (image->debug != MagickFalse) |
| 1749 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 1750 | if ((draw_info->primitive == (char *) NULL) || |
| 1751 | (*draw_info->primitive == '\0')) |
| 1752 | return(MagickFalse); |
| 1753 | if (image->debug != MagickFalse) |
| 1754 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"begin draw-image"); |
| 1755 | if (*draw_info->primitive != '@') |
| 1756 | primitive=AcquireString(draw_info->primitive); |
| 1757 | else |
cristy | 3a5987c | 2013-11-07 14:18:46 +0000 | [diff] [blame] | 1758 | primitive=FileToString(draw_info->primitive+1,~0UL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1759 | if (primitive == (char *) NULL) |
| 1760 | return(MagickFalse); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 1761 | primitive_extent=(double) strlen(primitive); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1762 | (void) SetImageArtifact(image,"MVG",primitive); |
| 1763 | n=0; |
| 1764 | /* |
| 1765 | Allocate primitive info memory. |
| 1766 | */ |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 1767 | graphic_context=(DrawInfo **) AcquireMagickMemory( |
cristy | ed11071 | 2010-03-23 01:16:38 +0000 | [diff] [blame] | 1768 | sizeof(*graphic_context)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1769 | if (graphic_context == (DrawInfo **) NULL) |
| 1770 | { |
| 1771 | primitive=DestroyString(primitive); |
| 1772 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1773 | image->filename); |
| 1774 | } |
cristy | 430522c | 2012-09-03 00:07:16 +0000 | [diff] [blame] | 1775 | number_points=6553; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1776 | primitive_info=(PrimitiveInfo *) AcquireQuantumMemory((size_t) number_points, |
| 1777 | sizeof(*primitive_info)); |
| 1778 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 1779 | { |
| 1780 | primitive=DestroyString(primitive); |
| 1781 | for ( ; n >= 0; n--) |
| 1782 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 1783 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 1784 | ThrowBinaryException(ResourceLimitError,"MemoryAllocationFailed", |
| 1785 | image->filename); |
| 1786 | } |
| 1787 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 1788 | graphic_context[n]->viewbox=image->page; |
| 1789 | if ((image->page.width == 0) || (image->page.height == 0)) |
| 1790 | { |
| 1791 | graphic_context[n]->viewbox.width=image->columns; |
| 1792 | graphic_context[n]->viewbox.height=image->rows; |
| 1793 | } |
| 1794 | token=AcquireString(primitive); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1795 | (void) QueryColorCompliance("#000000",AllCompliance,&start_color, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1796 | exception); |
| 1797 | if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1798 | return(MagickFalse); |
| 1799 | status=MagickTrue; |
| 1800 | for (q=primitive; *q != '\0'; ) |
| 1801 | { |
| 1802 | /* |
| 1803 | Interpret graphic primitive. |
| 1804 | */ |
| 1805 | GetMagickToken(q,&q,keyword); |
| 1806 | if (*keyword == '\0') |
| 1807 | break; |
| 1808 | if (*keyword == '#') |
| 1809 | { |
| 1810 | /* |
| 1811 | Comment. |
| 1812 | */ |
| 1813 | while ((*q != '\n') && (*q != '\0')) |
| 1814 | q++; |
| 1815 | continue; |
| 1816 | } |
| 1817 | p=q-strlen(keyword)-1; |
| 1818 | primitive_type=UndefinedPrimitive; |
| 1819 | current=graphic_context[n]->affine; |
| 1820 | GetAffineMatrix(&affine); |
| 1821 | switch (*keyword) |
| 1822 | { |
| 1823 | case ';': |
| 1824 | break; |
| 1825 | case 'a': |
| 1826 | case 'A': |
| 1827 | { |
| 1828 | if (LocaleCompare("affine",keyword) == 0) |
| 1829 | { |
| 1830 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1831 | affine.sx=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1832 | GetMagickToken(q,&q,token); |
| 1833 | if (*token == ',') |
| 1834 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1835 | affine.rx=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1836 | GetMagickToken(q,&q,token); |
| 1837 | if (*token == ',') |
| 1838 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1839 | affine.ry=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1840 | GetMagickToken(q,&q,token); |
| 1841 | if (*token == ',') |
| 1842 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1843 | affine.sy=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1844 | GetMagickToken(q,&q,token); |
| 1845 | if (*token == ',') |
| 1846 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1847 | affine.tx=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1848 | GetMagickToken(q,&q,token); |
| 1849 | if (*token == ',') |
| 1850 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 1851 | affine.ty=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1852 | break; |
| 1853 | } |
| 1854 | if (LocaleCompare("arc",keyword) == 0) |
| 1855 | { |
| 1856 | primitive_type=ArcPrimitive; |
| 1857 | break; |
| 1858 | } |
| 1859 | status=MagickFalse; |
| 1860 | break; |
| 1861 | } |
| 1862 | case 'b': |
| 1863 | case 'B': |
| 1864 | { |
| 1865 | if (LocaleCompare("bezier",keyword) == 0) |
| 1866 | { |
| 1867 | primitive_type=BezierPrimitive; |
| 1868 | break; |
| 1869 | } |
| 1870 | if (LocaleCompare("border-color",keyword) == 0) |
| 1871 | { |
| 1872 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 1873 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1874 | &graphic_context[n]->border_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1875 | break; |
| 1876 | } |
| 1877 | status=MagickFalse; |
| 1878 | break; |
| 1879 | } |
| 1880 | case 'c': |
| 1881 | case 'C': |
| 1882 | { |
| 1883 | if (LocaleCompare("clip-path",keyword) == 0) |
| 1884 | { |
| 1885 | /* |
| 1886 | Create clip mask. |
| 1887 | */ |
| 1888 | GetMagickToken(q,&q,token); |
| 1889 | (void) CloneString(&graphic_context[n]->clip_mask,token); |
| 1890 | (void) DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1891 | graphic_context[n]->clip_mask,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1892 | break; |
| 1893 | } |
| 1894 | if (LocaleCompare("clip-rule",keyword) == 0) |
| 1895 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1896 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1897 | fill_rule; |
| 1898 | |
| 1899 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1900 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1901 | token); |
| 1902 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1903 | status=MagickFalse; |
| 1904 | else |
| 1905 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1906 | break; |
| 1907 | } |
| 1908 | if (LocaleCompare("clip-units",keyword) == 0) |
| 1909 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1910 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1911 | clip_units; |
| 1912 | |
| 1913 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1914 | clip_units=ParseCommandOption(MagickClipPathOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1915 | token); |
| 1916 | if (clip_units == -1) |
| 1917 | { |
| 1918 | status=MagickFalse; |
| 1919 | break; |
| 1920 | } |
| 1921 | graphic_context[n]->clip_units=(ClipPathUnits) clip_units; |
| 1922 | if (clip_units == ObjectBoundingBox) |
| 1923 | { |
| 1924 | GetAffineMatrix(¤t); |
| 1925 | affine.sx=draw_info->bounds.x2; |
| 1926 | affine.sy=draw_info->bounds.y2; |
| 1927 | affine.tx=draw_info->bounds.x1; |
| 1928 | affine.ty=draw_info->bounds.y1; |
| 1929 | break; |
| 1930 | } |
| 1931 | break; |
| 1932 | } |
| 1933 | if (LocaleCompare("circle",keyword) == 0) |
| 1934 | { |
| 1935 | primitive_type=CirclePrimitive; |
| 1936 | break; |
| 1937 | } |
| 1938 | if (LocaleCompare("color",keyword) == 0) |
| 1939 | { |
| 1940 | primitive_type=ColorPrimitive; |
| 1941 | break; |
| 1942 | } |
| 1943 | status=MagickFalse; |
| 1944 | break; |
| 1945 | } |
| 1946 | case 'd': |
| 1947 | case 'D': |
| 1948 | { |
| 1949 | if (LocaleCompare("decorate",keyword) == 0) |
| 1950 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1951 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1952 | decorate; |
| 1953 | |
| 1954 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 1955 | decorate=ParseCommandOption(MagickDecorateOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1956 | token); |
| 1957 | if (decorate == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 1958 | status=MagickFalse; |
| 1959 | else |
| 1960 | graphic_context[n]->decorate=(DecorationType) decorate; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1961 | break; |
| 1962 | } |
| 1963 | status=MagickFalse; |
| 1964 | break; |
| 1965 | } |
| 1966 | case 'e': |
| 1967 | case 'E': |
| 1968 | { |
| 1969 | if (LocaleCompare("ellipse",keyword) == 0) |
| 1970 | { |
| 1971 | primitive_type=EllipsePrimitive; |
| 1972 | break; |
| 1973 | } |
| 1974 | if (LocaleCompare("encoding",keyword) == 0) |
| 1975 | { |
| 1976 | GetMagickToken(q,&q,token); |
| 1977 | (void) CloneString(&graphic_context[n]->encoding,token); |
| 1978 | break; |
| 1979 | } |
| 1980 | status=MagickFalse; |
| 1981 | break; |
| 1982 | } |
| 1983 | case 'f': |
| 1984 | case 'F': |
| 1985 | { |
| 1986 | if (LocaleCompare("fill",keyword) == 0) |
| 1987 | { |
| 1988 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1989 | (void) FormatLocaleString(pattern,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1990 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 1991 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1992 | &graphic_context[n]->fill_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1993 | else |
| 1994 | { |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 1995 | status&=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 1996 | &graphic_context[n]->fill,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1997 | if (status == MagickFalse) |
| 1998 | { |
| 1999 | ImageInfo |
| 2000 | *pattern_info; |
| 2001 | |
| 2002 | pattern_info=AcquireImageInfo(); |
| 2003 | (void) CopyMagickString(pattern_info->filename,token, |
| 2004 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2005 | graphic_context[n]->fill_pattern=ReadImage(pattern_info, |
| 2006 | exception); |
| 2007 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2008 | pattern_info=DestroyImageInfo(pattern_info); |
| 2009 | } |
| 2010 | } |
| 2011 | break; |
| 2012 | } |
cristy | 69fcc59 | 2012-04-28 18:39:59 +0000 | [diff] [blame] | 2013 | if (LocaleCompare("fill-alpha",keyword) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2014 | { |
| 2015 | GetMagickToken(q,&q,token); |
| 2016 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2017 | graphic_context[n]->fill.alpha=(double) QuantumRange* |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2018 | factor*StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2019 | break; |
| 2020 | } |
| 2021 | if (LocaleCompare("fill-rule",keyword) == 0) |
| 2022 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2023 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2024 | fill_rule; |
| 2025 | |
| 2026 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2027 | fill_rule=ParseCommandOption(MagickFillRuleOptions,MagickFalse, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2028 | token); |
| 2029 | if (fill_rule == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2030 | status=MagickFalse; |
| 2031 | else |
| 2032 | graphic_context[n]->fill_rule=(FillRule) fill_rule; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2033 | break; |
| 2034 | } |
| 2035 | if (LocaleCompare("font",keyword) == 0) |
| 2036 | { |
| 2037 | GetMagickToken(q,&q,token); |
| 2038 | (void) CloneString(&graphic_context[n]->font,token); |
| 2039 | if (LocaleCompare("none",token) == 0) |
| 2040 | graphic_context[n]->font=(char *) |
| 2041 | RelinquishMagickMemory(graphic_context[n]->font); |
| 2042 | break; |
| 2043 | } |
| 2044 | if (LocaleCompare("font-family",keyword) == 0) |
| 2045 | { |
| 2046 | GetMagickToken(q,&q,token); |
| 2047 | (void) CloneString(&graphic_context[n]->family,token); |
| 2048 | break; |
| 2049 | } |
| 2050 | if (LocaleCompare("font-size",keyword) == 0) |
| 2051 | { |
| 2052 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2053 | graphic_context[n]->pointsize=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2054 | break; |
| 2055 | } |
| 2056 | if (LocaleCompare("font-stretch",keyword) == 0) |
| 2057 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2058 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2059 | stretch; |
| 2060 | |
| 2061 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2062 | stretch=ParseCommandOption(MagickStretchOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2063 | if (stretch == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2064 | status=MagickFalse; |
| 2065 | else |
| 2066 | graphic_context[n]->stretch=(StretchType) stretch; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2067 | break; |
| 2068 | } |
| 2069 | if (LocaleCompare("font-style",keyword) == 0) |
| 2070 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2071 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2072 | style; |
| 2073 | |
| 2074 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2075 | style=ParseCommandOption(MagickStyleOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2076 | if (style == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2077 | status=MagickFalse; |
| 2078 | else |
| 2079 | graphic_context[n]->style=(StyleType) style; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2080 | break; |
| 2081 | } |
| 2082 | if (LocaleCompare("font-weight",keyword) == 0) |
| 2083 | { |
| 2084 | GetMagickToken(q,&q,token); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2085 | graphic_context[n]->weight=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2086 | if (LocaleCompare(token,"all") == 0) |
| 2087 | graphic_context[n]->weight=0; |
| 2088 | if (LocaleCompare(token,"bold") == 0) |
| 2089 | graphic_context[n]->weight=700; |
| 2090 | if (LocaleCompare(token,"bolder") == 0) |
| 2091 | if (graphic_context[n]->weight <= 800) |
| 2092 | graphic_context[n]->weight+=100; |
| 2093 | if (LocaleCompare(token,"lighter") == 0) |
| 2094 | if (graphic_context[n]->weight >= 100) |
| 2095 | graphic_context[n]->weight-=100; |
| 2096 | if (LocaleCompare(token,"normal") == 0) |
| 2097 | graphic_context[n]->weight=400; |
| 2098 | break; |
| 2099 | } |
| 2100 | status=MagickFalse; |
| 2101 | break; |
| 2102 | } |
| 2103 | case 'g': |
| 2104 | case 'G': |
| 2105 | { |
| 2106 | if (LocaleCompare("gradient-units",keyword) == 0) |
| 2107 | { |
| 2108 | GetMagickToken(q,&q,token); |
| 2109 | break; |
| 2110 | } |
| 2111 | if (LocaleCompare("gravity",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 | gravity; |
| 2115 | |
| 2116 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2117 | gravity=ParseCommandOption(MagickGravityOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2118 | if (gravity == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2119 | status=MagickFalse; |
| 2120 | else |
| 2121 | graphic_context[n]->gravity=(GravityType) gravity; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2122 | break; |
| 2123 | } |
| 2124 | status=MagickFalse; |
| 2125 | break; |
| 2126 | } |
| 2127 | case 'i': |
| 2128 | case 'I': |
| 2129 | { |
| 2130 | if (LocaleCompare("image",keyword) == 0) |
| 2131 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2132 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2133 | compose; |
| 2134 | |
| 2135 | primitive_type=ImagePrimitive; |
| 2136 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2137 | compose=ParseCommandOption(MagickComposeOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2138 | if (compose == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2139 | status=MagickFalse; |
| 2140 | else |
| 2141 | graphic_context[n]->compose=(CompositeOperator) compose; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2142 | break; |
| 2143 | } |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2144 | if (LocaleCompare("interline-spacing",keyword) == 0) |
| 2145 | { |
| 2146 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2147 | graphic_context[n]->interline_spacing=StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2148 | (char **) NULL); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 2149 | break; |
| 2150 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2151 | if (LocaleCompare("interword-spacing",keyword) == 0) |
| 2152 | { |
| 2153 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2154 | graphic_context[n]->interword_spacing=StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2155 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2156 | break; |
| 2157 | } |
| 2158 | status=MagickFalse; |
| 2159 | break; |
| 2160 | } |
| 2161 | case 'k': |
| 2162 | case 'K': |
| 2163 | { |
| 2164 | if (LocaleCompare("kerning",keyword) == 0) |
| 2165 | { |
| 2166 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2167 | graphic_context[n]->kerning=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2168 | break; |
| 2169 | } |
| 2170 | status=MagickFalse; |
| 2171 | break; |
| 2172 | } |
| 2173 | case 'l': |
| 2174 | case 'L': |
| 2175 | { |
| 2176 | if (LocaleCompare("line",keyword) == 0) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2177 | primitive_type=LinePrimitive; |
| 2178 | else |
| 2179 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2180 | break; |
| 2181 | } |
| 2182 | case 'm': |
| 2183 | case 'M': |
| 2184 | { |
| 2185 | if (LocaleCompare("matte",keyword) == 0) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2186 | primitive_type=MattePrimitive; |
| 2187 | else |
| 2188 | status=MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2189 | break; |
| 2190 | } |
| 2191 | case 'o': |
| 2192 | case 'O': |
| 2193 | { |
| 2194 | if (LocaleCompare("offset",keyword) == 0) |
| 2195 | { |
| 2196 | GetMagickToken(q,&q,token); |
| 2197 | break; |
| 2198 | } |
| 2199 | if (LocaleCompare("opacity",keyword) == 0) |
| 2200 | { |
| 2201 | GetMagickToken(q,&q,token); |
| 2202 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | 8cd03c3 | 2012-07-07 18:57:59 +0000 | [diff] [blame] | 2203 | graphic_context[n]->alpha=ClampToQuantum(QuantumRange*(1.0-((1.0- |
| 2204 | QuantumScale*graphic_context[n]->alpha)*factor* |
| 2205 | StringToDouble(token,(char **) NULL)))); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 2206 | graphic_context[n]->fill.alpha=(double) graphic_context[n]->alpha; |
| 2207 | graphic_context[n]->stroke.alpha=(double) graphic_context[n]->alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2208 | break; |
| 2209 | } |
| 2210 | status=MagickFalse; |
| 2211 | break; |
| 2212 | } |
| 2213 | case 'p': |
| 2214 | case 'P': |
| 2215 | { |
| 2216 | if (LocaleCompare("path",keyword) == 0) |
| 2217 | { |
| 2218 | primitive_type=PathPrimitive; |
| 2219 | break; |
| 2220 | } |
| 2221 | if (LocaleCompare("point",keyword) == 0) |
| 2222 | { |
| 2223 | primitive_type=PointPrimitive; |
| 2224 | break; |
| 2225 | } |
| 2226 | if (LocaleCompare("polyline",keyword) == 0) |
| 2227 | { |
| 2228 | primitive_type=PolylinePrimitive; |
| 2229 | break; |
| 2230 | } |
| 2231 | if (LocaleCompare("polygon",keyword) == 0) |
| 2232 | { |
| 2233 | primitive_type=PolygonPrimitive; |
| 2234 | break; |
| 2235 | } |
| 2236 | if (LocaleCompare("pop",keyword) == 0) |
| 2237 | { |
| 2238 | GetMagickToken(q,&q,token); |
| 2239 | if (LocaleCompare("clip-path",token) == 0) |
| 2240 | break; |
| 2241 | if (LocaleCompare("defs",token) == 0) |
| 2242 | break; |
| 2243 | if (LocaleCompare("gradient",token) == 0) |
| 2244 | break; |
| 2245 | if (LocaleCompare("graphic-context",token) == 0) |
| 2246 | { |
| 2247 | if (n <= 0) |
| 2248 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2249 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2250 | DrawError,"UnbalancedGraphicContextPushPop","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2251 | n=0; |
| 2252 | break; |
| 2253 | } |
| 2254 | if (graphic_context[n]->clip_mask != (char *) NULL) |
| 2255 | if (LocaleCompare(graphic_context[n]->clip_mask, |
| 2256 | graphic_context[n-1]->clip_mask) != 0) |
cristy | e42f658 | 2012-02-11 17:59:50 +0000 | [diff] [blame] | 2257 | (void) SetImageMask(image,(Image *) NULL,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2258 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 2259 | n--; |
| 2260 | break; |
| 2261 | } |
| 2262 | if (LocaleCompare("pattern",token) == 0) |
| 2263 | break; |
| 2264 | status=MagickFalse; |
| 2265 | break; |
| 2266 | } |
| 2267 | if (LocaleCompare("push",keyword) == 0) |
| 2268 | { |
| 2269 | GetMagickToken(q,&q,token); |
| 2270 | if (LocaleCompare("clip-path",token) == 0) |
| 2271 | { |
| 2272 | char |
| 2273 | name[MaxTextExtent]; |
| 2274 | |
| 2275 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2276 | (void) FormatLocaleString(name,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2277 | for (p=q; *q != '\0'; ) |
| 2278 | { |
| 2279 | GetMagickToken(q,&q,token); |
| 2280 | if (LocaleCompare(token,"pop") != 0) |
| 2281 | continue; |
| 2282 | GetMagickToken(q,(const char **) NULL,token); |
| 2283 | if (LocaleCompare(token,"clip-path") != 0) |
| 2284 | continue; |
| 2285 | break; |
| 2286 | } |
| 2287 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2288 | (void) SetImageArtifact(image,name,token); |
| 2289 | GetMagickToken(q,&q,token); |
| 2290 | break; |
| 2291 | } |
| 2292 | if (LocaleCompare("gradient",token) == 0) |
| 2293 | { |
| 2294 | char |
| 2295 | key[2*MaxTextExtent], |
| 2296 | name[MaxTextExtent], |
| 2297 | type[MaxTextExtent]; |
| 2298 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2299 | SegmentInfo |
| 2300 | segment; |
| 2301 | |
| 2302 | GetMagickToken(q,&q,token); |
| 2303 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 2304 | GetMagickToken(q,&q,token); |
| 2305 | (void) CopyMagickString(type,token,MaxTextExtent); |
| 2306 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2307 | segment.x1=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2308 | GetMagickToken(q,&q,token); |
| 2309 | if (*token == ',') |
| 2310 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2311 | segment.y1=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2312 | GetMagickToken(q,&q,token); |
| 2313 | if (*token == ',') |
| 2314 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2315 | segment.x2=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2316 | GetMagickToken(q,&q,token); |
| 2317 | if (*token == ',') |
| 2318 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2319 | segment.y2=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2320 | if (LocaleCompare(type,"radial") == 0) |
| 2321 | { |
| 2322 | GetMagickToken(q,&q,token); |
| 2323 | if (*token == ',') |
| 2324 | GetMagickToken(q,&q,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2325 | } |
| 2326 | for (p=q; *q != '\0'; ) |
| 2327 | { |
| 2328 | GetMagickToken(q,&q,token); |
| 2329 | if (LocaleCompare(token,"pop") != 0) |
| 2330 | continue; |
| 2331 | GetMagickToken(q,(const char **) NULL,token); |
| 2332 | if (LocaleCompare(token,"gradient") != 0) |
| 2333 | continue; |
| 2334 | break; |
| 2335 | } |
| 2336 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
| 2337 | bounds.x1=graphic_context[n]->affine.sx*segment.x1+ |
| 2338 | graphic_context[n]->affine.ry*segment.y1+ |
| 2339 | graphic_context[n]->affine.tx; |
| 2340 | bounds.y1=graphic_context[n]->affine.rx*segment.x1+ |
| 2341 | graphic_context[n]->affine.sy*segment.y1+ |
| 2342 | graphic_context[n]->affine.ty; |
| 2343 | bounds.x2=graphic_context[n]->affine.sx*segment.x2+ |
| 2344 | graphic_context[n]->affine.ry*segment.y2+ |
| 2345 | graphic_context[n]->affine.tx; |
| 2346 | bounds.y2=graphic_context[n]->affine.rx*segment.x2+ |
| 2347 | graphic_context[n]->affine.sy*segment.y2+ |
| 2348 | graphic_context[n]->affine.ty; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2349 | (void) FormatLocaleString(key,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2350 | (void) SetImageArtifact(image,key,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2351 | (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name); |
| 2352 | (void) FormatLocaleString(geometry,MaxTextExtent, |
cristy | e7f5109 | 2010-01-17 00:39:37 +0000 | [diff] [blame] | 2353 | "%gx%g%+.15g%+.15g", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2354 | MagickMax(fabs(bounds.x2-bounds.x1+1.0),1.0), |
| 2355 | MagickMax(fabs(bounds.y2-bounds.y1+1.0),1.0), |
| 2356 | bounds.x1,bounds.y1); |
| 2357 | (void) SetImageArtifact(image,key,geometry); |
| 2358 | GetMagickToken(q,&q,token); |
| 2359 | break; |
| 2360 | } |
| 2361 | if (LocaleCompare("pattern",token) == 0) |
| 2362 | { |
| 2363 | RectangleInfo |
| 2364 | bounds; |
| 2365 | |
| 2366 | GetMagickToken(q,&q,token); |
| 2367 | (void) CopyMagickString(name,token,MaxTextExtent); |
| 2368 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2369 | bounds.x=(ssize_t) ceil(StringToDouble(token,(char **) NULL)- |
| 2370 | 0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2371 | GetMagickToken(q,&q,token); |
| 2372 | if (*token == ',') |
| 2373 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2374 | bounds.y=(ssize_t) ceil(StringToDouble(token,(char **) NULL)- |
| 2375 | 0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2376 | GetMagickToken(q,&q,token); |
| 2377 | if (*token == ',') |
| 2378 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2379 | bounds.width=(size_t) floor(StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2380 | (char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2381 | GetMagickToken(q,&q,token); |
| 2382 | if (*token == ',') |
| 2383 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2384 | bounds.height=(size_t) floor(StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2385 | (char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2386 | for (p=q; *q != '\0'; ) |
| 2387 | { |
| 2388 | GetMagickToken(q,&q,token); |
| 2389 | if (LocaleCompare(token,"pop") != 0) |
| 2390 | continue; |
| 2391 | GetMagickToken(q,(const char **) NULL,token); |
| 2392 | if (LocaleCompare(token,"pattern") != 0) |
| 2393 | continue; |
| 2394 | break; |
| 2395 | } |
| 2396 | (void) CopyMagickString(token,p,(size_t) (q-p-4+1)); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2397 | (void) FormatLocaleString(key,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2398 | (void) SetImageArtifact(image,key,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2399 | (void) FormatLocaleString(key,MaxTextExtent,"%s-geometry",name); |
| 2400 | (void) FormatLocaleString(geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 2401 | "%.20gx%.20g%+.20g%+.20g",(double) bounds.width,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 2402 | bounds.height,(double) bounds.x,(double) bounds.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2403 | (void) SetImageArtifact(image,key,geometry); |
| 2404 | GetMagickToken(q,&q,token); |
| 2405 | break; |
| 2406 | } |
| 2407 | if (LocaleCompare("graphic-context",token) == 0) |
| 2408 | { |
| 2409 | n++; |
| 2410 | graphic_context=(DrawInfo **) ResizeQuantumMemory( |
| 2411 | graphic_context,(size_t) (n+1),sizeof(*graphic_context)); |
| 2412 | if (graphic_context == (DrawInfo **) NULL) |
| 2413 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2414 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2415 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2416 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2417 | break; |
| 2418 | } |
| 2419 | graphic_context[n]=CloneDrawInfo((ImageInfo *) NULL, |
| 2420 | graphic_context[n-1]); |
| 2421 | break; |
| 2422 | } |
| 2423 | if (LocaleCompare("defs",token) == 0) |
| 2424 | break; |
| 2425 | status=MagickFalse; |
| 2426 | break; |
| 2427 | } |
| 2428 | status=MagickFalse; |
| 2429 | break; |
| 2430 | } |
| 2431 | case 'r': |
| 2432 | case 'R': |
| 2433 | { |
| 2434 | if (LocaleCompare("rectangle",keyword) == 0) |
| 2435 | { |
| 2436 | primitive_type=RectanglePrimitive; |
| 2437 | break; |
| 2438 | } |
| 2439 | if (LocaleCompare("rotate",keyword) == 0) |
| 2440 | { |
| 2441 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2442 | angle=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2443 | affine.sx=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2444 | affine.rx=sin(DegreesToRadians(fmod((double) angle,360.0))); |
| 2445 | affine.ry=(-sin(DegreesToRadians(fmod((double) angle,360.0)))); |
| 2446 | affine.sy=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 2447 | break; |
| 2448 | } |
| 2449 | if (LocaleCompare("roundRectangle",keyword) == 0) |
| 2450 | { |
| 2451 | primitive_type=RoundRectanglePrimitive; |
| 2452 | break; |
| 2453 | } |
| 2454 | status=MagickFalse; |
| 2455 | break; |
| 2456 | } |
| 2457 | case 's': |
| 2458 | case 'S': |
| 2459 | { |
| 2460 | if (LocaleCompare("scale",keyword) == 0) |
| 2461 | { |
| 2462 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2463 | affine.sx=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2464 | GetMagickToken(q,&q,token); |
| 2465 | if (*token == ',') |
| 2466 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2467 | affine.sy=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2468 | break; |
| 2469 | } |
| 2470 | if (LocaleCompare("skewX",keyword) == 0) |
| 2471 | { |
| 2472 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2473 | angle=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2474 | affine.ry=sin(DegreesToRadians(angle)); |
| 2475 | break; |
| 2476 | } |
| 2477 | if (LocaleCompare("skewY",keyword) == 0) |
| 2478 | { |
| 2479 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2480 | angle=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2481 | affine.rx=(-tan(DegreesToRadians(angle)/2.0)); |
| 2482 | break; |
| 2483 | } |
| 2484 | if (LocaleCompare("stop-color",keyword) == 0) |
| 2485 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 2486 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2487 | stop_color; |
| 2488 | |
| 2489 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2490 | (void) QueryColorCompliance(token,AllCompliance,&stop_color, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2491 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2492 | (void) GradientImage(image,LinearGradient,ReflectSpread, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2493 | &start_color,&stop_color,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2494 | start_color=stop_color; |
| 2495 | GetMagickToken(q,&q,token); |
| 2496 | break; |
| 2497 | } |
| 2498 | if (LocaleCompare("stroke",keyword) == 0) |
| 2499 | { |
| 2500 | GetMagickToken(q,&q,token); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 2501 | (void) FormatLocaleString(pattern,MaxTextExtent,"%s",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2502 | if (GetImageArtifact(image,pattern) != (const char *) NULL) |
| 2503 | (void) DrawPatternPath(image,draw_info,token, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 2504 | &graphic_context[n]->stroke_pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2505 | else |
| 2506 | { |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 2507 | status&=QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2508 | &graphic_context[n]->stroke,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2509 | if (status == MagickFalse) |
| 2510 | { |
| 2511 | ImageInfo |
| 2512 | *pattern_info; |
| 2513 | |
| 2514 | pattern_info=AcquireImageInfo(); |
| 2515 | (void) CopyMagickString(pattern_info->filename,token, |
| 2516 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2517 | graphic_context[n]->stroke_pattern=ReadImage(pattern_info, |
| 2518 | exception); |
| 2519 | CatchException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2520 | pattern_info=DestroyImageInfo(pattern_info); |
| 2521 | } |
| 2522 | } |
| 2523 | break; |
| 2524 | } |
| 2525 | if (LocaleCompare("stroke-antialias",keyword) == 0) |
| 2526 | { |
| 2527 | GetMagickToken(q,&q,token); |
| 2528 | graphic_context[n]->stroke_antialias= |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2529 | StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2530 | break; |
| 2531 | } |
| 2532 | if (LocaleCompare("stroke-dasharray",keyword) == 0) |
| 2533 | { |
| 2534 | if (graphic_context[n]->dash_pattern != (double *) NULL) |
| 2535 | graphic_context[n]->dash_pattern=(double *) |
| 2536 | RelinquishMagickMemory(graphic_context[n]->dash_pattern); |
| 2537 | if (IsPoint(q) != MagickFalse) |
| 2538 | { |
| 2539 | const char |
| 2540 | *p; |
| 2541 | |
| 2542 | p=q; |
| 2543 | GetMagickToken(p,&p,token); |
| 2544 | if (*token == ',') |
| 2545 | GetMagickToken(p,&p,token); |
| 2546 | for (x=0; IsPoint(token) != MagickFalse; x++) |
| 2547 | { |
| 2548 | GetMagickToken(p,&p,token); |
| 2549 | if (*token == ',') |
| 2550 | GetMagickToken(p,&p,token); |
| 2551 | } |
| 2552 | graphic_context[n]->dash_pattern=(double *) |
| 2553 | AcquireQuantumMemory((size_t) (2UL*x+1UL), |
| 2554 | sizeof(*graphic_context[n]->dash_pattern)); |
| 2555 | if (graphic_context[n]->dash_pattern == (double *) NULL) |
| 2556 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2557 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2558 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2559 | image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2560 | break; |
| 2561 | } |
| 2562 | for (j=0; j < x; j++) |
| 2563 | { |
| 2564 | GetMagickToken(q,&q,token); |
| 2565 | if (*token == ',') |
| 2566 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2567 | graphic_context[n]->dash_pattern[j]=StringToDouble(token, |
| 2568 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2569 | } |
| 2570 | if ((x & 0x01) != 0) |
| 2571 | for ( ; j < (2*x); j++) |
| 2572 | graphic_context[n]->dash_pattern[j]= |
| 2573 | graphic_context[n]->dash_pattern[j-x]; |
| 2574 | graphic_context[n]->dash_pattern[j]=0.0; |
| 2575 | break; |
| 2576 | } |
| 2577 | GetMagickToken(q,&q,token); |
| 2578 | break; |
| 2579 | } |
| 2580 | if (LocaleCompare("stroke-dashoffset",keyword) == 0) |
| 2581 | { |
| 2582 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2583 | graphic_context[n]->dash_offset=StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2584 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2585 | break; |
| 2586 | } |
| 2587 | if (LocaleCompare("stroke-linecap",keyword) == 0) |
| 2588 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2589 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2590 | linecap; |
| 2591 | |
| 2592 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2593 | linecap=ParseCommandOption(MagickLineCapOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2594 | if (linecap == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2595 | status=MagickFalse; |
| 2596 | else |
| 2597 | graphic_context[n]->linecap=(LineCap) linecap; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2598 | break; |
| 2599 | } |
| 2600 | if (LocaleCompare("stroke-linejoin",keyword) == 0) |
| 2601 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2602 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2603 | linejoin; |
| 2604 | |
| 2605 | GetMagickToken(q,&q,token); |
cristy | 7118edf | 2011-10-08 13:33:25 +0000 | [diff] [blame] | 2606 | linejoin=ParseCommandOption(MagickLineJoinOptions,MagickFalse, |
| 2607 | token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2608 | if (linejoin == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2609 | status=MagickFalse; |
| 2610 | else |
| 2611 | graphic_context[n]->linejoin=(LineJoin) linejoin; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2612 | break; |
| 2613 | } |
| 2614 | if (LocaleCompare("stroke-miterlimit",keyword) == 0) |
| 2615 | { |
| 2616 | GetMagickToken(q,&q,token); |
cristy | e27293e | 2009-12-18 02:53:20 +0000 | [diff] [blame] | 2617 | graphic_context[n]->miterlimit=StringToUnsignedLong(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2618 | break; |
| 2619 | } |
| 2620 | if (LocaleCompare("stroke-opacity",keyword) == 0) |
| 2621 | { |
| 2622 | GetMagickToken(q,&q,token); |
| 2623 | factor=strchr(token,'%') != (char *) NULL ? 0.01 : 1.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2624 | graphic_context[n]->stroke.alpha=(double) QuantumRange* |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2625 | factor*StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2626 | break; |
| 2627 | } |
| 2628 | if (LocaleCompare("stroke-width",keyword) == 0) |
| 2629 | { |
| 2630 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2631 | graphic_context[n]->stroke_width=StringToDouble(token, |
cristy | c1acd84 | 2011-05-19 23:05:47 +0000 | [diff] [blame] | 2632 | (char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2633 | break; |
| 2634 | } |
| 2635 | status=MagickFalse; |
| 2636 | break; |
| 2637 | } |
| 2638 | case 't': |
| 2639 | case 'T': |
| 2640 | { |
| 2641 | if (LocaleCompare("text",keyword) == 0) |
| 2642 | { |
| 2643 | primitive_type=TextPrimitive; |
| 2644 | break; |
| 2645 | } |
| 2646 | if (LocaleCompare("text-align",keyword) == 0) |
| 2647 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2648 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2649 | align; |
| 2650 | |
| 2651 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2652 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2653 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2654 | status=MagickFalse; |
| 2655 | else |
| 2656 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2657 | break; |
| 2658 | } |
| 2659 | if (LocaleCompare("text-anchor",keyword) == 0) |
| 2660 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2661 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2662 | align; |
| 2663 | |
| 2664 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 2665 | align=ParseCommandOption(MagickAlignOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2666 | if (align == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 2667 | status=MagickFalse; |
| 2668 | else |
| 2669 | graphic_context[n]->align=(AlignType) align; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2670 | break; |
| 2671 | } |
| 2672 | if (LocaleCompare("text-antialias",keyword) == 0) |
| 2673 | { |
| 2674 | GetMagickToken(q,&q,token); |
| 2675 | graphic_context[n]->text_antialias= |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 2676 | StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2677 | break; |
| 2678 | } |
| 2679 | if (LocaleCompare("text-undercolor",keyword) == 0) |
| 2680 | { |
| 2681 | GetMagickToken(q,&q,token); |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 2682 | (void) QueryColorCompliance(token,AllCompliance, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2683 | &graphic_context[n]->undercolor,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2684 | break; |
| 2685 | } |
| 2686 | if (LocaleCompare("translate",keyword) == 0) |
| 2687 | { |
| 2688 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2689 | affine.tx=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2690 | GetMagickToken(q,&q,token); |
| 2691 | if (*token == ',') |
| 2692 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2693 | affine.ty=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2694 | break; |
| 2695 | } |
| 2696 | status=MagickFalse; |
| 2697 | break; |
| 2698 | } |
| 2699 | case 'v': |
| 2700 | case 'V': |
| 2701 | { |
| 2702 | if (LocaleCompare("viewbox",keyword) == 0) |
| 2703 | { |
| 2704 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2705 | graphic_context[n]->viewbox.x=(ssize_t) ceil(StringToDouble(token, |
| 2706 | (char **) NULL)-0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2707 | GetMagickToken(q,&q,token); |
| 2708 | if (*token == ',') |
| 2709 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2710 | graphic_context[n]->viewbox.y=(ssize_t) ceil(StringToDouble(token, |
| 2711 | (char **) NULL)-0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2712 | GetMagickToken(q,&q,token); |
| 2713 | if (*token == ',') |
| 2714 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2715 | graphic_context[n]->viewbox.width=(size_t) floor(StringToDouble( |
| 2716 | token,(char **) NULL)+0.5); |
cristy | 06609ee | 2010-03-17 20:21:27 +0000 | [diff] [blame] | 2717 | GetMagickToken(q,&q,token); |
| 2718 | if (*token == ',') |
| 2719 | GetMagickToken(q,&q,token); |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 2720 | graphic_context[n]->viewbox.height=(size_t) floor(StringToDouble( |
| 2721 | token,(char **) NULL)+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2722 | break; |
| 2723 | } |
| 2724 | status=MagickFalse; |
| 2725 | break; |
| 2726 | } |
| 2727 | default: |
| 2728 | { |
| 2729 | status=MagickFalse; |
| 2730 | break; |
| 2731 | } |
| 2732 | } |
| 2733 | if (status == MagickFalse) |
| 2734 | break; |
| 2735 | if ((affine.sx != 1.0) || (affine.rx != 0.0) || (affine.ry != 0.0) || |
| 2736 | (affine.sy != 1.0) || (affine.tx != 0.0) || (affine.ty != 0.0)) |
| 2737 | { |
cristy | fbd7009 | 2010-12-01 19:31:14 +0000 | [diff] [blame] | 2738 | graphic_context[n]->affine.sx=current.sx*affine.sx+current.ry*affine.rx; |
| 2739 | graphic_context[n]->affine.rx=current.rx*affine.sx+current.sy*affine.rx; |
| 2740 | graphic_context[n]->affine.ry=current.sx*affine.ry+current.ry*affine.sy; |
| 2741 | graphic_context[n]->affine.sy=current.rx*affine.ry+current.sy*affine.sy; |
| 2742 | graphic_context[n]->affine.tx=current.sx*affine.tx+current.ry*affine.ty+ |
| 2743 | current.tx; |
| 2744 | graphic_context[n]->affine.ty=current.rx*affine.tx+current.sy*affine.ty+ |
| 2745 | current.ty; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2746 | } |
| 2747 | if (primitive_type == UndefinedPrimitive) |
| 2748 | { |
| 2749 | if (image->debug != MagickFalse) |
| 2750 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s", |
| 2751 | (int) (q-p),p); |
| 2752 | continue; |
| 2753 | } |
| 2754 | /* |
| 2755 | Parse the primitive attributes. |
| 2756 | */ |
| 2757 | i=0; |
| 2758 | j=0; |
| 2759 | primitive_info[0].point.x=0.0; |
| 2760 | primitive_info[0].point.y=0.0; |
| 2761 | for (x=0; *q != '\0'; x++) |
| 2762 | { |
| 2763 | /* |
| 2764 | Define points. |
| 2765 | */ |
| 2766 | if (IsPoint(q) == MagickFalse) |
| 2767 | break; |
| 2768 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2769 | point.x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2770 | GetMagickToken(q,&q,token); |
| 2771 | if (*token == ',') |
| 2772 | GetMagickToken(q,&q,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2773 | point.y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2774 | GetMagickToken(q,(const char **) NULL,token); |
| 2775 | if (*token == ',') |
| 2776 | GetMagickToken(q,&q,token); |
| 2777 | primitive_info[i].primitive=primitive_type; |
| 2778 | primitive_info[i].point=point; |
| 2779 | primitive_info[i].coordinates=0; |
| 2780 | primitive_info[i].method=FloodfillMethod; |
| 2781 | i++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2782 | if (i < (ssize_t) number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2783 | continue; |
| 2784 | number_points<<=1; |
| 2785 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 2786 | (size_t) number_points,sizeof(*primitive_info)); |
| 2787 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 2788 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2789 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2790 | ResourceLimitError,"MemoryAllocationFailed","`%s'",image->filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2791 | break; |
| 2792 | } |
| 2793 | } |
| 2794 | primitive_info[j].primitive=primitive_type; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2795 | primitive_info[j].coordinates=(size_t) x; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2796 | primitive_info[j].method=FloodfillMethod; |
| 2797 | primitive_info[j].text=(char *) NULL; |
| 2798 | /* |
| 2799 | Circumscribe primitive within a circle. |
| 2800 | */ |
| 2801 | bounds.x1=primitive_info[j].point.x; |
| 2802 | bounds.y1=primitive_info[j].point.y; |
| 2803 | bounds.x2=primitive_info[j].point.x; |
| 2804 | bounds.y2=primitive_info[j].point.y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2805 | for (k=1; k < (ssize_t) primitive_info[j].coordinates; k++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2806 | { |
| 2807 | point=primitive_info[j+k].point; |
| 2808 | if (point.x < bounds.x1) |
| 2809 | bounds.x1=point.x; |
| 2810 | if (point.y < bounds.y1) |
| 2811 | bounds.y1=point.y; |
| 2812 | if (point.x > bounds.x2) |
| 2813 | bounds.x2=point.x; |
| 2814 | if (point.y > bounds.y2) |
| 2815 | bounds.y2=point.y; |
| 2816 | } |
| 2817 | /* |
| 2818 | Speculate how many points our primitive might consume. |
| 2819 | */ |
| 2820 | length=primitive_info[j].coordinates; |
| 2821 | switch (primitive_type) |
| 2822 | { |
| 2823 | case RectanglePrimitive: |
| 2824 | { |
| 2825 | length*=5; |
| 2826 | break; |
| 2827 | } |
| 2828 | case RoundRectanglePrimitive: |
| 2829 | { |
cristy | 78817ad | 2010-05-07 12:25:34 +0000 | [diff] [blame] | 2830 | length*=5+8*BezierQuantum; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2831 | break; |
| 2832 | } |
| 2833 | case BezierPrimitive: |
| 2834 | { |
| 2835 | if (primitive_info[j].coordinates > 107) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2836 | (void) ThrowMagickException(exception,GetMagickModule(),DrawError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2837 | "TooManyBezierCoordinates","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2838 | length=BezierQuantum*primitive_info[j].coordinates; |
| 2839 | break; |
| 2840 | } |
| 2841 | case PathPrimitive: |
| 2842 | { |
| 2843 | char |
| 2844 | *s, |
| 2845 | *t; |
| 2846 | |
| 2847 | GetMagickToken(q,&q,token); |
cristy | 40a08ad | 2010-02-09 02:27:44 +0000 | [diff] [blame] | 2848 | length=1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2849 | t=token; |
| 2850 | for (s=token; *s != '\0'; s=t) |
| 2851 | { |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 2852 | double |
| 2853 | value; |
| 2854 | |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 2855 | value=StringToDouble(s,&t); |
cristy | 00976d8 | 2011-02-20 20:31:28 +0000 | [diff] [blame] | 2856 | (void) value; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2857 | if (s == t) |
| 2858 | { |
| 2859 | t++; |
| 2860 | continue; |
| 2861 | } |
cristy | ef7a6ce | 2011-05-14 15:01:11 +0000 | [diff] [blame] | 2862 | length++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2863 | } |
cristy | d2f832c | 2011-06-28 12:35:24 +0000 | [diff] [blame] | 2864 | length=length*BezierQuantum/2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2865 | break; |
| 2866 | } |
| 2867 | case CirclePrimitive: |
| 2868 | case ArcPrimitive: |
| 2869 | case EllipsePrimitive: |
| 2870 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 2871 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2872 | alpha, |
| 2873 | beta, |
| 2874 | radius; |
| 2875 | |
| 2876 | alpha=bounds.x2-bounds.x1; |
| 2877 | beta=bounds.y2-bounds.y1; |
| 2878 | radius=hypot((double) alpha,(double) beta); |
cristy | f53f26f | 2011-05-16 00:56:05 +0000 | [diff] [blame] | 2879 | length=2*((size_t) ceil((double) MagickPI*radius))+6*BezierQuantum+360; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2880 | break; |
| 2881 | } |
| 2882 | default: |
| 2883 | break; |
| 2884 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2885 | if ((size_t) (i+length) >= number_points) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2886 | { |
| 2887 | /* |
| 2888 | Resize based on speculative points required by primitive. |
| 2889 | */ |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 2890 | number_points+=length+1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2891 | primitive_info=(PrimitiveInfo *) ResizeQuantumMemory(primitive_info, |
| 2892 | (size_t) number_points,sizeof(*primitive_info)); |
| 2893 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 2894 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 2895 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2896 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2897 | image->filename); |
| 2898 | break; |
| 2899 | } |
| 2900 | } |
| 2901 | switch (primitive_type) |
| 2902 | { |
| 2903 | case PointPrimitive: |
| 2904 | default: |
| 2905 | { |
| 2906 | if (primitive_info[j].coordinates != 1) |
| 2907 | { |
| 2908 | status=MagickFalse; |
| 2909 | break; |
| 2910 | } |
| 2911 | TracePoint(primitive_info+j,primitive_info[j].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2912 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2913 | break; |
| 2914 | } |
| 2915 | case LinePrimitive: |
| 2916 | { |
| 2917 | if (primitive_info[j].coordinates != 2) |
| 2918 | { |
| 2919 | status=MagickFalse; |
| 2920 | break; |
| 2921 | } |
| 2922 | TraceLine(primitive_info+j,primitive_info[j].point, |
| 2923 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2924 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2925 | break; |
| 2926 | } |
| 2927 | case RectanglePrimitive: |
| 2928 | { |
| 2929 | if (primitive_info[j].coordinates != 2) |
| 2930 | { |
| 2931 | status=MagickFalse; |
| 2932 | break; |
| 2933 | } |
| 2934 | TraceRectangle(primitive_info+j,primitive_info[j].point, |
| 2935 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2936 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2937 | break; |
| 2938 | } |
| 2939 | case RoundRectanglePrimitive: |
| 2940 | { |
| 2941 | if (primitive_info[j].coordinates != 3) |
| 2942 | { |
| 2943 | status=MagickFalse; |
| 2944 | break; |
| 2945 | } |
| 2946 | TraceRoundRectangle(primitive_info+j,primitive_info[j].point, |
| 2947 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2948 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2949 | break; |
| 2950 | } |
| 2951 | case ArcPrimitive: |
| 2952 | { |
| 2953 | if (primitive_info[j].coordinates != 3) |
| 2954 | { |
| 2955 | primitive_type=UndefinedPrimitive; |
| 2956 | break; |
| 2957 | } |
| 2958 | TraceArc(primitive_info+j,primitive_info[j].point, |
| 2959 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2960 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2961 | break; |
| 2962 | } |
| 2963 | case EllipsePrimitive: |
| 2964 | { |
| 2965 | if (primitive_info[j].coordinates != 3) |
| 2966 | { |
| 2967 | status=MagickFalse; |
| 2968 | break; |
| 2969 | } |
| 2970 | TraceEllipse(primitive_info+j,primitive_info[j].point, |
| 2971 | primitive_info[j+1].point,primitive_info[j+2].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2972 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2973 | break; |
| 2974 | } |
| 2975 | case CirclePrimitive: |
| 2976 | { |
| 2977 | if (primitive_info[j].coordinates != 2) |
| 2978 | { |
| 2979 | status=MagickFalse; |
| 2980 | break; |
| 2981 | } |
| 2982 | TraceCircle(primitive_info+j,primitive_info[j].point, |
| 2983 | primitive_info[j+1].point); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 2984 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2985 | break; |
| 2986 | } |
| 2987 | case PolylinePrimitive: |
| 2988 | break; |
| 2989 | case PolygonPrimitive: |
| 2990 | { |
| 2991 | primitive_info[i]=primitive_info[j]; |
| 2992 | primitive_info[i].coordinates=0; |
| 2993 | primitive_info[j].coordinates++; |
| 2994 | i++; |
| 2995 | break; |
| 2996 | } |
| 2997 | case BezierPrimitive: |
| 2998 | { |
| 2999 | if (primitive_info[j].coordinates < 3) |
| 3000 | { |
| 3001 | status=MagickFalse; |
| 3002 | break; |
| 3003 | } |
| 3004 | TraceBezier(primitive_info+j,primitive_info[j].coordinates); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3005 | i=(ssize_t) (j+primitive_info[j].coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3006 | break; |
| 3007 | } |
| 3008 | case PathPrimitive: |
| 3009 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3010 | i=(ssize_t) (j+TracePath(primitive_info+j,token)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3011 | break; |
| 3012 | } |
| 3013 | case ColorPrimitive: |
| 3014 | case MattePrimitive: |
| 3015 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3016 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3017 | method; |
| 3018 | |
| 3019 | if (primitive_info[j].coordinates != 1) |
| 3020 | { |
| 3021 | status=MagickFalse; |
| 3022 | break; |
| 3023 | } |
| 3024 | GetMagickToken(q,&q,token); |
cristy | 042ee78 | 2011-04-22 18:48:30 +0000 | [diff] [blame] | 3025 | method=ParseCommandOption(MagickMethodOptions,MagickFalse,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3026 | if (method == -1) |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3027 | status=MagickFalse; |
| 3028 | else |
| 3029 | primitive_info[j].method=(PaintMethod) method; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3030 | break; |
| 3031 | } |
| 3032 | case TextPrimitive: |
| 3033 | { |
| 3034 | if (primitive_info[j].coordinates != 1) |
| 3035 | { |
| 3036 | status=MagickFalse; |
| 3037 | break; |
| 3038 | } |
| 3039 | if (*token != ',') |
| 3040 | GetMagickToken(q,&q,token); |
| 3041 | primitive_info[j].text=AcquireString(token); |
| 3042 | break; |
| 3043 | } |
| 3044 | case ImagePrimitive: |
| 3045 | { |
| 3046 | if (primitive_info[j].coordinates != 2) |
| 3047 | { |
| 3048 | status=MagickFalse; |
| 3049 | break; |
| 3050 | } |
| 3051 | GetMagickToken(q,&q,token); |
| 3052 | primitive_info[j].text=AcquireString(token); |
| 3053 | break; |
| 3054 | } |
| 3055 | } |
| 3056 | if (primitive_info == (PrimitiveInfo *) NULL) |
| 3057 | break; |
| 3058 | if (image->debug != MagickFalse) |
| 3059 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," %.*s",(int) (q-p),p); |
| 3060 | if (status == MagickFalse) |
| 3061 | break; |
| 3062 | primitive_info[i].primitive=UndefinedPrimitive; |
| 3063 | if (i == 0) |
| 3064 | continue; |
| 3065 | /* |
| 3066 | Transform points. |
| 3067 | */ |
| 3068 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 3069 | { |
| 3070 | point=primitive_info[i].point; |
| 3071 | primitive_info[i].point.x=graphic_context[n]->affine.sx*point.x+ |
| 3072 | graphic_context[n]->affine.ry*point.y+graphic_context[n]->affine.tx; |
| 3073 | primitive_info[i].point.y=graphic_context[n]->affine.rx*point.x+ |
| 3074 | graphic_context[n]->affine.sy*point.y+graphic_context[n]->affine.ty; |
| 3075 | point=primitive_info[i].point; |
| 3076 | if (point.x < graphic_context[n]->bounds.x1) |
| 3077 | graphic_context[n]->bounds.x1=point.x; |
| 3078 | if (point.y < graphic_context[n]->bounds.y1) |
| 3079 | graphic_context[n]->bounds.y1=point.y; |
| 3080 | if (point.x > graphic_context[n]->bounds.x2) |
| 3081 | graphic_context[n]->bounds.x2=point.x; |
| 3082 | if (point.y > graphic_context[n]->bounds.y2) |
| 3083 | graphic_context[n]->bounds.y2=point.y; |
| 3084 | if (primitive_info[i].primitive == ImagePrimitive) |
| 3085 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3086 | if (i >= (ssize_t) number_points) |
cristy | 9ce61b9 | 2010-05-12 16:30:26 +0000 | [diff] [blame] | 3087 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3088 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3089 | if (graphic_context[n]->render != MagickFalse) |
| 3090 | { |
| 3091 | if ((n != 0) && (graphic_context[n]->clip_mask != (char *) NULL) && |
| 3092 | (LocaleCompare(graphic_context[n]->clip_mask, |
| 3093 | graphic_context[n-1]->clip_mask) != 0)) |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3094 | status&=DrawClipPath(image,graphic_context[n], |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3095 | graphic_context[n]->clip_mask,exception); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3096 | status&=DrawPrimitive(image,graphic_context[n],primitive_info, |
| 3097 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3098 | } |
| 3099 | if (primitive_info->text != (char *) NULL) |
| 3100 | primitive_info->text=(char *) RelinquishMagickMemory( |
| 3101 | primitive_info->text); |
| 3102 | proceed=SetImageProgress(image,RenderImageTag,q-primitive,(MagickSizeType) |
| 3103 | primitive_extent); |
| 3104 | if (proceed == MagickFalse) |
| 3105 | break; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3106 | if (status == 0) |
| 3107 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3108 | } |
| 3109 | if (image->debug != MagickFalse) |
| 3110 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end draw-image"); |
| 3111 | /* |
| 3112 | Relinquish resources. |
| 3113 | */ |
| 3114 | token=DestroyString(token); |
| 3115 | if (primitive_info != (PrimitiveInfo *) NULL) |
| 3116 | primitive_info=(PrimitiveInfo *) RelinquishMagickMemory(primitive_info); |
| 3117 | primitive=DestroyString(primitive); |
| 3118 | for ( ; n >= 0; n--) |
| 3119 | graphic_context[n]=DestroyDrawInfo(graphic_context[n]); |
| 3120 | graphic_context=(DrawInfo **) RelinquishMagickMemory(graphic_context); |
| 3121 | if (status == MagickFalse) |
| 3122 | ThrowBinaryException(DrawError,"NonconformingDrawingPrimitiveDefinition", |
| 3123 | keyword); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 3124 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3125 | } |
| 3126 | |
| 3127 | /* |
| 3128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3129 | % % |
| 3130 | % % |
| 3131 | % % |
| 3132 | % D r a w G r a d i e n t I m a g e % |
| 3133 | % % |
| 3134 | % % |
| 3135 | % % |
| 3136 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3137 | % |
| 3138 | % DrawGradientImage() draws a linear gradient on the image. |
| 3139 | % |
| 3140 | % The format of the DrawGradientImage method is: |
| 3141 | % |
| 3142 | % MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3143 | % const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3144 | % |
| 3145 | % A description of each parameter follows: |
| 3146 | % |
| 3147 | % o image: the image. |
| 3148 | % |
anthony | 2a02147 | 2011-10-08 11:29:29 +0000 | [diff] [blame] | 3149 | % o draw_info: the draw info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3150 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3151 | % o exception: return any errors or warnings in this structure. |
| 3152 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3153 | */ |
| 3154 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3155 | static inline double GetStopColorOffset(const GradientInfo *gradient, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3156 | const ssize_t x,const ssize_t y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3157 | { |
| 3158 | switch (gradient->type) |
| 3159 | { |
| 3160 | case UndefinedGradient: |
| 3161 | case LinearGradient: |
| 3162 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3163 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3164 | gamma, |
| 3165 | length, |
| 3166 | offset, |
| 3167 | scale; |
| 3168 | |
| 3169 | PointInfo |
| 3170 | p, |
| 3171 | q; |
| 3172 | |
| 3173 | const SegmentInfo |
| 3174 | *gradient_vector; |
| 3175 | |
| 3176 | gradient_vector=(&gradient->gradient_vector); |
| 3177 | p.x=gradient_vector->x2-gradient_vector->x1; |
| 3178 | p.y=gradient_vector->y2-gradient_vector->y1; |
| 3179 | q.x=(double) x-gradient_vector->x1; |
| 3180 | q.y=(double) y-gradient_vector->y1; |
| 3181 | length=sqrt(q.x*q.x+q.y*q.y); |
| 3182 | gamma=sqrt(p.x*p.x+p.y*p.y)*length; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 3183 | gamma=PerceptibleReciprocal(gamma); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3184 | scale=p.x*q.x+p.y*q.y; |
| 3185 | offset=gamma*scale*length; |
| 3186 | return(offset); |
| 3187 | } |
| 3188 | case RadialGradient: |
| 3189 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3190 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3191 | length, |
| 3192 | offset; |
| 3193 | |
| 3194 | PointInfo |
| 3195 | v; |
| 3196 | |
| 3197 | v.x=(double) x-gradient->center.x; |
| 3198 | v.y=(double) y-gradient->center.y; |
| 3199 | length=sqrt(v.x*v.x+v.y*v.y); |
| 3200 | if (gradient->spread == RepeatSpread) |
| 3201 | return(length); |
| 3202 | offset=length/gradient->radius; |
| 3203 | return(offset); |
| 3204 | } |
| 3205 | } |
| 3206 | return(0.0); |
| 3207 | } |
| 3208 | |
| 3209 | MagickExport MagickBooleanType DrawGradientImage(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3210 | const DrawInfo *draw_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3211 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 3212 | CacheView |
| 3213 | *image_view; |
| 3214 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3215 | const GradientInfo |
| 3216 | *gradient; |
| 3217 | |
| 3218 | const SegmentInfo |
| 3219 | *gradient_vector; |
| 3220 | |
cristy | 75c658f | 2012-12-30 16:09:36 +0000 | [diff] [blame] | 3221 | double |
| 3222 | length; |
| 3223 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3224 | MagickBooleanType |
| 3225 | status; |
| 3226 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3227 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3228 | zero; |
| 3229 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3230 | PointInfo |
| 3231 | point; |
| 3232 | |
| 3233 | RectangleInfo |
| 3234 | bounding_box; |
| 3235 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3236 | ssize_t |
| 3237 | y; |
| 3238 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3239 | /* |
| 3240 | Draw linear or radial gradient on image. |
| 3241 | */ |
| 3242 | assert(image != (Image *) NULL); |
| 3243 | assert(image->signature == MagickSignature); |
| 3244 | if (image->debug != MagickFalse) |
| 3245 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3246 | assert(draw_info != (const DrawInfo *) NULL); |
| 3247 | gradient=(&draw_info->gradient); |
| 3248 | gradient_vector=(&gradient->gradient_vector); |
| 3249 | point.x=gradient_vector->x2-gradient_vector->x1; |
| 3250 | point.y=gradient_vector->y2-gradient_vector->y1; |
| 3251 | length=sqrt(point.x*point.x+point.y*point.y); |
| 3252 | bounding_box=gradient->bounding_box; |
| 3253 | status=MagickTrue; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3254 | GetPixelInfo(image,&zero); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3255 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3256 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 3257 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 3258 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3259 | #endif |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3260 | for (y=bounding_box.y; y < (ssize_t) bounding_box.height; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3261 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3262 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3263 | composite, |
| 3264 | pixel; |
| 3265 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3266 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3267 | alpha, |
| 3268 | offset; |
| 3269 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3270 | register Quantum |
| 3271 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3272 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3273 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3274 | i, |
| 3275 | x; |
| 3276 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3277 | ssize_t |
| 3278 | j; |
| 3279 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3280 | if (status == MagickFalse) |
| 3281 | continue; |
| 3282 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3283 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3284 | { |
| 3285 | status=MagickFalse; |
| 3286 | continue; |
| 3287 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3288 | pixel=zero; |
| 3289 | composite=zero; |
| 3290 | offset=GetStopColorOffset(gradient,0,y); |
| 3291 | if (gradient->type != RadialGradient) |
| 3292 | offset/=length; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3293 | for (x=bounding_box.x; x < (ssize_t) bounding_box.width; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3294 | { |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 3295 | GetPixelInfoPixel(image,q,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3296 | switch (gradient->spread) |
| 3297 | { |
| 3298 | case UndefinedSpread: |
| 3299 | case PadSpread: |
| 3300 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3301 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3302 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3303 | { |
| 3304 | offset=GetStopColorOffset(gradient,x,y); |
| 3305 | if (gradient->type != RadialGradient) |
| 3306 | offset/=length; |
| 3307 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3308 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3309 | if (offset < gradient->stops[i].offset) |
| 3310 | break; |
| 3311 | if ((offset < 0.0) || (i == 0)) |
| 3312 | composite=gradient->stops[0].color; |
| 3313 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3314 | if ((offset > 1.0) || (i == (ssize_t) gradient->number_stops)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3315 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3316 | else |
| 3317 | { |
| 3318 | j=i; |
| 3319 | i--; |
| 3320 | alpha=(offset-gradient->stops[i].offset)/ |
| 3321 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3322 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3323 | &gradient->stops[j].color,alpha,&composite); |
| 3324 | } |
| 3325 | break; |
| 3326 | } |
| 3327 | case ReflectSpread: |
| 3328 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3329 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3330 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3331 | { |
| 3332 | offset=GetStopColorOffset(gradient,x,y); |
| 3333 | if (gradient->type != RadialGradient) |
| 3334 | offset/=length; |
| 3335 | } |
| 3336 | if (offset < 0.0) |
| 3337 | offset=(-offset); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3338 | if ((ssize_t) fmod(offset,2.0) == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3339 | offset=fmod(offset,1.0); |
| 3340 | else |
| 3341 | offset=1.0-fmod(offset,1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3342 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3343 | if (offset < gradient->stops[i].offset) |
| 3344 | break; |
| 3345 | if (i == 0) |
| 3346 | composite=gradient->stops[0].color; |
| 3347 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3348 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3349 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3350 | else |
| 3351 | { |
| 3352 | j=i; |
| 3353 | i--; |
| 3354 | alpha=(offset-gradient->stops[i].offset)/ |
| 3355 | (gradient->stops[j].offset-gradient->stops[i].offset); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3356 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3357 | &gradient->stops[j].color,alpha,&composite); |
| 3358 | } |
| 3359 | break; |
| 3360 | } |
| 3361 | case RepeatSpread: |
| 3362 | { |
| 3363 | MagickBooleanType |
| 3364 | antialias; |
| 3365 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3366 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3367 | repeat; |
| 3368 | |
| 3369 | antialias=MagickFalse; |
| 3370 | repeat=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3371 | if ((x != (ssize_t) ceil(gradient_vector->x1-0.5)) || |
| 3372 | (y != (ssize_t) ceil(gradient_vector->y1-0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3373 | { |
| 3374 | offset=GetStopColorOffset(gradient,x,y); |
| 3375 | if (gradient->type == LinearGradient) |
| 3376 | { |
| 3377 | repeat=fmod(offset,length); |
| 3378 | if (repeat < 0.0) |
| 3379 | repeat=length-fmod(-repeat,length); |
| 3380 | else |
| 3381 | repeat=fmod(offset,length); |
| 3382 | antialias=(repeat < length) && ((repeat+1.0) > length) ? |
| 3383 | MagickTrue : MagickFalse; |
| 3384 | offset=repeat/length; |
| 3385 | } |
| 3386 | else |
| 3387 | { |
| 3388 | repeat=fmod(offset,gradient->radius); |
| 3389 | if (repeat < 0.0) |
| 3390 | repeat=gradient->radius-fmod(-repeat,gradient->radius); |
| 3391 | else |
| 3392 | repeat=fmod(offset,gradient->radius); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3393 | antialias=repeat+1.0 > gradient->radius ? MagickTrue : |
| 3394 | MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3395 | offset=repeat/gradient->radius; |
| 3396 | } |
| 3397 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3398 | for (i=0; i < (ssize_t) gradient->number_stops; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3399 | if (offset < gradient->stops[i].offset) |
| 3400 | break; |
| 3401 | if (i == 0) |
| 3402 | composite=gradient->stops[0].color; |
| 3403 | else |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3404 | if (i == (ssize_t) gradient->number_stops) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3405 | composite=gradient->stops[gradient->number_stops-1].color; |
| 3406 | else |
| 3407 | { |
| 3408 | j=i; |
| 3409 | i--; |
| 3410 | alpha=(offset-gradient->stops[i].offset)/ |
| 3411 | (gradient->stops[j].offset-gradient->stops[i].offset); |
| 3412 | if (antialias != MagickFalse) |
| 3413 | { |
| 3414 | if (gradient->type == LinearGradient) |
| 3415 | alpha=length-repeat; |
| 3416 | else |
| 3417 | alpha=gradient->radius-repeat; |
| 3418 | i=0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3419 | j=(ssize_t) gradient->number_stops-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3420 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3421 | CompositePixelInfoBlend(&gradient->stops[i].color,1.0-alpha, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3422 | &gradient->stops[j].color,alpha,&composite); |
| 3423 | } |
| 3424 | break; |
| 3425 | } |
| 3426 | } |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3427 | CompositePixelInfoOver(&composite,composite.alpha,&pixel,pixel.alpha, |
| 3428 | &pixel); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 3429 | SetPixelInfoPixel(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3430 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3431 | } |
| 3432 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3433 | status=MagickFalse; |
| 3434 | } |
| 3435 | image_view=DestroyCacheView(image_view); |
| 3436 | return(status); |
| 3437 | } |
| 3438 | |
| 3439 | /* |
| 3440 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3441 | % % |
| 3442 | % % |
| 3443 | % % |
| 3444 | % D r a w P a t t e r n P a t h % |
| 3445 | % % |
| 3446 | % % |
| 3447 | % % |
| 3448 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3449 | % |
| 3450 | % DrawPatternPath() draws a pattern. |
| 3451 | % |
| 3452 | % The format of the DrawPatternPath method is: |
| 3453 | % |
| 3454 | % MagickBooleanType DrawPatternPath(Image *image,const DrawInfo *draw_info, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3455 | % const char *name,Image **pattern,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3456 | % |
| 3457 | % A description of each parameter follows: |
| 3458 | % |
| 3459 | % o image: the image. |
| 3460 | % |
| 3461 | % o draw_info: the draw info. |
| 3462 | % |
| 3463 | % o name: the pattern name. |
| 3464 | % |
| 3465 | % o image: the image. |
| 3466 | % |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3467 | % o exception: return any errors or warnings in this structure. |
| 3468 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3469 | */ |
| 3470 | MagickExport MagickBooleanType DrawPatternPath(Image *image, |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3471 | const DrawInfo *draw_info,const char *name,Image **pattern, |
| 3472 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3473 | { |
| 3474 | char |
| 3475 | property[MaxTextExtent]; |
| 3476 | |
| 3477 | const char |
| 3478 | *geometry, |
| 3479 | *path; |
| 3480 | |
| 3481 | DrawInfo |
| 3482 | *clone_info; |
| 3483 | |
| 3484 | ImageInfo |
| 3485 | *image_info; |
| 3486 | |
| 3487 | MagickBooleanType |
| 3488 | status; |
| 3489 | |
| 3490 | assert(image != (Image *) NULL); |
| 3491 | assert(image->signature == MagickSignature); |
| 3492 | if (image->debug != MagickFalse) |
| 3493 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3494 | assert(draw_info != (const DrawInfo *) NULL); |
| 3495 | assert(name != (const char *) NULL); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3496 | (void) FormatLocaleString(property,MaxTextExtent,"%s",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3497 | path=GetImageArtifact(image,property); |
| 3498 | if (path == (const char *) NULL) |
| 3499 | return(MagickFalse); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 3500 | (void) FormatLocaleString(property,MaxTextExtent,"%s-geometry",name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3501 | geometry=GetImageArtifact(image,property); |
| 3502 | if (geometry == (const char *) NULL) |
| 3503 | return(MagickFalse); |
| 3504 | if ((*pattern) != (Image *) NULL) |
| 3505 | *pattern=DestroyImage(*pattern); |
| 3506 | image_info=AcquireImageInfo(); |
| 3507 | image_info->size=AcquireString(geometry); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3508 | *pattern=AcquireImage(image_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3509 | image_info=DestroyImageInfo(image_info); |
cristy | ca61154 | 2013-02-19 00:54:03 +0000 | [diff] [blame] | 3510 | (void) QueryColorCompliance("#000000ff",AllCompliance, |
cristy | ea1a8aa | 2011-10-20 13:24:06 +0000 | [diff] [blame] | 3511 | &(*pattern)->background_color,exception); |
| 3512 | (void) SetImageBackgroundColor(*pattern,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3513 | if (image->debug != MagickFalse) |
| 3514 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 3515 | "begin pattern-path %s %s",name,geometry); |
| 3516 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 3517 | clone_info->fill_pattern=NewImageList(); |
| 3518 | clone_info->stroke_pattern=NewImageList(); |
| 3519 | (void) CloneString(&clone_info->primitive,path); |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 3520 | status=DrawImage(*pattern,clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3521 | clone_info=DestroyDrawInfo(clone_info); |
| 3522 | if (image->debug != MagickFalse) |
| 3523 | (void) LogMagickEvent(DrawEvent,GetMagickModule(),"end pattern-path"); |
| 3524 | return(status); |
| 3525 | } |
| 3526 | |
| 3527 | /* |
| 3528 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3529 | % % |
| 3530 | % % |
| 3531 | % % |
| 3532 | + D r a w P o l y g o n P r i m i t i v e % |
| 3533 | % % |
| 3534 | % % |
| 3535 | % % |
| 3536 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3537 | % |
| 3538 | % DrawPolygonPrimitive() draws a polygon on the image. |
| 3539 | % |
| 3540 | % The format of the DrawPolygonPrimitive method is: |
| 3541 | % |
| 3542 | % MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3543 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3544 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3545 | % |
| 3546 | % A description of each parameter follows: |
| 3547 | % |
| 3548 | % o image: the image. |
| 3549 | % |
| 3550 | % o draw_info: the draw info. |
| 3551 | % |
| 3552 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 3553 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3554 | % o exception: return any errors or warnings in this structure. |
| 3555 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3556 | */ |
| 3557 | |
| 3558 | static PolygonInfo **DestroyPolygonThreadSet(PolygonInfo **polygon_info) |
| 3559 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3560 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3561 | i; |
| 3562 | |
| 3563 | assert(polygon_info != (PolygonInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3564 | for (i=0; i < (ssize_t) GetMagickResourceLimit(ThreadResource); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3565 | if (polygon_info[i] != (PolygonInfo *) NULL) |
| 3566 | polygon_info[i]=DestroyPolygonInfo(polygon_info[i]); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3567 | polygon_info=(PolygonInfo **) RelinquishMagickMemory(polygon_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3568 | return(polygon_info); |
| 3569 | } |
| 3570 | |
| 3571 | static PolygonInfo **AcquirePolygonThreadSet(const DrawInfo *draw_info, |
| 3572 | const PrimitiveInfo *primitive_info) |
| 3573 | { |
| 3574 | PathInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3575 | *restrict path_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3576 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3577 | PolygonInfo |
| 3578 | **polygon_info; |
| 3579 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3580 | register ssize_t |
| 3581 | i; |
| 3582 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3583 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3584 | number_threads; |
| 3585 | |
cristy | 9357bdd | 2012-07-30 12:28:34 +0000 | [diff] [blame] | 3586 | number_threads=(size_t) GetMagickResourceLimit(ThreadResource); |
cristy | b41ee10 | 2010-10-04 16:46:15 +0000 | [diff] [blame] | 3587 | polygon_info=(PolygonInfo **) AcquireQuantumMemory(number_threads, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3588 | sizeof(*polygon_info)); |
| 3589 | if (polygon_info == (PolygonInfo **) NULL) |
| 3590 | return((PolygonInfo **) NULL); |
cristy | ac245f8 | 2012-05-05 17:13:57 +0000 | [diff] [blame] | 3591 | (void) ResetMagickMemory(polygon_info,0,number_threads*sizeof(*polygon_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3592 | path_info=ConvertPrimitiveToPath(draw_info,primitive_info); |
| 3593 | if (path_info == (PathInfo *) NULL) |
| 3594 | return(DestroyPolygonThreadSet(polygon_info)); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3595 | for (i=0; i < (ssize_t) number_threads; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3596 | { |
| 3597 | polygon_info[i]=ConvertPathToPolygon(draw_info,path_info); |
| 3598 | if (polygon_info[i] == (PolygonInfo *) NULL) |
| 3599 | return(DestroyPolygonThreadSet(polygon_info)); |
| 3600 | } |
| 3601 | path_info=(PathInfo *) RelinquishMagickMemory(path_info); |
| 3602 | return(polygon_info); |
| 3603 | } |
| 3604 | |
cristy | 884d162 | 2012-09-03 18:10:10 +0000 | [diff] [blame] | 3605 | static double GetFillAlpha(PolygonInfo *polygon_info,const double mid, |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3606 | const MagickBooleanType fill,const FillRule fill_rule,const ssize_t x, |
| 3607 | const ssize_t y,double *stroke_alpha) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3608 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3609 | double |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3610 | alpha, |
| 3611 | beta, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3612 | distance, |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3613 | subpath_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3614 | |
| 3615 | PointInfo |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3616 | delta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3617 | |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3618 | register const PointInfo |
| 3619 | *q; |
| 3620 | |
cristy | 884d162 | 2012-09-03 18:10:10 +0000 | [diff] [blame] | 3621 | register EdgeInfo |
| 3622 | *p; |
| 3623 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3624 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3625 | i; |
| 3626 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 3627 | ssize_t |
| 3628 | j, |
| 3629 | winding_number; |
| 3630 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3631 | /* |
| 3632 | Compute fill & stroke opacity for this (x,y) point. |
| 3633 | */ |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3634 | *stroke_alpha=0.0; |
| 3635 | subpath_alpha=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3636 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3637 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3638 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3639 | if ((double) y <= (p->bounds.y1-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3640 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3641 | if ((double) y > (p->bounds.y2+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3642 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3643 | (void) DestroyEdge(polygon_info,(size_t) j); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3644 | continue; |
| 3645 | } |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3646 | if (((double) x <= (p->bounds.x1-mid-0.5)) || |
| 3647 | ((double) x > (p->bounds.x2+mid+0.5))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3648 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3649 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3650 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3651 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3652 | if ((double) y <= (p->points[i-1].y-mid-0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3653 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3654 | if ((double) y > (p->points[i].y+mid+0.5)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3655 | continue; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3656 | if (p->scanline != (double) y) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3657 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3658 | p->scanline=(double) y; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3659 | p->highwater=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3660 | } |
| 3661 | /* |
| 3662 | Compute distance between a point and an edge. |
| 3663 | */ |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3664 | q=p->points+i-1; |
| 3665 | delta.x=(q+1)->x-q->x; |
| 3666 | delta.y=(q+1)->y-q->y; |
| 3667 | beta=delta.x*(x-q->x)+delta.y*(y-q->y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3668 | if (beta < 0.0) |
| 3669 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3670 | delta.x=(double) x-q->x; |
| 3671 | delta.y=(double) y-q->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3672 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3673 | } |
| 3674 | else |
| 3675 | { |
| 3676 | alpha=delta.x*delta.x+delta.y*delta.y; |
| 3677 | if (beta > alpha) |
| 3678 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3679 | delta.x=(double) x-(q+1)->x; |
| 3680 | delta.y=(double) y-(q+1)->y; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3681 | distance=delta.x*delta.x+delta.y*delta.y; |
| 3682 | } |
| 3683 | else |
| 3684 | { |
cristy | 592aefd | 2013-02-03 15:41:39 +0000 | [diff] [blame] | 3685 | alpha=1.0/alpha; |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3686 | beta=delta.x*(y-q->y)-delta.y*(x-q->x); |
cristy | 4b67d75 | 2012-07-07 23:50:17 +0000 | [diff] [blame] | 3687 | distance=alpha*beta*beta; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3688 | } |
| 3689 | } |
| 3690 | /* |
| 3691 | Compute stroke & subpath opacity. |
| 3692 | */ |
| 3693 | beta=0.0; |
| 3694 | if (p->ghostline == MagickFalse) |
| 3695 | { |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3696 | alpha=mid+0.5; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3697 | if ((*stroke_alpha < 1.0) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3698 | (distance <= ((alpha+0.25)*(alpha+0.25)))) |
| 3699 | { |
| 3700 | alpha=mid-0.5; |
| 3701 | if (distance <= ((alpha+0.25)*(alpha+0.25))) |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3702 | *stroke_alpha=1.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3703 | else |
| 3704 | { |
| 3705 | beta=1.0; |
| 3706 | if (distance != 1.0) |
| 3707 | beta=sqrt((double) distance); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3708 | alpha=beta-mid-0.5; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3709 | if (*stroke_alpha < ((alpha-0.25)*(alpha-0.25))) |
| 3710 | *stroke_alpha=(alpha-0.25)*(alpha-0.25); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3711 | } |
| 3712 | } |
| 3713 | } |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3714 | if ((fill == MagickFalse) || (distance > 1.0) || (subpath_alpha >= 1.0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3715 | continue; |
| 3716 | if (distance <= 0.0) |
| 3717 | { |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3718 | subpath_alpha=1.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3719 | continue; |
| 3720 | } |
| 3721 | if (distance > 1.0) |
| 3722 | continue; |
| 3723 | if (beta == 0.0) |
| 3724 | { |
| 3725 | beta=1.0; |
| 3726 | if (distance != 1.0) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3727 | beta=sqrt(distance); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3728 | } |
| 3729 | alpha=beta-1.0; |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3730 | if (subpath_alpha < (alpha*alpha)) |
| 3731 | subpath_alpha=alpha*alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3732 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3733 | } |
| 3734 | /* |
| 3735 | Compute fill opacity. |
| 3736 | */ |
| 3737 | if (fill == MagickFalse) |
| 3738 | return(0.0); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3739 | if (subpath_alpha >= 1.0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3740 | return(1.0); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3741 | /* |
| 3742 | Determine winding number. |
| 3743 | */ |
| 3744 | winding_number=0; |
| 3745 | p=polygon_info->edges; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3746 | for (j=0; j < (ssize_t) polygon_info->number_edges; j++, p++) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3747 | { |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3748 | if ((double) y <= p->bounds.y1) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3749 | break; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3750 | if (((double) y > p->bounds.y2) || ((double) x <= p->bounds.x1)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3751 | continue; |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3752 | if ((double) x > p->bounds.x2) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3753 | { |
| 3754 | winding_number+=p->direction ? 1 : -1; |
| 3755 | continue; |
| 3756 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3757 | i=(ssize_t) MagickMax((double) p->highwater,1.0); |
| 3758 | for ( ; i < (ssize_t) p->number_points; i++) |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3759 | if ((double) y <= p->points[i].y) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 3760 | break; |
| 3761 | q=p->points+i-1; |
| 3762 | if ((((q+1)->x-q->x)*(y-q->y)) <= (((q+1)->y-q->y)*(x-q->x))) |
| 3763 | winding_number+=p->direction ? 1 : -1; |
| 3764 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3765 | if (fill_rule != NonZeroRule) |
| 3766 | { |
| 3767 | if ((MagickAbsoluteValue(winding_number) & 0x01) != 0) |
| 3768 | return(1.0); |
| 3769 | } |
| 3770 | else |
| 3771 | if (MagickAbsoluteValue(winding_number) != 0) |
| 3772 | return(1.0); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3773 | return(subpath_alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3774 | } |
| 3775 | |
| 3776 | static MagickBooleanType DrawPolygonPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3777 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 3778 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3779 | { |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3780 | CacheView |
| 3781 | *image_view; |
| 3782 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3783 | MagickBooleanType |
| 3784 | fill, |
| 3785 | status; |
| 3786 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3787 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3788 | mid; |
| 3789 | |
| 3790 | PolygonInfo |
cristy | fa11211 | 2010-01-04 17:48:07 +0000 | [diff] [blame] | 3791 | **restrict polygon_info; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3792 | |
| 3793 | register EdgeInfo |
| 3794 | *p; |
| 3795 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3796 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3797 | i; |
| 3798 | |
| 3799 | SegmentInfo |
| 3800 | bounds; |
| 3801 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3802 | ssize_t |
| 3803 | start, |
| 3804 | stop, |
| 3805 | y; |
| 3806 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3807 | /* |
| 3808 | Compute bounding box. |
| 3809 | */ |
| 3810 | assert(image != (Image *) NULL); |
| 3811 | assert(image->signature == MagickSignature); |
| 3812 | if (image->debug != MagickFalse) |
| 3813 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 3814 | assert(draw_info != (DrawInfo *) NULL); |
| 3815 | assert(draw_info->signature == MagickSignature); |
| 3816 | assert(primitive_info != (PrimitiveInfo *) NULL); |
| 3817 | if (primitive_info->coordinates == 0) |
| 3818 | return(MagickTrue); |
| 3819 | polygon_info=AcquirePolygonThreadSet(draw_info,primitive_info); |
| 3820 | if (polygon_info == (PolygonInfo **) NULL) |
| 3821 | return(MagickFalse); |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 3822 | DisableMSCWarning(4127) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3823 | if (0) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 3824 | DrawBoundingRectangles(image,draw_info,polygon_info[0],exception); |
dirk | 93b02b7 | 2013-11-16 16:03:36 +0000 | [diff] [blame] | 3825 | RestoreMSCWarning |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3826 | if (image->debug != MagickFalse) |
| 3827 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," begin draw-polygon"); |
| 3828 | fill=(primitive_info->method == FillToBorderMethod) || |
| 3829 | (primitive_info->method == FloodfillMethod) ? MagickTrue : MagickFalse; |
| 3830 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
| 3831 | bounds=polygon_info[0]->edges[0].bounds; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3832 | for (i=1; i < (ssize_t) polygon_info[0]->number_edges; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3833 | { |
| 3834 | p=polygon_info[0]->edges+i; |
| 3835 | if (p->bounds.x1 < bounds.x1) |
| 3836 | bounds.x1=p->bounds.x1; |
| 3837 | if (p->bounds.y1 < bounds.y1) |
| 3838 | bounds.y1=p->bounds.y1; |
| 3839 | if (p->bounds.x2 > bounds.x2) |
| 3840 | bounds.x2=p->bounds.x2; |
| 3841 | if (p->bounds.y2 > bounds.y2) |
| 3842 | bounds.y2=p->bounds.y2; |
| 3843 | } |
| 3844 | bounds.x1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3845 | 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] | 3846 | image->columns ? (double) image->columns-1 : bounds.x1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3847 | bounds.y1-=(mid+1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3848 | 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] | 3849 | image->rows ? (double) image->rows-1 : bounds.y1; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3850 | bounds.x2+=(mid+1.0); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3851 | 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] | 3852 | image->columns ? (double) image->columns-1 : bounds.x2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3853 | bounds.y2+=(mid+1.0); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3854 | 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] | 3855 | image->rows ? (double) image->rows-1 : bounds.y2; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3856 | status=MagickTrue; |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 3857 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3858 | if (primitive_info->coordinates == 1) |
| 3859 | { |
| 3860 | /* |
| 3861 | Draw point. |
| 3862 | */ |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3863 | start=(ssize_t) ceil(bounds.y1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3864 | stop=(ssize_t) floor(bounds.y2+0.5); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3865 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 3866 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 3867 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3868 | #endif |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3869 | for (y=start; y <= stop; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3870 | { |
| 3871 | MagickBooleanType |
| 3872 | sync; |
| 3873 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3874 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3875 | pixel; |
| 3876 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3877 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3878 | x; |
| 3879 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3880 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3881 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3882 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3883 | ssize_t |
| 3884 | start, |
| 3885 | stop; |
| 3886 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3887 | if (status == MagickFalse) |
| 3888 | continue; |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3889 | start=(ssize_t) ceil(bounds.x1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3890 | stop=(ssize_t) floor(bounds.x2+0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3891 | x=start; |
cristy | f707b30 | 2012-09-04 23:51:26 +0000 | [diff] [blame] | 3892 | q=GetCacheViewAuthenticPixels(image_view,x,y,(size_t) (stop-x+1),1, |
| 3893 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3894 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3895 | { |
| 3896 | status=MagickFalse; |
| 3897 | continue; |
| 3898 | } |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3899 | GetPixelInfo(image,&pixel); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3900 | for ( ; x <= stop; x++) |
| 3901 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 3902 | if ((x == (ssize_t) ceil(primitive_info->point.x-0.5)) && |
| 3903 | (y == (ssize_t) ceil(primitive_info->point.y-0.5))) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3904 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3905 | (void) GetStrokeColor(draw_info,x,y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 3906 | SetPixelInfoPixel(image,&pixel,q); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3907 | } |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3908 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3909 | } |
| 3910 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 3911 | if (sync == MagickFalse) |
| 3912 | status=MagickFalse; |
| 3913 | } |
| 3914 | image_view=DestroyCacheView(image_view); |
| 3915 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 3916 | if (image->debug != MagickFalse) |
| 3917 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 3918 | " end draw-polygon"); |
| 3919 | return(status); |
| 3920 | } |
| 3921 | /* |
| 3922 | Draw polygon or line. |
| 3923 | */ |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 3924 | if (image->alpha_trait != BlendPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 3925 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3926 | start=(ssize_t) ceil(bounds.y1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3927 | stop=(ssize_t) floor(bounds.y2+0.5); |
cristy | b5d5f72 | 2009-11-04 03:03:49 +0000 | [diff] [blame] | 3928 | #if defined(MAGICKCORE_OPENMP_SUPPORT) |
cristy | 9a5a52f | 2012-10-09 14:40:31 +0000 | [diff] [blame] | 3929 | #pragma omp parallel for schedule(static,4) shared(status) \ |
cristy | cb7dfcc | 2013-01-06 18:34:59 +0000 | [diff] [blame] | 3930 | magick_threads(image,image,1,1) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3931 | #endif |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3932 | for (y=start; y <= stop; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3933 | { |
cristy | 5c9e6f2 | 2010-09-17 17:31:01 +0000 | [diff] [blame] | 3934 | const int |
| 3935 | id = GetOpenMPThreadId(); |
cristy | 6ebe97c | 2010-07-03 01:17:28 +0000 | [diff] [blame] | 3936 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3937 | double |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3938 | fill_alpha, |
| 3939 | stroke_alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3940 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 3941 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3942 | fill_color, |
| 3943 | stroke_color; |
| 3944 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3945 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 3946 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3947 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 3948 | register ssize_t |
| 3949 | x; |
| 3950 | |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3951 | ssize_t |
| 3952 | start, |
| 3953 | stop; |
| 3954 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3955 | if (status == MagickFalse) |
| 3956 | continue; |
cristy | 564a569 | 2012-01-20 23:56:26 +0000 | [diff] [blame] | 3957 | start=(ssize_t) ceil(bounds.x1-0.5); |
cristy | 8071c47 | 2012-09-24 12:41:06 +0000 | [diff] [blame] | 3958 | stop=(ssize_t) floor(bounds.x2+0.5); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3959 | q=GetCacheViewAuthenticPixels(image_view,start,y,(size_t) (stop-start+1),1, |
| 3960 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3961 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3962 | { |
| 3963 | status=MagickFalse; |
| 3964 | continue; |
| 3965 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3966 | for (x=start; x <= stop; x++) |
| 3967 | { |
| 3968 | /* |
| 3969 | Fill and/or stroke. |
| 3970 | */ |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3971 | fill_alpha=GetFillAlpha(polygon_info[id],mid,fill,draw_info->fill_rule, |
cristy | e4e47ae | 2012-09-04 23:36:43 +0000 | [diff] [blame] | 3972 | x,y,&stroke_alpha); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3973 | if (draw_info->stroke_antialias == MagickFalse) |
| 3974 | { |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3975 | fill_alpha=fill_alpha > 0.25 ? 1.0 : 0.0; |
| 3976 | stroke_alpha=stroke_alpha > 0.25 ? 1.0 : 0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3977 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3978 | (void) GetFillColor(draw_info,x,y,&fill_color,exception); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3979 | fill_alpha=fill_alpha*fill_color.alpha; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3980 | CompositePixelOver(image,&fill_color,fill_alpha,q,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3981 | GetPixelAlpha(image,q),q); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 3982 | (void) GetStrokeColor(draw_info,x,y,&stroke_color,exception); |
cristy | b2e6b99 | 2011-12-17 16:42:29 +0000 | [diff] [blame] | 3983 | stroke_alpha=stroke_alpha*stroke_color.alpha; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 3984 | CompositePixelOver(image,&stroke_color,stroke_alpha,q,(double) |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 3985 | GetPixelAlpha(image,q),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 3986 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 3987 | } |
| 3988 | if (SyncCacheViewAuthenticPixels(image_view,exception) == MagickFalse) |
| 3989 | status=MagickFalse; |
| 3990 | } |
| 3991 | image_view=DestroyCacheView(image_view); |
| 3992 | polygon_info=DestroyPolygonThreadSet(polygon_info); |
| 3993 | if (image->debug != MagickFalse) |
| 3994 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-polygon"); |
| 3995 | return(status); |
| 3996 | } |
| 3997 | |
| 3998 | /* |
| 3999 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4000 | % % |
| 4001 | % % |
| 4002 | % % |
| 4003 | % D r a w P r i m i t i v e % |
| 4004 | % % |
| 4005 | % % |
| 4006 | % % |
| 4007 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4008 | % |
| 4009 | % DrawPrimitive() draws a primitive (line, rectangle, ellipse) on the image. |
| 4010 | % |
| 4011 | % The format of the DrawPrimitive method is: |
| 4012 | % |
| 4013 | % MagickBooleanType DrawPrimitive(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4014 | % PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4015 | % |
| 4016 | % A description of each parameter follows: |
| 4017 | % |
| 4018 | % o image: the image. |
| 4019 | % |
| 4020 | % o draw_info: the draw info. |
| 4021 | % |
| 4022 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4023 | % |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4024 | % o exception: return any errors or warnings in this structure. |
| 4025 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4026 | */ |
| 4027 | |
| 4028 | static void LogPrimitiveInfo(const PrimitiveInfo *primitive_info) |
| 4029 | { |
| 4030 | const char |
| 4031 | *methods[] = |
| 4032 | { |
| 4033 | "point", |
| 4034 | "replace", |
| 4035 | "floodfill", |
| 4036 | "filltoborder", |
| 4037 | "reset", |
| 4038 | "?" |
| 4039 | }; |
| 4040 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4041 | PointInfo |
| 4042 | p, |
| 4043 | q, |
| 4044 | point; |
| 4045 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4046 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4047 | i, |
| 4048 | x; |
| 4049 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4050 | ssize_t |
| 4051 | coordinates, |
| 4052 | y; |
| 4053 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4054 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4055 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4056 | switch (primitive_info->primitive) |
| 4057 | { |
| 4058 | case PointPrimitive: |
| 4059 | { |
| 4060 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4061 | "PointPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4062 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4063 | return; |
| 4064 | } |
| 4065 | case ColorPrimitive: |
| 4066 | { |
| 4067 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4068 | "ColorPrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4069 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4070 | return; |
| 4071 | } |
| 4072 | case MattePrimitive: |
| 4073 | { |
| 4074 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4075 | "MattePrimitive %.20g,%.20g %s",(double) x,(double) y, |
cristy | f2faecf | 2010-05-28 19:19:36 +0000 | [diff] [blame] | 4076 | methods[primitive_info->method]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4077 | return; |
| 4078 | } |
| 4079 | case TextPrimitive: |
| 4080 | { |
| 4081 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4082 | "TextPrimitive %.20g,%.20g",(double) x,(double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4083 | return; |
| 4084 | } |
| 4085 | case ImagePrimitive: |
| 4086 | { |
| 4087 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4088 | "ImagePrimitive %.20g,%.20g",(double) x,(double) y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4089 | return; |
| 4090 | } |
| 4091 | default: |
| 4092 | break; |
| 4093 | } |
| 4094 | coordinates=0; |
| 4095 | p=primitive_info[0].point; |
| 4096 | q.x=(-1.0); |
| 4097 | q.y=(-1.0); |
| 4098 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) |
| 4099 | { |
| 4100 | point=primitive_info[i].point; |
| 4101 | if (coordinates <= 0) |
| 4102 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4103 | coordinates=(ssize_t) primitive_info[i].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4104 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4105 | " begin open (%.20g)",(double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4106 | p=point; |
| 4107 | } |
| 4108 | point=primitive_info[i].point; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 4109 | if ((fabs(q.x-point.x) >= MagickEpsilon) || |
| 4110 | (fabs(q.y-point.y) >= MagickEpsilon)) |
cristy | 8cd5b31 | 2010-01-07 01:10:24 +0000 | [diff] [blame] | 4111 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4112 | " %.20g: %.18g,%.18g",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4113 | else |
| 4114 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 4115 | " %.20g: %g %g (duplicate)",(double) coordinates,point.x,point.y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4116 | q=point; |
| 4117 | coordinates--; |
| 4118 | if (coordinates > 0) |
| 4119 | continue; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 4120 | if ((fabs(p.x-point.x) >= MagickEpsilon) || |
| 4121 | (fabs(p.y-point.y) >= MagickEpsilon)) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4122 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end last (%.20g)", |
| 4123 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4124 | else |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4125 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end open (%.20g)", |
| 4126 | (double) coordinates); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4127 | } |
| 4128 | } |
| 4129 | |
| 4130 | MagickExport MagickBooleanType DrawPrimitive(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4131 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4132 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4133 | { |
cristy | c4c8d13 | 2010-01-07 01:58:38 +0000 | [diff] [blame] | 4134 | CacheView |
| 4135 | *image_view; |
| 4136 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4137 | MagickStatusType |
| 4138 | status; |
| 4139 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4140 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4141 | i, |
| 4142 | x; |
| 4143 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4144 | ssize_t |
| 4145 | y; |
| 4146 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4147 | if (image->debug != MagickFalse) |
| 4148 | { |
| 4149 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4150 | " begin draw-primitive"); |
| 4151 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
cristy | 14388de | 2011-05-15 14:57:16 +0000 | [diff] [blame] | 4152 | " affine: %g %g %g %g %g %g",draw_info->affine.sx, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4153 | draw_info->affine.rx,draw_info->affine.ry,draw_info->affine.sy, |
| 4154 | draw_info->affine.tx,draw_info->affine.ty); |
| 4155 | } |
cristy | a6400b1 | 2013-03-15 12:20:18 +0000 | [diff] [blame] | 4156 | if ((IsGrayColorspace(image->colorspace) != MagickFalse) && |
cristy | 4dab380 | 2013-03-15 22:08:15 +0000 | [diff] [blame] | 4157 | ((IsPixelInfoGray(&draw_info->fill) == MagickFalse) || |
| 4158 | (IsPixelInfoGray(&draw_info->stroke) == MagickFalse))) |
cristy | 0c81d06 | 2013-04-21 15:22:02 +0000 | [diff] [blame] | 4159 | (void) SetImageColorspace(image,sRGBColorspace,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4160 | status=MagickTrue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4161 | x=(ssize_t) ceil(primitive_info->point.x-0.5); |
| 4162 | y=(ssize_t) ceil(primitive_info->point.y-0.5); |
cristy | 46ff267 | 2012-12-14 15:32:26 +0000 | [diff] [blame] | 4163 | image_view=AcquireAuthenticCacheView(image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4164 | switch (primitive_info->primitive) |
| 4165 | { |
| 4166 | case PointPrimitive: |
| 4167 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4168 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4169 | fill_color; |
| 4170 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4171 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4172 | *q; |
| 4173 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4174 | if ((y < 0) || (y >= (ssize_t) image->rows)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4175 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4176 | if ((x < 0) || (x >= (ssize_t) image->columns)) |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 4177 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4178 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4179 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4180 | break; |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4181 | (void) GetFillColor(draw_info,x,y,&fill_color,exception); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4182 | CompositePixelOver(image,&fill_color,(double) fill_color.alpha,q, |
| 4183 | (double) GetPixelAlpha(image,q),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4184 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4185 | break; |
| 4186 | } |
| 4187 | case ColorPrimitive: |
| 4188 | { |
| 4189 | switch (primitive_info->method) |
| 4190 | { |
| 4191 | case PointMethod: |
| 4192 | default: |
| 4193 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4194 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4195 | pixel; |
| 4196 | |
| 4197 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4198 | *q; |
| 4199 | |
| 4200 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4201 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4202 | break; |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4203 | GetPixelInfo(image,&pixel); |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4204 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 4205 | SetPixelInfoPixel(image,&pixel,q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4206 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4207 | break; |
| 4208 | } |
| 4209 | case ReplaceMethod: |
| 4210 | { |
| 4211 | MagickBooleanType |
| 4212 | sync; |
| 4213 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4214 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4215 | pixel, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4216 | target; |
| 4217 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4218 | (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4219 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4220 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4221 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4222 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4223 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4224 | |
| 4225 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4226 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4227 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4228 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4229 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4230 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4231 | GetPixelInfoPixel(image,q,&pixel); |
| 4232 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4233 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4234 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4235 | continue; |
| 4236 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4237 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 4238 | SetPixelInfoPixel(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4239 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4240 | } |
| 4241 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4242 | if (sync == MagickFalse) |
| 4243 | break; |
| 4244 | } |
| 4245 | break; |
| 4246 | } |
| 4247 | case FloodfillMethod: |
| 4248 | case FillToBorderMethod: |
| 4249 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4250 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4251 | target; |
| 4252 | |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 4253 | (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y, |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame] | 4254 | &target,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4255 | if (primitive_info->method == FillToBorderMethod) |
| 4256 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4257 | target.red=(double) draw_info->border_color.red; |
| 4258 | target.green=(double) draw_info->border_color.green; |
| 4259 | target.blue=(double) draw_info->border_color.blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4260 | } |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4261 | status&=FloodfillPaintImage(image,draw_info,&target,x,y, |
cristy | d42d995 | 2011-07-08 14:21:50 +0000 | [diff] [blame] | 4262 | primitive_info->method == FloodfillMethod ? MagickFalse : |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 4263 | MagickTrue,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4264 | break; |
| 4265 | } |
| 4266 | case ResetMethod: |
| 4267 | { |
| 4268 | MagickBooleanType |
| 4269 | sync; |
| 4270 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4271 | PixelInfo |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4272 | pixel; |
| 4273 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4274 | GetPixelInfo(image,&pixel); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4275 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4276 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4277 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4278 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4279 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4280 | register ssize_t |
| 4281 | x; |
| 4282 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4283 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4284 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4285 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4286 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4287 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4288 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4289 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | 803640d | 2011-11-17 02:11:32 +0000 | [diff] [blame] | 4290 | SetPixelInfoPixel(image,&pixel,q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4291 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4292 | } |
| 4293 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4294 | if (sync == MagickFalse) |
| 4295 | break; |
| 4296 | } |
| 4297 | break; |
| 4298 | } |
| 4299 | } |
| 4300 | break; |
| 4301 | } |
| 4302 | case MattePrimitive: |
| 4303 | { |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4304 | if (image->alpha_trait != BlendPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4305 | (void) SetImageAlphaChannel(image,OpaqueAlphaChannel,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4306 | switch (primitive_info->method) |
| 4307 | { |
| 4308 | case PointMethod: |
| 4309 | default: |
| 4310 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4311 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4312 | pixel; |
| 4313 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4314 | register Quantum |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4315 | *q; |
| 4316 | |
| 4317 | q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4318 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4319 | break; |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4320 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4321 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4322 | (void) SyncCacheViewAuthenticPixels(image_view,exception); |
| 4323 | break; |
| 4324 | } |
| 4325 | case ReplaceMethod: |
| 4326 | { |
| 4327 | MagickBooleanType |
| 4328 | sync; |
| 4329 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4330 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4331 | pixel, |
| 4332 | target; |
| 4333 | |
cristy | f05d494 | 2012-03-17 16:26:09 +0000 | [diff] [blame] | 4334 | (void) GetOneCacheViewVirtualPixelInfo(image_view,x,y,&target, |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4335 | exception); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4336 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4337 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4338 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4339 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4340 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4341 | register ssize_t |
| 4342 | x; |
| 4343 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4344 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4345 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4346 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4347 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4348 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4349 | { |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4350 | GetPixelInfoPixel(image,q,&pixel); |
| 4351 | if (IsFuzzyEquivalencePixelInfo(&pixel,&target) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4352 | { |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4353 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4354 | continue; |
| 4355 | } |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4356 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4357 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4358 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4359 | } |
| 4360 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4361 | if (sync == MagickFalse) |
| 4362 | break; |
| 4363 | } |
| 4364 | break; |
| 4365 | } |
| 4366 | case FloodfillMethod: |
| 4367 | case FillToBorderMethod: |
| 4368 | { |
cristy | bd5a96c | 2011-08-21 00:04:26 +0000 | [diff] [blame] | 4369 | ChannelType |
| 4370 | channel_mask; |
| 4371 | |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4372 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4373 | target; |
| 4374 | |
cristy | 3aa9375 | 2011-12-18 15:54:24 +0000 | [diff] [blame] | 4375 | (void) GetOneVirtualPixelInfo(image,TileVirtualPixelMethod,x,y, |
cristy | 5201002 | 2011-10-21 18:07:37 +0000 | [diff] [blame] | 4376 | &target,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4377 | if (primitive_info->method == FillToBorderMethod) |
| 4378 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4379 | target.red=(double) draw_info->border_color.red; |
| 4380 | target.green=(double) draw_info->border_color.green; |
| 4381 | target.blue=(double) draw_info->border_color.blue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4382 | } |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4383 | channel_mask=SetImageChannelMask(image,AlphaChannel); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4384 | status&=FloodfillPaintImage(image,draw_info,&target,x,y, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4385 | primitive_info->method == FloodfillMethod ? MagickFalse : |
cristy | 189e84c | 2011-08-27 18:08:53 +0000 | [diff] [blame] | 4386 | MagickTrue,exception); |
cristy | cf1296e | 2012-08-26 23:40:49 +0000 | [diff] [blame] | 4387 | (void) SetImageChannelMask(image,channel_mask); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4388 | break; |
| 4389 | } |
| 4390 | case ResetMethod: |
| 4391 | { |
| 4392 | MagickBooleanType |
| 4393 | sync; |
| 4394 | |
cristy | 101ab70 | 2011-10-13 13:06:32 +0000 | [diff] [blame] | 4395 | PixelInfo |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4396 | pixel; |
| 4397 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4398 | for (y=0; y < (ssize_t) image->rows; y++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4399 | { |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4400 | register Quantum |
cristy | c47d1f8 | 2009-11-26 01:44:43 +0000 | [diff] [blame] | 4401 | *restrict q; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4402 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4403 | register ssize_t |
| 4404 | x; |
| 4405 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4406 | q=GetCacheViewAuthenticPixels(image_view,0,y,image->columns,1, |
| 4407 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4408 | if (q == (Quantum *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4409 | break; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4410 | for (x=0; x < (ssize_t) image->columns; x++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4411 | { |
cristy | 2ed42f6 | 2011-10-02 19:49:57 +0000 | [diff] [blame] | 4412 | (void) GetFillColor(draw_info,x,y,&pixel,exception); |
cristy | da1f9c1 | 2011-10-02 21:39:49 +0000 | [diff] [blame] | 4413 | SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); |
cristy | ed23157 | 2011-07-14 02:18:59 +0000 | [diff] [blame] | 4414 | q+=GetPixelChannels(image); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4415 | } |
| 4416 | sync=SyncCacheViewAuthenticPixels(image_view,exception); |
| 4417 | if (sync == MagickFalse) |
| 4418 | break; |
| 4419 | } |
| 4420 | break; |
| 4421 | } |
| 4422 | } |
| 4423 | break; |
| 4424 | } |
| 4425 | case TextPrimitive: |
| 4426 | { |
| 4427 | char |
| 4428 | geometry[MaxTextExtent]; |
| 4429 | |
| 4430 | DrawInfo |
| 4431 | *clone_info; |
| 4432 | |
| 4433 | if (primitive_info->text == (char *) NULL) |
| 4434 | break; |
| 4435 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4436 | (void) CloneString(&clone_info->text,primitive_info->text); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4437 | (void) FormatLocaleString(geometry,MaxTextExtent,"%+f%+f", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4438 | primitive_info->point.x,primitive_info->point.y); |
| 4439 | (void) CloneString(&clone_info->geometry,geometry); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4440 | status&=AnnotateImage(image,clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4441 | clone_info=DestroyDrawInfo(clone_info); |
| 4442 | break; |
| 4443 | } |
| 4444 | case ImagePrimitive: |
| 4445 | { |
| 4446 | AffineMatrix |
| 4447 | affine; |
| 4448 | |
| 4449 | char |
| 4450 | composite_geometry[MaxTextExtent]; |
| 4451 | |
| 4452 | Image |
| 4453 | *composite_image; |
| 4454 | |
| 4455 | ImageInfo |
| 4456 | *clone_info; |
| 4457 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 4458 | RectangleInfo |
| 4459 | geometry; |
| 4460 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4461 | ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4462 | x1, |
| 4463 | y1; |
| 4464 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4465 | if (primitive_info->text == (char *) NULL) |
| 4466 | break; |
| 4467 | clone_info=AcquireImageInfo(); |
| 4468 | if (LocaleNCompare(primitive_info->text,"data:",5) == 0) |
| 4469 | composite_image=ReadInlineImage(clone_info,primitive_info->text, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4470 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4471 | else |
| 4472 | { |
| 4473 | (void) CopyMagickString(clone_info->filename,primitive_info->text, |
| 4474 | MaxTextExtent); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4475 | composite_image=ReadImage(clone_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4476 | } |
| 4477 | clone_info=DestroyImageInfo(clone_info); |
| 4478 | if (composite_image == (Image *) NULL) |
| 4479 | break; |
| 4480 | (void) SetImageProgressMonitor(composite_image,(MagickProgressMonitor) |
| 4481 | NULL,(void *) NULL); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4482 | x1=(ssize_t) ceil(primitive_info[1].point.x-0.5); |
| 4483 | y1=(ssize_t) ceil(primitive_info[1].point.y-0.5); |
| 4484 | if (((x1 != 0L) && (x1 != (ssize_t) composite_image->columns)) || |
| 4485 | ((y1 != 0L) && (y1 != (ssize_t) composite_image->rows))) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4486 | { |
| 4487 | char |
| 4488 | geometry[MaxTextExtent]; |
| 4489 | |
| 4490 | /* |
| 4491 | Resize image. |
| 4492 | */ |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4493 | (void) FormatLocaleString(geometry,MaxTextExtent,"%gx%g!", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4494 | primitive_info[1].point.x,primitive_info[1].point.y); |
| 4495 | composite_image->filter=image->filter; |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4496 | (void) TransformImage(&composite_image,(char *) NULL,geometry, |
| 4497 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4498 | } |
cristy | 8a46d82 | 2012-08-28 23:32:39 +0000 | [diff] [blame] | 4499 | if (composite_image->alpha_trait != BlendPixelTrait) |
cristy | 6324088 | 2011-08-05 19:05:27 +0000 | [diff] [blame] | 4500 | (void) SetImageAlphaChannel(composite_image,OpaqueAlphaChannel, |
| 4501 | exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4502 | if (draw_info->alpha != OpaqueAlpha) |
cristy | e941a75 | 2011-10-15 01:52:48 +0000 | [diff] [blame] | 4503 | (void) SetImageAlpha(composite_image,draw_info->alpha,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4504 | SetGeometry(image,&geometry); |
| 4505 | image->gravity=draw_info->gravity; |
| 4506 | geometry.x=x; |
| 4507 | geometry.y=y; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 4508 | (void) FormatLocaleString(composite_geometry,MaxTextExtent, |
cristy | 6d8abba | 2010-06-03 01:10:47 +0000 | [diff] [blame] | 4509 | "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns,(double) |
cristy | e8c25f9 | 2010-06-03 00:53:06 +0000 | [diff] [blame] | 4510 | composite_image->rows,(double) geometry.x,(double) geometry.y); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4511 | (void) ParseGravityGeometry(image,composite_geometry,&geometry,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4512 | affine=draw_info->affine; |
| 4513 | affine.tx=(double) geometry.x; |
| 4514 | affine.ty=(double) geometry.y; |
| 4515 | composite_image->interpolate=image->interpolate; |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4516 | if (draw_info->compose == OverCompositeOp) |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4517 | (void) DrawAffineImage(image,composite_image,&affine,exception); |
cristy | d5f3fc3 | 2011-04-26 14:44:36 +0000 | [diff] [blame] | 4518 | else |
cristy | feb3e96 | 2012-03-29 17:25:55 +0000 | [diff] [blame] | 4519 | (void) CompositeImage(image,composite_image,draw_info->compose, |
cristy | 3917240 | 2012-03-30 13:04:39 +0000 | [diff] [blame] | 4520 | MagickTrue,geometry.x,geometry.y,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4521 | composite_image=DestroyImage(composite_image); |
| 4522 | break; |
| 4523 | } |
| 4524 | default: |
| 4525 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4526 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4527 | mid, |
| 4528 | scale; |
| 4529 | |
| 4530 | DrawInfo |
| 4531 | *clone_info; |
| 4532 | |
| 4533 | if (IsEventLogging() != MagickFalse) |
| 4534 | LogPrimitiveInfo(primitive_info); |
| 4535 | scale=ExpandAffine(&draw_info->affine); |
| 4536 | if ((draw_info->dash_pattern != (double *) NULL) && |
| 4537 | (draw_info->dash_pattern[0] != 0.0) && |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 4538 | ((scale*draw_info->stroke_width) >= MagickEpsilon) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4539 | (draw_info->stroke.alpha != (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4540 | { |
| 4541 | /* |
| 4542 | Draw dash polygon. |
| 4543 | */ |
| 4544 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4545 | clone_info->stroke_width=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4546 | clone_info->stroke.alpha=(Quantum) TransparentAlpha; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4547 | status&=DrawPolygonPrimitive(image,clone_info,primitive_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4548 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4549 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4550 | (void) DrawDashPolygon(draw_info,primitive_info,image,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4551 | break; |
| 4552 | } |
| 4553 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
| 4554 | if ((mid > 1.0) && |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4555 | (draw_info->stroke.alpha != (Quantum) TransparentAlpha)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4556 | { |
| 4557 | MagickBooleanType |
| 4558 | closed_path; |
| 4559 | |
| 4560 | /* |
| 4561 | Draw strokes while respecting line cap/join attributes. |
| 4562 | */ |
| 4563 | for (i=0; primitive_info[i].primitive != UndefinedPrimitive; i++) ; |
| 4564 | closed_path= |
| 4565 | (primitive_info[i-1].point.x == primitive_info[0].point.x) && |
| 4566 | (primitive_info[i-1].point.y == primitive_info[0].point.y) ? |
| 4567 | MagickTrue : MagickFalse; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4568 | i=(ssize_t) primitive_info[0].coordinates; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4569 | if ((((draw_info->linecap == RoundCap) || |
| 4570 | (closed_path != MagickFalse)) && |
| 4571 | (draw_info->linejoin == RoundJoin)) || |
| 4572 | (primitive_info[i].primitive != UndefinedPrimitive)) |
| 4573 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4574 | (void) DrawPolygonPrimitive(image,draw_info,primitive_info, |
| 4575 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4576 | break; |
| 4577 | } |
| 4578 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4579 | clone_info->stroke_width=0.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4580 | clone_info->stroke.alpha=(Quantum) TransparentAlpha; |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4581 | status&=DrawPolygonPrimitive(image,clone_info,primitive_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4582 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4583 | clone_info=DestroyDrawInfo(clone_info); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4584 | status&=DrawStrokePolygon(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4585 | break; |
| 4586 | } |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4587 | status&=DrawPolygonPrimitive(image,draw_info,primitive_info,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4588 | break; |
| 4589 | } |
| 4590 | } |
| 4591 | image_view=DestroyCacheView(image_view); |
| 4592 | if (image->debug != MagickFalse) |
| 4593 | (void) LogMagickEvent(DrawEvent,GetMagickModule()," end draw-primitive"); |
| 4594 | return(status != 0 ? MagickTrue : MagickFalse); |
| 4595 | } |
| 4596 | |
| 4597 | /* |
| 4598 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4599 | % % |
| 4600 | % % |
| 4601 | % % |
| 4602 | + D r a w S t r o k e P o l y g o n % |
| 4603 | % % |
| 4604 | % % |
| 4605 | % % |
| 4606 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4607 | % |
| 4608 | % DrawStrokePolygon() draws a stroked polygon (line, rectangle, ellipse) on |
| 4609 | % the image while respecting the line cap and join attributes. |
| 4610 | % |
| 4611 | % The format of the DrawStrokePolygon method is: |
| 4612 | % |
| 4613 | % MagickBooleanType DrawStrokePolygon(Image *image, |
| 4614 | % const DrawInfo *draw_info,const PrimitiveInfo *primitive_info) |
| 4615 | % |
| 4616 | % A description of each parameter follows: |
| 4617 | % |
| 4618 | % o image: the image. |
| 4619 | % |
| 4620 | % o draw_info: the draw info. |
| 4621 | % |
| 4622 | % o primitive_info: Specifies a pointer to a PrimitiveInfo structure. |
| 4623 | % |
| 4624 | % |
| 4625 | */ |
| 4626 | |
| 4627 | static void DrawRoundLinecap(Image *image,const DrawInfo *draw_info, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4628 | const PrimitiveInfo *primitive_info,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4629 | { |
| 4630 | PrimitiveInfo |
| 4631 | linecap[5]; |
| 4632 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4633 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4634 | i; |
| 4635 | |
| 4636 | for (i=0; i < 4; i++) |
| 4637 | linecap[i]=(*primitive_info); |
| 4638 | linecap[0].coordinates=4; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 4639 | linecap[1].point.x+=(double) (10.0*MagickEpsilon); |
| 4640 | linecap[2].point.x+=(double) (10.0*MagickEpsilon); |
| 4641 | linecap[2].point.y+=(double) (10.0*MagickEpsilon); |
| 4642 | linecap[3].point.y+=(double) (10.0*MagickEpsilon); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4643 | linecap[4].primitive=UndefinedPrimitive; |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4644 | (void) DrawPolygonPrimitive(image,draw_info,linecap,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4645 | } |
| 4646 | |
| 4647 | static MagickBooleanType DrawStrokePolygon(Image *image, |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4648 | const DrawInfo *draw_info,const PrimitiveInfo *primitive_info, |
| 4649 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4650 | { |
| 4651 | DrawInfo |
| 4652 | *clone_info; |
| 4653 | |
| 4654 | MagickBooleanType |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4655 | closed_path; |
| 4656 | |
| 4657 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4658 | status; |
| 4659 | |
| 4660 | PrimitiveInfo |
| 4661 | *stroke_polygon; |
| 4662 | |
| 4663 | register const PrimitiveInfo |
| 4664 | *p, |
| 4665 | *q; |
| 4666 | |
| 4667 | /* |
| 4668 | Draw stroked polygon. |
| 4669 | */ |
| 4670 | if (image->debug != MagickFalse) |
| 4671 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4672 | " begin draw-stroke-polygon"); |
| 4673 | clone_info=CloneDrawInfo((ImageInfo *) NULL,draw_info); |
| 4674 | clone_info->fill=draw_info->stroke; |
cristy | 2d2d562 | 2012-01-19 19:11:29 +0000 | [diff] [blame] | 4675 | if (clone_info->fill_pattern != (Image *) NULL) |
| 4676 | clone_info->fill_pattern=DestroyImage(clone_info->fill_pattern); |
cristy | 2195b75 | 2012-01-19 16:04:04 +0000 | [diff] [blame] | 4677 | if (clone_info->stroke_pattern != (Image *) NULL) |
cristy | 2d2d562 | 2012-01-19 19:11:29 +0000 | [diff] [blame] | 4678 | clone_info->fill_pattern=CloneImage(clone_info->stroke_pattern,0,0, |
| 4679 | MagickTrue,exception); |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4680 | clone_info->stroke.alpha=(Quantum) TransparentAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4681 | clone_info->stroke_width=0.0; |
| 4682 | clone_info->fill_rule=NonZeroRule; |
| 4683 | status=MagickTrue; |
| 4684 | for (p=primitive_info; p->primitive != UndefinedPrimitive; p+=p->coordinates) |
| 4685 | { |
| 4686 | stroke_polygon=TraceStrokePolygon(draw_info,p); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4687 | status&=DrawPolygonPrimitive(image,clone_info,stroke_polygon,exception); |
| 4688 | if (status == 0) |
| 4689 | break; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4690 | stroke_polygon=(PrimitiveInfo *) RelinquishMagickMemory(stroke_polygon); |
| 4691 | q=p+p->coordinates-1; |
| 4692 | closed_path=(q->point.x == p->point.x) && (q->point.y == p->point.y) ? |
| 4693 | MagickTrue : MagickFalse; |
| 4694 | if ((draw_info->linecap == RoundCap) && (closed_path == MagickFalse)) |
| 4695 | { |
cristy | 947cb4c | 2011-10-20 18:41:46 +0000 | [diff] [blame] | 4696 | DrawRoundLinecap(image,draw_info,p,exception); |
| 4697 | DrawRoundLinecap(image,draw_info,q,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4698 | } |
| 4699 | } |
| 4700 | clone_info=DestroyDrawInfo(clone_info); |
| 4701 | if (image->debug != MagickFalse) |
| 4702 | (void) LogMagickEvent(DrawEvent,GetMagickModule(), |
| 4703 | " end draw-stroke-polygon"); |
cristy | 8a77f14 | 2013-08-14 12:44:38 +0000 | [diff] [blame] | 4704 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
| 4707 | /* |
| 4708 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4709 | % % |
| 4710 | % % |
| 4711 | % % |
| 4712 | % G e t A f f i n e M a t r i x % |
| 4713 | % % |
| 4714 | % % |
| 4715 | % % |
| 4716 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4717 | % |
| 4718 | % GetAffineMatrix() returns an AffineMatrix initialized to the identity |
| 4719 | % matrix. |
| 4720 | % |
| 4721 | % The format of the GetAffineMatrix method is: |
| 4722 | % |
| 4723 | % void GetAffineMatrix(AffineMatrix *affine_matrix) |
| 4724 | % |
| 4725 | % A description of each parameter follows: |
| 4726 | % |
| 4727 | % o affine_matrix: the affine matrix. |
| 4728 | % |
| 4729 | */ |
| 4730 | MagickExport void GetAffineMatrix(AffineMatrix *affine_matrix) |
| 4731 | { |
| 4732 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 4733 | assert(affine_matrix != (AffineMatrix *) NULL); |
| 4734 | (void) ResetMagickMemory(affine_matrix,0,sizeof(*affine_matrix)); |
| 4735 | affine_matrix->sx=1.0; |
| 4736 | affine_matrix->sy=1.0; |
| 4737 | } |
| 4738 | |
| 4739 | /* |
| 4740 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4741 | % % |
| 4742 | % % |
| 4743 | % % |
| 4744 | + G e t D r a w I n f o % |
| 4745 | % % |
| 4746 | % % |
| 4747 | % % |
| 4748 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4749 | % |
anthony | 9c88e8f | 2011-09-29 11:31:53 +0000 | [diff] [blame] | 4750 | % GetDrawInfo() initializes draw_info to default values from image_info. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4751 | % |
| 4752 | % The format of the GetDrawInfo method is: |
| 4753 | % |
| 4754 | % void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) |
| 4755 | % |
| 4756 | % A description of each parameter follows: |
| 4757 | % |
| 4758 | % o image_info: the image info.. |
| 4759 | % |
| 4760 | % o draw_info: the draw info. |
| 4761 | % |
| 4762 | */ |
| 4763 | MagickExport void GetDrawInfo(const ImageInfo *image_info,DrawInfo *draw_info) |
| 4764 | { |
| 4765 | const char |
| 4766 | *option; |
| 4767 | |
| 4768 | ExceptionInfo |
| 4769 | *exception; |
| 4770 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4771 | /* |
| 4772 | Initialize draw attributes. |
| 4773 | */ |
| 4774 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 4775 | assert(draw_info != (DrawInfo *) NULL); |
| 4776 | (void) ResetMagickMemory(draw_info,0,sizeof(*draw_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4777 | GetAffineMatrix(&draw_info->affine); |
| 4778 | exception=AcquireExceptionInfo(); |
cristy | fad60c9 | 2012-01-19 18:32:39 +0000 | [diff] [blame] | 4779 | (void) QueryColorCompliance("#000F",AllCompliance,&draw_info->fill, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4780 | exception); |
dirk | e191b32 | 2013-09-23 23:37:07 +0000 | [diff] [blame] | 4781 | (void) QueryColorCompliance("#FFFF",AllCompliance,&draw_info->stroke, |
cristy | 9950d57 | 2011-10-01 18:22:35 +0000 | [diff] [blame] | 4782 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4783 | draw_info->stroke_width=1.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4784 | draw_info->alpha=OpaqueAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4785 | draw_info->fill_rule=EvenOddRule; |
| 4786 | draw_info->linecap=ButtCap; |
| 4787 | draw_info->linejoin=MiterJoin; |
| 4788 | draw_info->miterlimit=10; |
| 4789 | draw_info->decorate=NoDecoration; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4790 | draw_info->pointsize=12.0; |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 4791 | draw_info->undercolor.alpha=(Quantum) TransparentAlpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4792 | draw_info->compose=OverCompositeOp; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4793 | draw_info->render=MagickTrue; |
| 4794 | draw_info->debug=IsEventLogging(); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4795 | if (image_info != (ImageInfo *) NULL) |
| 4796 | { |
| 4797 | draw_info->stroke_antialias=image_info->antialias; |
| 4798 | if (image_info->font != (char *) NULL) |
| 4799 | draw_info->font=AcquireString(image_info->font); |
| 4800 | if (image_info->density != (char *) NULL) |
| 4801 | draw_info->density=AcquireString(image_info->density); |
| 4802 | draw_info->text_antialias=image_info->antialias; |
| 4803 | if (image_info->pointsize != 0.0) |
| 4804 | draw_info->pointsize=image_info->pointsize; |
| 4805 | draw_info->border_color=image_info->border_color; |
| 4806 | if (image_info->server_name != (char *) NULL) |
| 4807 | draw_info->server_name=AcquireString(image_info->server_name); |
| 4808 | option=GetImageOption(image_info,"encoding"); |
| 4809 | if (option != (const char *) NULL) |
| 4810 | (void) CloneString(&draw_info->encoding,option); |
| 4811 | option=GetImageOption(image_info,"kerning"); |
| 4812 | if (option != (const char *) NULL) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 4813 | draw_info->kerning=StringToDouble(option,(char **) NULL); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4814 | option=GetImageOption(image_info,"interline-spacing"); |
| 4815 | if (option != (const char *) NULL) |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 4816 | draw_info->interline_spacing=StringToDouble(option,(char **) NULL); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4817 | option=GetImageOption(image_info,"interword-spacing"); |
| 4818 | if (option != (const char *) NULL) |
cristy | 9b34e30 | 2011-11-05 02:15:45 +0000 | [diff] [blame] | 4819 | draw_info->interword_spacing=StringToDouble(option,(char **) NULL); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4820 | option=GetImageOption(image_info,"direction"); |
| 4821 | if (option != (const char *) NULL) |
| 4822 | draw_info->direction=(DirectionType) ParseCommandOption( |
| 4823 | MagickDirectionOptions,MagickFalse,option); |
anthony | 42f6c20 | 2011-10-23 10:28:55 +0000 | [diff] [blame] | 4824 | else |
| 4825 | draw_info->direction=UndefinedDirection; |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4826 | option=GetImageOption(image_info,"fill"); |
| 4827 | if (option != (const char *) NULL) |
| 4828 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->fill, |
| 4829 | exception); |
| 4830 | option=GetImageOption(image_info,"stroke"); |
| 4831 | if (option != (const char *) NULL) |
| 4832 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->stroke, |
| 4833 | exception); |
| 4834 | option=GetImageOption(image_info,"strokewidth"); |
| 4835 | if (option != (const char *) NULL) |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 4836 | draw_info->stroke_width=StringToDouble(option,(char **) NULL); |
cristy | 0245b5d | 2011-10-05 12:03:49 +0000 | [diff] [blame] | 4837 | option=GetImageOption(image_info,"undercolor"); |
| 4838 | if (option != (const char *) NULL) |
| 4839 | (void) QueryColorCompliance(option,AllCompliance,&draw_info->undercolor, |
| 4840 | exception); |
| 4841 | option=GetImageOption(image_info,"gravity"); |
| 4842 | if (option != (const char *) NULL) |
| 4843 | draw_info->gravity=(GravityType) ParseCommandOption( |
| 4844 | MagickGravityOptions,MagickFalse,option); |
| 4845 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4846 | exception=DestroyExceptionInfo(exception); |
| 4847 | draw_info->signature=MagickSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4848 | } |
| 4849 | |
| 4850 | /* |
| 4851 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4852 | % % |
| 4853 | % % |
| 4854 | % % |
| 4855 | + P e r m u t a t e % |
| 4856 | % % |
| 4857 | % % |
| 4858 | % % |
| 4859 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4860 | % |
| 4861 | % Permutate() returns the permuation of the (n,k). |
| 4862 | % |
| 4863 | % The format of the Permutate method is: |
| 4864 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4865 | % void Permutate(ssize_t n,ssize_t k) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4866 | % |
| 4867 | % A description of each parameter follows: |
| 4868 | % |
| 4869 | % o n: |
| 4870 | % |
| 4871 | % o k: |
| 4872 | % |
| 4873 | % |
| 4874 | */ |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4875 | static inline double Permutate(const ssize_t n,const ssize_t k) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4876 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4877 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4878 | r; |
| 4879 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4880 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4881 | i; |
| 4882 | |
| 4883 | r=1.0; |
| 4884 | for (i=k+1; i <= n; i++) |
| 4885 | r*=i; |
| 4886 | for (i=1; i <= (n-k); i++) |
| 4887 | r/=i; |
| 4888 | return(r); |
| 4889 | } |
| 4890 | |
| 4891 | /* |
| 4892 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4893 | % % |
| 4894 | % % |
| 4895 | % % |
| 4896 | + T r a c e P r i m i t i v e % |
| 4897 | % % |
| 4898 | % % |
| 4899 | % % |
| 4900 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 4901 | % |
| 4902 | % TracePrimitive is a collection of methods for generating graphic |
| 4903 | % primitives such as arcs, ellipses, paths, etc. |
| 4904 | % |
| 4905 | */ |
| 4906 | |
| 4907 | static void TraceArc(PrimitiveInfo *primitive_info,const PointInfo start, |
| 4908 | const PointInfo end,const PointInfo degrees) |
| 4909 | { |
| 4910 | PointInfo |
| 4911 | center, |
| 4912 | radii; |
| 4913 | |
| 4914 | center.x=0.5*(end.x+start.x); |
| 4915 | center.y=0.5*(end.y+start.y); |
| 4916 | radii.x=fabs(center.x-start.x); |
| 4917 | radii.y=fabs(center.y-start.y); |
| 4918 | TraceEllipse(primitive_info,center,radii,degrees); |
| 4919 | } |
| 4920 | |
| 4921 | static void TraceArcPath(PrimitiveInfo *primitive_info,const PointInfo start, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4922 | const PointInfo end,const PointInfo arc,const double angle, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4923 | const MagickBooleanType large_arc,const MagickBooleanType sweep) |
| 4924 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4925 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4926 | alpha, |
| 4927 | beta, |
| 4928 | delta, |
| 4929 | factor, |
| 4930 | gamma, |
| 4931 | theta; |
| 4932 | |
| 4933 | PointInfo |
| 4934 | center, |
| 4935 | points[3], |
| 4936 | radii; |
| 4937 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4938 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4939 | cosine, |
| 4940 | sine; |
| 4941 | |
| 4942 | register PrimitiveInfo |
| 4943 | *p; |
| 4944 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4945 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4946 | i; |
| 4947 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 4948 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4949 | arc_segments; |
| 4950 | |
| 4951 | if ((start.x == end.x) && (start.y == end.y)) |
| 4952 | { |
| 4953 | TracePoint(primitive_info,end); |
| 4954 | return; |
| 4955 | } |
| 4956 | radii.x=fabs(arc.x); |
| 4957 | radii.y=fabs(arc.y); |
| 4958 | if ((radii.x == 0.0) || (radii.y == 0.0)) |
| 4959 | { |
| 4960 | TraceLine(primitive_info,start,end); |
| 4961 | return; |
| 4962 | } |
| 4963 | cosine=cos(DegreesToRadians(fmod((double) angle,360.0))); |
| 4964 | sine=sin(DegreesToRadians(fmod((double) angle,360.0))); |
| 4965 | center.x=(double) (cosine*(end.x-start.x)/2+sine*(end.y-start.y)/2); |
| 4966 | center.y=(double) (cosine*(end.y-start.y)/2-sine*(end.x-start.x)/2); |
| 4967 | delta=(center.x*center.x)/(radii.x*radii.x)+(center.y*center.y)/ |
| 4968 | (radii.y*radii.y); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 4969 | if (delta < MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4970 | { |
| 4971 | TraceLine(primitive_info,start,end); |
| 4972 | return; |
| 4973 | } |
| 4974 | if (delta > 1.0) |
| 4975 | { |
| 4976 | radii.x*=sqrt((double) delta); |
| 4977 | radii.y*=sqrt((double) delta); |
| 4978 | } |
| 4979 | points[0].x=(double) (cosine*start.x/radii.x+sine*start.y/radii.x); |
| 4980 | points[0].y=(double) (cosine*start.y/radii.y-sine*start.x/radii.y); |
| 4981 | points[1].x=(double) (cosine*end.x/radii.x+sine*end.y/radii.x); |
| 4982 | points[1].y=(double) (cosine*end.y/radii.y-sine*end.x/radii.y); |
| 4983 | alpha=points[1].x-points[0].x; |
| 4984 | beta=points[1].y-points[0].y; |
cristy | 3e3ec3a | 2012-11-03 23:11:06 +0000 | [diff] [blame] | 4985 | factor=PerceptibleReciprocal(alpha*alpha+beta*beta)-0.25; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 4986 | if (factor <= 0.0) |
| 4987 | factor=0.0; |
| 4988 | else |
| 4989 | { |
| 4990 | factor=sqrt((double) factor); |
| 4991 | if (sweep == large_arc) |
| 4992 | factor=(-factor); |
| 4993 | } |
| 4994 | center.x=(double) ((points[0].x+points[1].x)/2-factor*beta); |
| 4995 | center.y=(double) ((points[0].y+points[1].y)/2+factor*alpha); |
| 4996 | alpha=atan2(points[0].y-center.y,points[0].x-center.x); |
| 4997 | theta=atan2(points[1].y-center.y,points[1].x-center.x)-alpha; |
| 4998 | if ((theta < 0.0) && (sweep != MagickFalse)) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 4999 | theta+=(double) (2.0*MagickPI); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5000 | else |
| 5001 | if ((theta > 0.0) && (sweep == MagickFalse)) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5002 | theta-=(double) (2.0*MagickPI); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5003 | arc_segments=(size_t) ceil(fabs((double) (theta/(0.5*MagickPI+ |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5004 | MagickEpsilon)))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5005 | p=primitive_info; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5006 | for (i=0; i < (ssize_t) arc_segments; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5007 | { |
| 5008 | beta=0.5*((alpha+(i+1)*theta/arc_segments)-(alpha+i*theta/arc_segments)); |
| 5009 | gamma=(8.0/3.0)*sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))* |
| 5010 | sin(fmod((double) (0.5*beta),DegreesToRadians(360.0)))/ |
| 5011 | sin(fmod((double) beta,DegreesToRadians(360.0))); |
| 5012 | points[0].x=(double) (center.x+cos(fmod((double) (alpha+(double) i*theta/ |
| 5013 | arc_segments),DegreesToRadians(360.0)))-gamma*sin(fmod((double) (alpha+ |
| 5014 | (double) i*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5015 | points[0].y=(double) (center.y+sin(fmod((double) (alpha+(double) i*theta/ |
| 5016 | arc_segments),DegreesToRadians(360.0)))+gamma*cos(fmod((double) (alpha+ |
| 5017 | (double) i*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5018 | points[2].x=(double) (center.x+cos(fmod((double) (alpha+(double) (i+1)* |
| 5019 | theta/arc_segments),DegreesToRadians(360.0)))); |
| 5020 | points[2].y=(double) (center.y+sin(fmod((double) (alpha+(double) (i+1)* |
| 5021 | theta/arc_segments),DegreesToRadians(360.0)))); |
| 5022 | points[1].x=(double) (points[2].x+gamma*sin(fmod((double) (alpha+(double) |
| 5023 | (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5024 | points[1].y=(double) (points[2].y-gamma*cos(fmod((double) (alpha+(double) |
| 5025 | (i+1)*theta/arc_segments),DegreesToRadians(360.0)))); |
| 5026 | p->point.x=(p == primitive_info) ? start.x : (p-1)->point.x; |
| 5027 | p->point.y=(p == primitive_info) ? start.y : (p-1)->point.y; |
| 5028 | (p+1)->point.x=(double) (cosine*radii.x*points[0].x-sine*radii.y* |
| 5029 | points[0].y); |
| 5030 | (p+1)->point.y=(double) (sine*radii.x*points[0].x+cosine*radii.y* |
| 5031 | points[0].y); |
| 5032 | (p+2)->point.x=(double) (cosine*radii.x*points[1].x-sine*radii.y* |
| 5033 | points[1].y); |
| 5034 | (p+2)->point.y=(double) (sine*radii.x*points[1].x+cosine*radii.y* |
| 5035 | points[1].y); |
| 5036 | (p+3)->point.x=(double) (cosine*radii.x*points[2].x-sine*radii.y* |
| 5037 | points[2].y); |
| 5038 | (p+3)->point.y=(double) (sine*radii.x*points[2].x+cosine*radii.y* |
| 5039 | points[2].y); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5040 | if (i == (ssize_t) (arc_segments-1)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5041 | (p+3)->point=end; |
| 5042 | TraceBezier(p,4); |
| 5043 | p+=p->coordinates; |
| 5044 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5045 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5046 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5047 | { |
| 5048 | p->primitive=primitive_info->primitive; |
| 5049 | p--; |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | static void TraceBezier(PrimitiveInfo *primitive_info, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5054 | const size_t number_coordinates) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5055 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5056 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5057 | alpha, |
| 5058 | *coefficients, |
| 5059 | weight; |
| 5060 | |
| 5061 | PointInfo |
| 5062 | end, |
| 5063 | point, |
| 5064 | *points; |
| 5065 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5066 | register PrimitiveInfo |
| 5067 | *p; |
| 5068 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5069 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5070 | i, |
| 5071 | j; |
| 5072 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5073 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5074 | control_points, |
| 5075 | quantum; |
| 5076 | |
| 5077 | /* |
| 5078 | Allocate coeficients. |
| 5079 | */ |
| 5080 | quantum=number_coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5081 | for (i=0; i < (ssize_t) number_coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5082 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5083 | for (j=i+1; j < (ssize_t) number_coordinates; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5084 | { |
| 5085 | alpha=fabs(primitive_info[j].point.x-primitive_info[i].point.x); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5086 | if (alpha > (double) quantum) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5087 | quantum=(size_t) alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5088 | alpha=fabs(primitive_info[j].point.y-primitive_info[i].point.y); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5089 | if (alpha > (double) quantum) |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5090 | quantum=(size_t) alpha; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5091 | } |
| 5092 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5093 | quantum=(size_t) MagickMin((double) quantum/number_coordinates, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5094 | (double) BezierQuantum); |
| 5095 | control_points=quantum*number_coordinates; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5096 | coefficients=(double *) AcquireQuantumMemory((size_t) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5097 | number_coordinates,sizeof(*coefficients)); |
| 5098 | points=(PointInfo *) AcquireQuantumMemory((size_t) control_points, |
| 5099 | sizeof(*points)); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5100 | if ((coefficients == (double *) NULL) || |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5101 | (points == (PointInfo *) NULL)) |
| 5102 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 5103 | /* |
| 5104 | Compute bezier points. |
| 5105 | */ |
| 5106 | end=primitive_info[number_coordinates-1].point; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5107 | for (i=0; i < (ssize_t) number_coordinates; i++) |
| 5108 | coefficients[i]=Permutate((ssize_t) number_coordinates-1,i); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5109 | weight=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5110 | for (i=0; i < (ssize_t) control_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5111 | { |
| 5112 | p=primitive_info; |
| 5113 | point.x=0.0; |
| 5114 | point.y=0.0; |
| 5115 | alpha=pow((double) (1.0-weight),(double) number_coordinates-1.0); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5116 | for (j=0; j < (ssize_t) number_coordinates; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5117 | { |
| 5118 | point.x+=alpha*coefficients[j]*p->point.x; |
| 5119 | point.y+=alpha*coefficients[j]*p->point.y; |
| 5120 | alpha*=weight/(1.0-weight); |
| 5121 | p++; |
| 5122 | } |
| 5123 | points[i]=point; |
| 5124 | weight+=1.0/control_points; |
| 5125 | } |
| 5126 | /* |
| 5127 | Bezier curves are just short segmented polys. |
| 5128 | */ |
| 5129 | p=primitive_info; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5130 | for (i=0; i < (ssize_t) control_points; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5131 | { |
| 5132 | TracePoint(p,points[i]); |
| 5133 | p+=p->coordinates; |
| 5134 | } |
| 5135 | TracePoint(p,end); |
| 5136 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5137 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5138 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5139 | { |
| 5140 | p->primitive=primitive_info->primitive; |
| 5141 | p--; |
| 5142 | } |
| 5143 | points=(PointInfo *) RelinquishMagickMemory(points); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5144 | coefficients=(double *) RelinquishMagickMemory(coefficients); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5145 | } |
| 5146 | |
| 5147 | static void TraceCircle(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5148 | const PointInfo end) |
| 5149 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5150 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5151 | alpha, |
| 5152 | beta, |
| 5153 | radius; |
| 5154 | |
| 5155 | PointInfo |
| 5156 | offset, |
| 5157 | degrees; |
| 5158 | |
| 5159 | alpha=end.x-start.x; |
| 5160 | beta=end.y-start.y; |
| 5161 | radius=hypot((double) alpha,(double) beta); |
| 5162 | offset.x=(double) radius; |
| 5163 | offset.y=(double) radius; |
| 5164 | degrees.x=0.0; |
| 5165 | degrees.y=360.0; |
| 5166 | TraceEllipse(primitive_info,start,offset,degrees); |
| 5167 | } |
| 5168 | |
| 5169 | static void TraceEllipse(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5170 | const PointInfo stop,const PointInfo degrees) |
| 5171 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5172 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5173 | delta, |
| 5174 | step, |
| 5175 | y; |
| 5176 | |
| 5177 | PointInfo |
| 5178 | angle, |
| 5179 | point; |
| 5180 | |
| 5181 | register PrimitiveInfo |
| 5182 | *p; |
| 5183 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5184 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5185 | i; |
| 5186 | |
| 5187 | /* |
| 5188 | Ellipses are just short segmented polys. |
| 5189 | */ |
| 5190 | if ((stop.x == 0.0) && (stop.y == 0.0)) |
| 5191 | { |
| 5192 | TracePoint(primitive_info,start); |
| 5193 | return; |
| 5194 | } |
| 5195 | delta=2.0/MagickMax(stop.x,stop.y); |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5196 | step=(double) (MagickPI/8.0); |
| 5197 | if ((delta >= 0.0) && (delta < (double) (MagickPI/8.0))) |
| 5198 | step=(double) (MagickPI/(4*(MagickPI/delta/2+0.5))); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5199 | angle.x=DegreesToRadians(degrees.x); |
| 5200 | y=degrees.y; |
| 5201 | while (y < degrees.x) |
| 5202 | y+=360.0; |
cristy | a855f3d | 2012-12-01 13:02:13 +0000 | [diff] [blame] | 5203 | angle.y=(double) DegreesToRadians(y); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5204 | for (p=primitive_info; angle.x < angle.y; angle.x+=step) |
| 5205 | { |
| 5206 | point.x=cos(fmod(angle.x,DegreesToRadians(360.0)))*stop.x+start.x; |
| 5207 | point.y=sin(fmod(angle.x,DegreesToRadians(360.0)))*stop.y+start.y; |
| 5208 | TracePoint(p,point); |
| 5209 | p+=p->coordinates; |
| 5210 | } |
| 5211 | point.x=cos(fmod(angle.y,DegreesToRadians(360.0)))*stop.x+start.x; |
| 5212 | point.y=sin(fmod(angle.y,DegreesToRadians(360.0)))*stop.y+start.y; |
| 5213 | TracePoint(p,point); |
| 5214 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5215 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5216 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5217 | { |
| 5218 | p->primitive=primitive_info->primitive; |
| 5219 | p--; |
| 5220 | } |
| 5221 | } |
| 5222 | |
| 5223 | static void TraceLine(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5224 | const PointInfo end) |
| 5225 | { |
| 5226 | TracePoint(primitive_info,start); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5227 | if ((fabs(start.x-end.x) < MagickEpsilon) && |
| 5228 | (fabs(start.y-end.y) < MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5229 | { |
| 5230 | primitive_info->primitive=PointPrimitive; |
| 5231 | primitive_info->coordinates=1; |
| 5232 | return; |
| 5233 | } |
| 5234 | TracePoint(primitive_info+1,end); |
| 5235 | (primitive_info+1)->primitive=primitive_info->primitive; |
| 5236 | primitive_info->coordinates=2; |
| 5237 | } |
| 5238 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5239 | static size_t TracePath(PrimitiveInfo *primitive_info,const char *path) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5240 | { |
| 5241 | char |
| 5242 | token[MaxTextExtent]; |
| 5243 | |
| 5244 | const char |
| 5245 | *p; |
| 5246 | |
| 5247 | int |
| 5248 | attribute, |
| 5249 | last_attribute; |
| 5250 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5251 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5252 | x, |
| 5253 | y; |
| 5254 | |
| 5255 | PointInfo |
| 5256 | end, |
| 5257 | points[4], |
| 5258 | point, |
| 5259 | start; |
| 5260 | |
| 5261 | PrimitiveType |
| 5262 | primitive_type; |
| 5263 | |
| 5264 | register PrimitiveInfo |
| 5265 | *q; |
| 5266 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5267 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5268 | i; |
| 5269 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5270 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5271 | number_coordinates, |
| 5272 | z_count; |
| 5273 | |
| 5274 | attribute=0; |
cristy | 206c26e | 2013-11-07 18:04:21 +0000 | [diff] [blame] | 5275 | end.x=0.0; |
| 5276 | end.y=0.0; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5277 | point.x=0.0; |
| 5278 | point.y=0.0; |
| 5279 | start.x=0.0; |
| 5280 | start.y=0.0; |
| 5281 | number_coordinates=0; |
| 5282 | z_count=0; |
cristy | 54ebd8d | 2014-01-14 01:14:23 +0000 | [diff] [blame] | 5283 | (void) ResetMagickMemory(points,0,sizeof(*points)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5284 | primitive_type=primitive_info->primitive; |
| 5285 | q=primitive_info; |
| 5286 | for (p=path; *p != '\0'; ) |
| 5287 | { |
| 5288 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 5289 | p++; |
| 5290 | if (*p == '\0') |
| 5291 | break; |
| 5292 | last_attribute=attribute; |
| 5293 | attribute=(int) (*p++); |
| 5294 | switch (attribute) |
| 5295 | { |
| 5296 | case 'a': |
| 5297 | case 'A': |
| 5298 | { |
| 5299 | MagickBooleanType |
| 5300 | large_arc, |
| 5301 | sweep; |
| 5302 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5303 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5304 | angle; |
| 5305 | |
| 5306 | PointInfo |
| 5307 | arc; |
| 5308 | |
| 5309 | /* |
| 5310 | Compute arc points. |
| 5311 | */ |
| 5312 | do |
| 5313 | { |
| 5314 | GetMagickToken(p,&p,token); |
| 5315 | if (*token == ',') |
| 5316 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5317 | arc.x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5318 | GetMagickToken(p,&p,token); |
| 5319 | if (*token == ',') |
| 5320 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5321 | arc.y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5322 | GetMagickToken(p,&p,token); |
| 5323 | if (*token == ',') |
| 5324 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5325 | angle=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5326 | GetMagickToken(p,&p,token); |
| 5327 | if (*token == ',') |
| 5328 | GetMagickToken(p,&p,token); |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5329 | large_arc=StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5330 | GetMagickToken(p,&p,token); |
| 5331 | if (*token == ',') |
| 5332 | GetMagickToken(p,&p,token); |
cristy | f2f2727 | 2009-12-17 14:48:46 +0000 | [diff] [blame] | 5333 | sweep=StringToLong(token) != 0 ? MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5334 | GetMagickToken(p,&p,token); |
| 5335 | if (*token == ',') |
| 5336 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5337 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5338 | GetMagickToken(p,&p,token); |
| 5339 | if (*token == ',') |
| 5340 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5341 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5342 | end.x=(double) (attribute == (int) 'A' ? x : point.x+x); |
| 5343 | end.y=(double) (attribute == (int) 'A' ? y : point.y+y); |
| 5344 | TraceArcPath(q,point,end,arc,angle,large_arc,sweep); |
| 5345 | q+=q->coordinates; |
| 5346 | point=end; |
cristy | 671fcfc | 2011-12-13 13:28:31 +0000 | [diff] [blame] | 5347 | while (isspace((int) ((unsigned char) *p)) != 0) |
| 5348 | p++; |
| 5349 | if (*p == ',') |
| 5350 | p++; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5351 | } while (IsPoint(p) != MagickFalse); |
| 5352 | break; |
| 5353 | } |
| 5354 | case 'c': |
| 5355 | case 'C': |
| 5356 | { |
| 5357 | /* |
| 5358 | Compute bezier points. |
| 5359 | */ |
| 5360 | do |
| 5361 | { |
| 5362 | points[0]=point; |
| 5363 | for (i=1; i < 4; i++) |
| 5364 | { |
| 5365 | GetMagickToken(p,&p,token); |
| 5366 | if (*token == ',') |
| 5367 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5368 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5369 | GetMagickToken(p,&p,token); |
| 5370 | if (*token == ',') |
| 5371 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5372 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5373 | end.x=(double) (attribute == (int) 'C' ? x : point.x+x); |
| 5374 | end.y=(double) (attribute == (int) 'C' ? y : point.y+y); |
| 5375 | points[i]=end; |
| 5376 | } |
| 5377 | for (i=0; i < 4; i++) |
| 5378 | (q+i)->point=points[i]; |
| 5379 | TraceBezier(q,4); |
| 5380 | q+=q->coordinates; |
| 5381 | point=end; |
| 5382 | } while (IsPoint(p) != MagickFalse); |
| 5383 | break; |
| 5384 | } |
| 5385 | case 'H': |
| 5386 | case 'h': |
| 5387 | { |
| 5388 | do |
| 5389 | { |
| 5390 | GetMagickToken(p,&p,token); |
| 5391 | if (*token == ',') |
| 5392 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5393 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5394 | point.x=(double) (attribute == (int) 'H' ? x: point.x+x); |
| 5395 | TracePoint(q,point); |
| 5396 | q+=q->coordinates; |
| 5397 | } while (IsPoint(p) != MagickFalse); |
| 5398 | break; |
| 5399 | } |
| 5400 | case 'l': |
| 5401 | case 'L': |
| 5402 | { |
| 5403 | do |
| 5404 | { |
| 5405 | GetMagickToken(p,&p,token); |
| 5406 | if (*token == ',') |
| 5407 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5408 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5409 | GetMagickToken(p,&p,token); |
| 5410 | if (*token == ',') |
| 5411 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5412 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5413 | point.x=(double) (attribute == (int) 'L' ? x : point.x+x); |
| 5414 | point.y=(double) (attribute == (int) 'L' ? y : point.y+y); |
| 5415 | TracePoint(q,point); |
| 5416 | q+=q->coordinates; |
| 5417 | } while (IsPoint(p) != MagickFalse); |
| 5418 | break; |
| 5419 | } |
| 5420 | case 'M': |
| 5421 | case 'm': |
| 5422 | { |
| 5423 | if (q != primitive_info) |
| 5424 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5425 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5426 | number_coordinates+=primitive_info->coordinates; |
| 5427 | primitive_info=q; |
| 5428 | } |
| 5429 | i=0; |
| 5430 | do |
| 5431 | { |
| 5432 | GetMagickToken(p,&p,token); |
| 5433 | if (*token == ',') |
| 5434 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5435 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5436 | GetMagickToken(p,&p,token); |
| 5437 | if (*token == ',') |
| 5438 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5439 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5440 | point.x=(double) (attribute == (int) 'M' ? x : point.x+x); |
| 5441 | point.y=(double) (attribute == (int) 'M' ? y : point.y+y); |
| 5442 | if (i == 0) |
| 5443 | start=point; |
| 5444 | i++; |
| 5445 | TracePoint(q,point); |
| 5446 | q+=q->coordinates; |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5447 | if ((i != 0) && (attribute == (int) 'M')) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5448 | { |
| 5449 | TracePoint(q,point); |
| 5450 | q+=q->coordinates; |
| 5451 | } |
| 5452 | } while (IsPoint(p) != MagickFalse); |
| 5453 | break; |
| 5454 | } |
| 5455 | case 'q': |
| 5456 | case 'Q': |
| 5457 | { |
| 5458 | /* |
| 5459 | Compute bezier points. |
| 5460 | */ |
| 5461 | do |
| 5462 | { |
| 5463 | points[0]=point; |
| 5464 | for (i=1; i < 3; i++) |
| 5465 | { |
| 5466 | GetMagickToken(p,&p,token); |
| 5467 | if (*token == ',') |
| 5468 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5469 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5470 | GetMagickToken(p,&p,token); |
| 5471 | if (*token == ',') |
| 5472 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5473 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5474 | if (*p == ',') |
| 5475 | p++; |
| 5476 | end.x=(double) (attribute == (int) 'Q' ? x : point.x+x); |
| 5477 | end.y=(double) (attribute == (int) 'Q' ? y : point.y+y); |
| 5478 | points[i]=end; |
| 5479 | } |
| 5480 | for (i=0; i < 3; i++) |
| 5481 | (q+i)->point=points[i]; |
| 5482 | TraceBezier(q,3); |
| 5483 | q+=q->coordinates; |
| 5484 | point=end; |
| 5485 | } while (IsPoint(p) != MagickFalse); |
| 5486 | break; |
| 5487 | } |
| 5488 | case 's': |
| 5489 | case 'S': |
| 5490 | { |
| 5491 | /* |
| 5492 | Compute bezier points. |
| 5493 | */ |
| 5494 | do |
| 5495 | { |
| 5496 | points[0]=points[3]; |
| 5497 | points[1].x=2.0*points[3].x-points[2].x; |
| 5498 | points[1].y=2.0*points[3].y-points[2].y; |
| 5499 | for (i=2; i < 4; i++) |
| 5500 | { |
| 5501 | GetMagickToken(p,&p,token); |
| 5502 | if (*token == ',') |
| 5503 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5504 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5505 | GetMagickToken(p,&p,token); |
| 5506 | if (*token == ',') |
| 5507 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5508 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5509 | if (*p == ',') |
| 5510 | p++; |
| 5511 | end.x=(double) (attribute == (int) 'S' ? x : point.x+x); |
| 5512 | end.y=(double) (attribute == (int) 'S' ? y : point.y+y); |
| 5513 | points[i]=end; |
| 5514 | } |
| 5515 | if (strchr("CcSs",last_attribute) == (char *) NULL) |
| 5516 | { |
| 5517 | points[0]=points[2]; |
| 5518 | points[1]=points[3]; |
| 5519 | } |
| 5520 | for (i=0; i < 4; i++) |
| 5521 | (q+i)->point=points[i]; |
| 5522 | TraceBezier(q,4); |
| 5523 | q+=q->coordinates; |
| 5524 | point=end; |
| 5525 | } while (IsPoint(p) != MagickFalse); |
| 5526 | break; |
| 5527 | } |
| 5528 | case 't': |
| 5529 | case 'T': |
| 5530 | { |
| 5531 | /* |
| 5532 | Compute bezier points. |
| 5533 | */ |
| 5534 | do |
| 5535 | { |
| 5536 | points[0]=points[2]; |
| 5537 | points[1].x=2.0*points[2].x-points[1].x; |
| 5538 | points[1].y=2.0*points[2].y-points[1].y; |
| 5539 | for (i=2; i < 3; i++) |
| 5540 | { |
| 5541 | GetMagickToken(p,&p,token); |
| 5542 | if (*token == ',') |
| 5543 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5544 | x=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5545 | GetMagickToken(p,&p,token); |
| 5546 | if (*token == ',') |
| 5547 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5548 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5549 | end.x=(double) (attribute == (int) 'T' ? x : point.x+x); |
| 5550 | end.y=(double) (attribute == (int) 'T' ? y : point.y+y); |
| 5551 | points[i]=end; |
| 5552 | } |
| 5553 | if (strchr("QqTt",last_attribute) == (char *) NULL) |
| 5554 | { |
| 5555 | points[0]=points[2]; |
| 5556 | points[1]=points[3]; |
| 5557 | } |
| 5558 | for (i=0; i < 3; i++) |
| 5559 | (q+i)->point=points[i]; |
| 5560 | TraceBezier(q,3); |
| 5561 | q+=q->coordinates; |
| 5562 | point=end; |
| 5563 | } while (IsPoint(p) != MagickFalse); |
| 5564 | break; |
| 5565 | } |
| 5566 | case 'v': |
| 5567 | case 'V': |
| 5568 | { |
| 5569 | do |
| 5570 | { |
| 5571 | GetMagickToken(p,&p,token); |
| 5572 | if (*token == ',') |
| 5573 | GetMagickToken(p,&p,token); |
cristy | dbdd0e3 | 2011-11-04 23:29:40 +0000 | [diff] [blame] | 5574 | y=StringToDouble(token,(char **) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5575 | point.y=(double) (attribute == (int) 'V' ? y : point.y+y); |
| 5576 | TracePoint(q,point); |
| 5577 | q+=q->coordinates; |
| 5578 | } while (IsPoint(p) != MagickFalse); |
| 5579 | break; |
| 5580 | } |
| 5581 | case 'z': |
| 5582 | case 'Z': |
| 5583 | { |
| 5584 | point=start; |
| 5585 | TracePoint(q,point); |
| 5586 | q+=q->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5587 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5588 | number_coordinates+=primitive_info->coordinates; |
| 5589 | primitive_info=q; |
| 5590 | z_count++; |
| 5591 | break; |
| 5592 | } |
| 5593 | default: |
| 5594 | { |
| 5595 | if (isalpha((int) ((unsigned char) attribute)) != 0) |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 5596 | (void) FormatLocaleFile(stderr,"attribute not recognized: %c\n", |
| 5597 | attribute); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5598 | break; |
| 5599 | } |
| 5600 | } |
| 5601 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5602 | primitive_info->coordinates=(size_t) (q-primitive_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5603 | number_coordinates+=primitive_info->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5604 | for (i=0; i < (ssize_t) number_coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5605 | { |
| 5606 | q--; |
| 5607 | q->primitive=primitive_type; |
| 5608 | if (z_count > 1) |
| 5609 | q->method=FillToBorderMethod; |
| 5610 | } |
| 5611 | q=primitive_info; |
| 5612 | return(number_coordinates); |
| 5613 | } |
| 5614 | |
| 5615 | static void TraceRectangle(PrimitiveInfo *primitive_info,const PointInfo start, |
| 5616 | const PointInfo end) |
| 5617 | { |
| 5618 | PointInfo |
| 5619 | point; |
| 5620 | |
| 5621 | register PrimitiveInfo |
| 5622 | *p; |
| 5623 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5624 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5625 | i; |
| 5626 | |
| 5627 | p=primitive_info; |
| 5628 | TracePoint(p,start); |
| 5629 | p+=p->coordinates; |
| 5630 | point.x=start.x; |
| 5631 | point.y=end.y; |
| 5632 | TracePoint(p,point); |
| 5633 | p+=p->coordinates; |
| 5634 | TracePoint(p,end); |
| 5635 | p+=p->coordinates; |
| 5636 | point.x=end.x; |
| 5637 | point.y=start.y; |
| 5638 | TracePoint(p,point); |
| 5639 | p+=p->coordinates; |
| 5640 | TracePoint(p,start); |
| 5641 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5642 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5643 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5644 | { |
| 5645 | p->primitive=primitive_info->primitive; |
| 5646 | p--; |
| 5647 | } |
| 5648 | } |
| 5649 | |
| 5650 | static void TraceRoundRectangle(PrimitiveInfo *primitive_info, |
| 5651 | const PointInfo start,const PointInfo end,PointInfo arc) |
| 5652 | { |
| 5653 | PointInfo |
| 5654 | degrees, |
| 5655 | offset, |
| 5656 | point; |
| 5657 | |
| 5658 | register PrimitiveInfo |
| 5659 | *p; |
| 5660 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5661 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5662 | i; |
| 5663 | |
| 5664 | p=primitive_info; |
| 5665 | offset.x=fabs(end.x-start.x); |
| 5666 | offset.y=fabs(end.y-start.y); |
| 5667 | if (arc.x > (0.5*offset.x)) |
| 5668 | arc.x=0.5*offset.x; |
| 5669 | if (arc.y > (0.5*offset.y)) |
| 5670 | arc.y=0.5*offset.y; |
| 5671 | point.x=start.x+offset.x-arc.x; |
| 5672 | point.y=start.y+arc.y; |
| 5673 | degrees.x=270.0; |
| 5674 | degrees.y=360.0; |
| 5675 | TraceEllipse(p,point,arc,degrees); |
| 5676 | p+=p->coordinates; |
| 5677 | point.x=start.x+offset.x-arc.x; |
| 5678 | point.y=start.y+offset.y-arc.y; |
| 5679 | degrees.x=0.0; |
| 5680 | degrees.y=90.0; |
| 5681 | TraceEllipse(p,point,arc,degrees); |
| 5682 | p+=p->coordinates; |
| 5683 | point.x=start.x+arc.x; |
| 5684 | point.y=start.y+offset.y-arc.y; |
| 5685 | degrees.x=90.0; |
| 5686 | degrees.y=180.0; |
| 5687 | TraceEllipse(p,point,arc,degrees); |
| 5688 | p+=p->coordinates; |
| 5689 | point.x=start.x+arc.x; |
| 5690 | point.y=start.y+arc.y; |
| 5691 | degrees.x=180.0; |
| 5692 | degrees.y=270.0; |
| 5693 | TraceEllipse(p,point,arc,degrees); |
| 5694 | p+=p->coordinates; |
| 5695 | TracePoint(p,primitive_info->point); |
| 5696 | p+=p->coordinates; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5697 | primitive_info->coordinates=(size_t) (p-primitive_info); |
| 5698 | for (i=0; i < (ssize_t) primitive_info->coordinates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5699 | { |
| 5700 | p->primitive=primitive_info->primitive; |
| 5701 | p--; |
| 5702 | } |
| 5703 | } |
| 5704 | |
| 5705 | static void TraceSquareLinecap(PrimitiveInfo *primitive_info, |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5706 | const size_t number_vertices,const double offset) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5707 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5708 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5709 | distance; |
| 5710 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5711 | register double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5712 | dx, |
| 5713 | dy; |
| 5714 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5715 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5716 | i; |
| 5717 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5718 | ssize_t |
| 5719 | j; |
| 5720 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5721 | dx=0.0; |
| 5722 | dy=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5723 | for (i=1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5724 | { |
| 5725 | dx=primitive_info[0].point.x-primitive_info[i].point.x; |
| 5726 | dy=primitive_info[0].point.y-primitive_info[i].point.y; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5727 | if ((fabs((double) dx) >= MagickEpsilon) || |
| 5728 | (fabs((double) dy) >= MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5729 | break; |
| 5730 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5731 | if (i == (ssize_t) number_vertices) |
| 5732 | i=(ssize_t) number_vertices-1L; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5733 | distance=hypot((double) dx,(double) dy); |
| 5734 | primitive_info[0].point.x=(double) (primitive_info[i].point.x+ |
| 5735 | dx*(distance+offset)/distance); |
| 5736 | primitive_info[0].point.y=(double) (primitive_info[i].point.y+ |
| 5737 | dy*(distance+offset)/distance); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5738 | for (j=(ssize_t) number_vertices-2; j >= 0; j--) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5739 | { |
| 5740 | dx=primitive_info[number_vertices-1].point.x-primitive_info[j].point.x; |
| 5741 | dy=primitive_info[number_vertices-1].point.y-primitive_info[j].point.y; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5742 | if ((fabs((double) dx) >= MagickEpsilon) || |
| 5743 | (fabs((double) dy) >= MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5744 | break; |
| 5745 | } |
| 5746 | distance=hypot((double) dx,(double) dy); |
| 5747 | primitive_info[number_vertices-1].point.x=(double) (primitive_info[j].point.x+ |
| 5748 | dx*(distance+offset)/distance); |
| 5749 | primitive_info[number_vertices-1].point.y=(double) (primitive_info[j].point.y+ |
| 5750 | dy*(distance+offset)/distance); |
| 5751 | } |
| 5752 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5753 | static inline double DrawEpsilonReciprocal(const double x) |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5754 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5755 | #define DrawEpsilon ((double) 1.0e-10) |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5756 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5757 | double sign = x < (double) 0.0 ? (double) -1.0 : |
| 5758 | (double) 1.0; |
| 5759 | return((sign*x) >= DrawEpsilon ? (double) 1.0/x : sign*( |
| 5760 | (double) 1.0/DrawEpsilon)); |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5761 | } |
| 5762 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5763 | static PrimitiveInfo *TraceStrokePolygon(const DrawInfo *draw_info, |
| 5764 | const PrimitiveInfo *primitive_info) |
| 5765 | { |
| 5766 | typedef struct _LineSegment |
| 5767 | { |
| 5768 | double |
| 5769 | p, |
| 5770 | q; |
| 5771 | } LineSegment; |
| 5772 | |
| 5773 | LineSegment |
| 5774 | dx, |
| 5775 | dy, |
| 5776 | inverse_slope, |
| 5777 | slope, |
| 5778 | theta; |
| 5779 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5780 | MagickBooleanType |
| 5781 | closed_path; |
| 5782 | |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5783 | double |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5784 | delta_theta, |
| 5785 | dot_product, |
| 5786 | mid, |
| 5787 | miterlimit; |
| 5788 | |
| 5789 | PointInfo |
| 5790 | box_p[5], |
| 5791 | box_q[5], |
| 5792 | center, |
| 5793 | offset, |
| 5794 | *path_p, |
| 5795 | *path_q; |
| 5796 | |
| 5797 | PrimitiveInfo |
| 5798 | *polygon_primitive, |
| 5799 | *stroke_polygon; |
| 5800 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5801 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5802 | i; |
| 5803 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5804 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5805 | arc_segments, |
| 5806 | max_strokes, |
| 5807 | number_vertices; |
| 5808 | |
cristy | 826a547 | 2010-08-31 23:21:38 +0000 | [diff] [blame] | 5809 | ssize_t |
| 5810 | j, |
| 5811 | n, |
| 5812 | p, |
| 5813 | q; |
| 5814 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5815 | /* |
| 5816 | Allocate paths. |
| 5817 | */ |
| 5818 | number_vertices=primitive_info->coordinates; |
| 5819 | max_strokes=2*number_vertices+6*BezierQuantum+360; |
| 5820 | path_p=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, |
| 5821 | sizeof(*path_p)); |
| 5822 | path_q=(PointInfo *) AcquireQuantumMemory((size_t) max_strokes, |
| 5823 | sizeof(*path_q)); |
| 5824 | polygon_primitive=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 5825 | number_vertices+2UL,sizeof(*polygon_primitive)); |
| 5826 | if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL) || |
| 5827 | (polygon_primitive == (PrimitiveInfo *) NULL)) |
| 5828 | return((PrimitiveInfo *) NULL); |
| 5829 | (void) CopyMagickMemory(polygon_primitive,primitive_info,(size_t) |
| 5830 | number_vertices*sizeof(*polygon_primitive)); |
| 5831 | closed_path= |
| 5832 | (primitive_info[number_vertices-1].point.x == primitive_info[0].point.x) && |
| 5833 | (primitive_info[number_vertices-1].point.y == primitive_info[0].point.y) ? |
| 5834 | MagickTrue : MagickFalse; |
| 5835 | if ((draw_info->linejoin == RoundJoin) || |
| 5836 | ((draw_info->linejoin == MiterJoin) && (closed_path != MagickFalse))) |
| 5837 | { |
| 5838 | polygon_primitive[number_vertices]=primitive_info[1]; |
| 5839 | number_vertices++; |
| 5840 | } |
| 5841 | polygon_primitive[number_vertices].primitive=UndefinedPrimitive; |
| 5842 | /* |
| 5843 | Compute the slope for the first line segment, p. |
| 5844 | */ |
| 5845 | dx.p=0.0; |
| 5846 | dy.p=0.0; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5847 | for (n=1; n < (ssize_t) number_vertices; n++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5848 | { |
| 5849 | dx.p=polygon_primitive[n].point.x-polygon_primitive[0].point.x; |
| 5850 | dy.p=polygon_primitive[n].point.y-polygon_primitive[0].point.y; |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5851 | if ((fabs(dx.p) >= MagickEpsilon) || (fabs(dy.p) >= MagickEpsilon)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5852 | break; |
| 5853 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5854 | if (n == (ssize_t) number_vertices) |
| 5855 | n=(ssize_t) number_vertices-1L; |
cristy | 66fce5b | 2012-06-29 15:58:17 +0000 | [diff] [blame] | 5856 | slope.p=DrawEpsilonReciprocal(dx.p)*dy.p; |
| 5857 | inverse_slope.p=(-1.0*DrawEpsilonReciprocal(slope.p)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5858 | mid=ExpandAffine(&draw_info->affine)*draw_info->stroke_width/2.0; |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 5859 | miterlimit=(double) (draw_info->miterlimit*draw_info->miterlimit* |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5860 | mid*mid); |
| 5861 | if ((draw_info->linecap == SquareCap) && (closed_path == MagickFalse)) |
| 5862 | TraceSquareLinecap(polygon_primitive,number_vertices,mid); |
| 5863 | offset.x=sqrt((double) (mid*mid/(inverse_slope.p*inverse_slope.p+1.0))); |
| 5864 | offset.y=(double) (offset.x*inverse_slope.p); |
| 5865 | if ((dy.p*offset.x-dx.p*offset.y) > 0.0) |
| 5866 | { |
| 5867 | box_p[0].x=polygon_primitive[0].point.x-offset.x; |
| 5868 | box_p[0].y=polygon_primitive[0].point.y-offset.x*inverse_slope.p; |
| 5869 | box_p[1].x=polygon_primitive[n].point.x-offset.x; |
| 5870 | box_p[1].y=polygon_primitive[n].point.y-offset.x*inverse_slope.p; |
| 5871 | box_q[0].x=polygon_primitive[0].point.x+offset.x; |
| 5872 | box_q[0].y=polygon_primitive[0].point.y+offset.x*inverse_slope.p; |
| 5873 | box_q[1].x=polygon_primitive[n].point.x+offset.x; |
| 5874 | box_q[1].y=polygon_primitive[n].point.y+offset.x*inverse_slope.p; |
| 5875 | } |
| 5876 | else |
| 5877 | { |
| 5878 | box_p[0].x=polygon_primitive[0].point.x+offset.x; |
| 5879 | box_p[0].y=polygon_primitive[0].point.y+offset.y; |
| 5880 | box_p[1].x=polygon_primitive[n].point.x+offset.x; |
| 5881 | box_p[1].y=polygon_primitive[n].point.y+offset.y; |
| 5882 | box_q[0].x=polygon_primitive[0].point.x-offset.x; |
| 5883 | box_q[0].y=polygon_primitive[0].point.y-offset.y; |
| 5884 | box_q[1].x=polygon_primitive[n].point.x-offset.x; |
| 5885 | box_q[1].y=polygon_primitive[n].point.y-offset.y; |
| 5886 | } |
| 5887 | /* |
| 5888 | Create strokes for the line join attribute: bevel, miter, round. |
| 5889 | */ |
| 5890 | p=0; |
| 5891 | q=0; |
| 5892 | path_q[p++]=box_q[0]; |
| 5893 | path_p[q++]=box_p[0]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5894 | for (i=(ssize_t) n+1; i < (ssize_t) number_vertices; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5895 | { |
| 5896 | /* |
| 5897 | Compute the slope for this line segment, q. |
| 5898 | */ |
| 5899 | dx.q=polygon_primitive[i].point.x-polygon_primitive[n].point.x; |
| 5900 | dy.q=polygon_primitive[i].point.y-polygon_primitive[n].point.y; |
| 5901 | dot_product=dx.q*dx.q+dy.q*dy.q; |
| 5902 | if (dot_product < 0.25) |
| 5903 | continue; |
cristy | 66fce5b | 2012-06-29 15:58:17 +0000 | [diff] [blame] | 5904 | slope.q=DrawEpsilonReciprocal(dx.q)*dy.q; |
| 5905 | inverse_slope.q=(-1.0*DrawEpsilonReciprocal(slope.q)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5906 | offset.x=sqrt((double) (mid*mid/(inverse_slope.q*inverse_slope.q+1.0))); |
| 5907 | offset.y=(double) (offset.x*inverse_slope.q); |
| 5908 | dot_product=dy.q*offset.x-dx.q*offset.y; |
| 5909 | if (dot_product > 0.0) |
| 5910 | { |
| 5911 | box_p[2].x=polygon_primitive[n].point.x-offset.x; |
| 5912 | box_p[2].y=polygon_primitive[n].point.y-offset.y; |
| 5913 | box_p[3].x=polygon_primitive[i].point.x-offset.x; |
| 5914 | box_p[3].y=polygon_primitive[i].point.y-offset.y; |
| 5915 | box_q[2].x=polygon_primitive[n].point.x+offset.x; |
| 5916 | box_q[2].y=polygon_primitive[n].point.y+offset.y; |
| 5917 | box_q[3].x=polygon_primitive[i].point.x+offset.x; |
| 5918 | box_q[3].y=polygon_primitive[i].point.y+offset.y; |
| 5919 | } |
| 5920 | else |
| 5921 | { |
| 5922 | box_p[2].x=polygon_primitive[n].point.x+offset.x; |
| 5923 | box_p[2].y=polygon_primitive[n].point.y+offset.y; |
| 5924 | box_p[3].x=polygon_primitive[i].point.x+offset.x; |
| 5925 | box_p[3].y=polygon_primitive[i].point.y+offset.y; |
| 5926 | box_q[2].x=polygon_primitive[n].point.x-offset.x; |
| 5927 | box_q[2].y=polygon_primitive[n].point.y-offset.y; |
| 5928 | box_q[3].x=polygon_primitive[i].point.x-offset.x; |
| 5929 | box_q[3].y=polygon_primitive[i].point.y-offset.y; |
| 5930 | } |
cristy | 53aed70 | 2012-07-08 00:21:25 +0000 | [diff] [blame] | 5931 | if (fabs((double) (slope.p-slope.q)) < MagickEpsilon) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5932 | { |
| 5933 | box_p[4]=box_p[1]; |
| 5934 | box_q[4]=box_q[1]; |
| 5935 | } |
| 5936 | else |
| 5937 | { |
| 5938 | box_p[4].x=(double) ((slope.p*box_p[0].x-box_p[0].y-slope.q*box_p[3].x+ |
| 5939 | box_p[3].y)/(slope.p-slope.q)); |
| 5940 | box_p[4].y=(double) (slope.p*(box_p[4].x-box_p[0].x)+box_p[0].y); |
| 5941 | box_q[4].x=(double) ((slope.p*box_q[0].x-box_q[0].y-slope.q*box_q[3].x+ |
| 5942 | box_q[3].y)/(slope.p-slope.q)); |
| 5943 | box_q[4].y=(double) (slope.p*(box_q[4].x-box_q[0].x)+box_q[0].y); |
| 5944 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 5945 | if (q >= (ssize_t) (max_strokes-6*BezierQuantum-360)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 5946 | { |
| 5947 | max_strokes+=6*BezierQuantum+360; |
| 5948 | path_p=(PointInfo *) ResizeQuantumMemory(path_p,(size_t) max_strokes, |
| 5949 | sizeof(*path_p)); |
| 5950 | path_q=(PointInfo *) ResizeQuantumMemory(path_q,(size_t) max_strokes, |
| 5951 | sizeof(*path_q)); |
| 5952 | if ((path_p == (PointInfo *) NULL) || (path_q == (PointInfo *) NULL)) |
| 5953 | { |
| 5954 | polygon_primitive=(PrimitiveInfo *) |
| 5955 | RelinquishMagickMemory(polygon_primitive); |
| 5956 | return((PrimitiveInfo *) NULL); |
| 5957 | } |
| 5958 | } |
| 5959 | dot_product=dx.q*dy.p-dx.p*dy.q; |
| 5960 | if (dot_product <= 0.0) |
| 5961 | switch (draw_info->linejoin) |
| 5962 | { |
| 5963 | case BevelJoin: |
| 5964 | { |
| 5965 | path_q[q++]=box_q[1]; |
| 5966 | path_q[q++]=box_q[2]; |
| 5967 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 5968 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 5969 | if (dot_product <= miterlimit) |
| 5970 | path_p[p++]=box_p[4]; |
| 5971 | else |
| 5972 | { |
| 5973 | path_p[p++]=box_p[1]; |
| 5974 | path_p[p++]=box_p[2]; |
| 5975 | } |
| 5976 | break; |
| 5977 | } |
| 5978 | case MiterJoin: |
| 5979 | { |
| 5980 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 5981 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 5982 | if (dot_product <= miterlimit) |
| 5983 | { |
| 5984 | path_q[q++]=box_q[4]; |
| 5985 | path_p[p++]=box_p[4]; |
| 5986 | } |
| 5987 | else |
| 5988 | { |
| 5989 | path_q[q++]=box_q[1]; |
| 5990 | path_q[q++]=box_q[2]; |
| 5991 | path_p[p++]=box_p[1]; |
| 5992 | path_p[p++]=box_p[2]; |
| 5993 | } |
| 5994 | break; |
| 5995 | } |
| 5996 | case RoundJoin: |
| 5997 | { |
| 5998 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 5999 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6000 | if (dot_product <= miterlimit) |
| 6001 | path_p[p++]=box_p[4]; |
| 6002 | else |
| 6003 | { |
| 6004 | path_p[p++]=box_p[1]; |
| 6005 | path_p[p++]=box_p[2]; |
| 6006 | } |
| 6007 | center=polygon_primitive[n].point; |
| 6008 | theta.p=atan2(box_q[1].y-center.y,box_q[1].x-center.x); |
| 6009 | theta.q=atan2(box_q[2].y-center.y,box_q[2].x-center.x); |
| 6010 | if (theta.q < theta.p) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6011 | theta.q+=(double) (2.0*MagickPI); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6012 | arc_segments=(size_t) ceil((double) ((theta.q-theta.p)/ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6013 | (2.0*sqrt((double) (1.0/mid))))); |
| 6014 | path_q[q].x=box_q[1].x; |
| 6015 | path_q[q].y=box_q[1].y; |
| 6016 | q++; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6017 | for (j=1; j < (ssize_t) arc_segments; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6018 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6019 | delta_theta=(double) (j*(theta.q-theta.p)/arc_segments); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6020 | path_q[q].x=(double) (center.x+mid*cos(fmod((double) |
| 6021 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6022 | path_q[q].y=(double) (center.y+mid*sin(fmod((double) |
| 6023 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6024 | q++; |
| 6025 | } |
| 6026 | path_q[q++]=box_q[2]; |
| 6027 | break; |
| 6028 | } |
| 6029 | default: |
| 6030 | break; |
| 6031 | } |
| 6032 | else |
| 6033 | switch (draw_info->linejoin) |
| 6034 | { |
| 6035 | case BevelJoin: |
| 6036 | { |
| 6037 | path_p[p++]=box_p[1]; |
| 6038 | path_p[p++]=box_p[2]; |
| 6039 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6040 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6041 | if (dot_product <= miterlimit) |
| 6042 | path_q[q++]=box_q[4]; |
| 6043 | else |
| 6044 | { |
| 6045 | path_q[q++]=box_q[1]; |
| 6046 | path_q[q++]=box_q[2]; |
| 6047 | } |
| 6048 | break; |
| 6049 | } |
| 6050 | case MiterJoin: |
| 6051 | { |
| 6052 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6053 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6054 | if (dot_product <= miterlimit) |
| 6055 | { |
| 6056 | path_q[q++]=box_q[4]; |
| 6057 | path_p[p++]=box_p[4]; |
| 6058 | } |
| 6059 | else |
| 6060 | { |
| 6061 | path_q[q++]=box_q[1]; |
| 6062 | path_q[q++]=box_q[2]; |
| 6063 | path_p[p++]=box_p[1]; |
| 6064 | path_p[p++]=box_p[2]; |
| 6065 | } |
| 6066 | break; |
| 6067 | } |
| 6068 | case RoundJoin: |
| 6069 | { |
| 6070 | dot_product=(box_q[4].x-box_p[4].x)*(box_q[4].x-box_p[4].x)+ |
| 6071 | (box_q[4].y-box_p[4].y)*(box_q[4].y-box_p[4].y); |
| 6072 | if (dot_product <= miterlimit) |
| 6073 | path_q[q++]=box_q[4]; |
| 6074 | else |
| 6075 | { |
| 6076 | path_q[q++]=box_q[1]; |
| 6077 | path_q[q++]=box_q[2]; |
| 6078 | } |
| 6079 | center=polygon_primitive[n].point; |
| 6080 | theta.p=atan2(box_p[1].y-center.y,box_p[1].x-center.x); |
| 6081 | theta.q=atan2(box_p[2].y-center.y,box_p[2].x-center.x); |
| 6082 | if (theta.p < theta.q) |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6083 | theta.p+=(double) (2.0*MagickPI); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6084 | arc_segments=(size_t) ceil((double) ((theta.p-theta.q)/ |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6085 | (2.0*sqrt((double) (1.0/mid))))); |
| 6086 | path_p[p++]=box_p[1]; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6087 | for (j=1; j < (ssize_t) arc_segments; j++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6088 | { |
cristy | a19f1d7 | 2012-08-07 18:24:38 +0000 | [diff] [blame] | 6089 | delta_theta=(double) (j*(theta.q-theta.p)/arc_segments); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6090 | path_p[p].x=(double) (center.x+mid*cos(fmod((double) |
| 6091 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6092 | path_p[p].y=(double) (center.y+mid*sin(fmod((double) |
| 6093 | (theta.p+delta_theta),DegreesToRadians(360.0)))); |
| 6094 | p++; |
| 6095 | } |
| 6096 | path_p[p++]=box_p[2]; |
| 6097 | break; |
| 6098 | } |
| 6099 | default: |
| 6100 | break; |
| 6101 | } |
| 6102 | slope.p=slope.q; |
| 6103 | inverse_slope.p=inverse_slope.q; |
| 6104 | box_p[0]=box_p[2]; |
| 6105 | box_p[1]=box_p[3]; |
| 6106 | box_q[0]=box_q[2]; |
| 6107 | box_q[1]=box_q[3]; |
| 6108 | dx.p=dx.q; |
| 6109 | dy.p=dy.q; |
| 6110 | n=i; |
| 6111 | } |
| 6112 | path_p[p++]=box_p[1]; |
| 6113 | path_q[q++]=box_q[1]; |
| 6114 | /* |
| 6115 | Trace stroked polygon. |
| 6116 | */ |
| 6117 | stroke_polygon=(PrimitiveInfo *) AcquireQuantumMemory((size_t) |
| 6118 | (p+q+2UL*closed_path+2UL),sizeof(*stroke_polygon)); |
| 6119 | if (stroke_polygon != (PrimitiveInfo *) NULL) |
| 6120 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6121 | for (i=0; i < (ssize_t) p; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6122 | { |
| 6123 | stroke_polygon[i]=polygon_primitive[0]; |
| 6124 | stroke_polygon[i].point=path_p[i]; |
| 6125 | } |
| 6126 | if (closed_path != MagickFalse) |
| 6127 | { |
| 6128 | stroke_polygon[i]=polygon_primitive[0]; |
| 6129 | stroke_polygon[i].point=stroke_polygon[0].point; |
| 6130 | i++; |
| 6131 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6132 | for ( ; i < (ssize_t) (p+q+closed_path); i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6133 | { |
| 6134 | stroke_polygon[i]=polygon_primitive[0]; |
| 6135 | stroke_polygon[i].point=path_q[p+q+closed_path-(i+1)]; |
| 6136 | } |
| 6137 | if (closed_path != MagickFalse) |
| 6138 | { |
| 6139 | stroke_polygon[i]=polygon_primitive[0]; |
| 6140 | stroke_polygon[i].point=stroke_polygon[p+closed_path].point; |
| 6141 | i++; |
| 6142 | } |
| 6143 | stroke_polygon[i]=polygon_primitive[0]; |
| 6144 | stroke_polygon[i].point=stroke_polygon[0].point; |
| 6145 | i++; |
| 6146 | stroke_polygon[i].primitive=UndefinedPrimitive; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 6147 | stroke_polygon[0].coordinates=(size_t) (p+q+2*closed_path+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 6148 | } |
| 6149 | path_p=(PointInfo *) RelinquishMagickMemory(path_p); |
| 6150 | path_q=(PointInfo *) RelinquishMagickMemory(path_q); |
| 6151 | polygon_primitive=(PrimitiveInfo *) RelinquishMagickMemory(polygon_primitive); |
| 6152 | return(stroke_polygon); |
| 6153 | } |