1 /* 2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 3 % % 4 % % 5 % PPPP EEEEE RRRR L % 6 % P P E R R L % 7 % PPPP EEE RRRR L % 8 % P E R R L % 9 % P EEEEE R R LLLLL % 10 % % 11 % M M AAA GGGG IIIII CCCC K K % 12 % MM MM A A G I C K K % 13 % M M M AAAAA G GGG I C KKK % 14 % M M A A G G I C K K % 15 % M M A A GGGG IIIII CCCC K K % 16 % % 17 % % 18 % Object-oriented Perl interface to ImageMagick % 19 % % 20 % Software Design % 21 % Kyle Shorter % 22 % Cristy % 23 % February 1997 % 24 % % 25 % % 26 % Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization % 27 % dedicated to making software imaging solutions freely available. % 28 % % 29 % You may not use this file except in compliance with the License. You may % 30 % obtain a copy of the License at % 31 % % 32 % http://www.imagemagick.org/script/license.php % 33 % % 34 % Unless required by applicable law or agreed to in writing, software % 35 % distributed under the License is distributed on an "AS IS" BASIS, % 36 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % 37 % See the License for the specific language governing permissions and % 38 % limitations under the License. % 39 % % 40 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 41 % 42 % PerlMagick is an objected-oriented Perl interface to ImageMagick. Use 43 % the module to read, manipulate, or write an image or image sequence from 44 % within a Perl script. This makes PerlMagick suitable for Web CGI scripts. 45 % 46 */ 47 48 /* 50 Include declarations. 51 */ 52 #if defined(__cplusplus) || defined(c_plusplus) 53 extern "C" { 54 #endif 55 56 #define PERL_NO_GET_CONTEXT 57 #include "EXTERN.h" 58 #include "perl.h" 59 #include "XSUB.h" 60 #include <math.h> 61 #include <MagickCore/MagickCore.h> 62 #undef tainted 63 64 #if defined(__cplusplus) || defined(c_plusplus) 65 } 66 #endif 67 68 /* 70 Define declarations. 71 */ 72 #ifndef aTHX_ 73 #define aTHX_ 74 #define pTHX_ 75 #define dTHX 76 #endif 77 #define DegreesToRadians(x) (MagickPI*(x)/180.0) 78 #define EndOf(array) (&array[NumberOf(array)]) 79 #define MagickPI 3.14159265358979323846264338327950288419716939937510 80 #define MaxArguments 33 81 #ifndef na 82 #define na PL_na 83 #endif 84 #define NumberOf(array) (sizeof(array)/sizeof(*array)) 85 #define PackageName "Image::Magick::@MAGICK_ABI_SUFFIX@" 86 #if PERL_VERSION <= 6 87 #define PerlIO FILE 88 #define PerlIO_importFILE(f, fl) (f) 89 #define PerlIO_findFILE(f) NULL 90 #endif 91 #ifndef sv_undef 92 #define sv_undef PL_sv_undef 93 #endif 94 95 #define AddImageToRegistry(sv,image) \ 96 { \ 97 if (magick_registry != (SplayTreeInfo *) NULL) \ 98 { \ 99 (void) AddValueToSplayTree(magick_registry,image,image); \ 100 (sv)=newSViv(PTR2IV(image)); \ 101 } \ 102 } 103 104 #define DeleteImageFromRegistry(reference,image) \ 105 { \ 106 if (magick_registry != (SplayTreeInfo *) NULL) \ 107 { \ 108 if (GetImageReferenceCount(image) == 1) \ 109 (void) DeleteNodeByValueFromSplayTree(magick_registry,image); \ 110 image=DestroyImage(image); \ 111 sv_setiv(reference,0); \ 112 } \ 113 } 114 115 #define InheritPerlException(exception,perl_exception) \ 116 { \ 117 char \ 118 message[MagickPathExtent]; \ 119 \ 120 if ((exception)->severity != UndefinedException) \ 121 { \ 122 (void) FormatLocaleString(message,MagickPathExtent,"Exception %d: %s%s%s%s",\ 123 (exception)->severity, (exception)->reason ? \ 124 GetLocaleExceptionMessage((exception)->severity,(exception)->reason) : \ 125 "Unknown", (exception)->description ? " (" : "", \ 126 (exception)->description ? GetLocaleExceptionMessage( \ 127 (exception)->severity,(exception)->description) : "", \ 128 (exception)->description ? ")" : ""); \ 129 if ((perl_exception) != (SV *) NULL) \ 130 { \ 131 if (SvCUR(perl_exception)) \ 132 sv_catpv(perl_exception,"\n"); \ 133 sv_catpv(perl_exception,message); \ 134 } \ 135 } \ 136 } 137 138 #define ThrowPerlException(exception,severity,tag,reason) \ 139 (void) ThrowMagickException(exception,GetMagickModule(),severity, \ 140 tag,"`%s'",reason); \ 141 142 /* 144 Typedef and structure declarations. 145 */ 146 typedef enum 147 { 148 ArrayReference = (~0), 149 RealReference = (~0)-1, 150 FileReference = (~0)-2, 151 ImageReference = (~0)-3, 152 IntegerReference = (~0)-4, 153 StringReference = (~0)-5 154 } MagickReference; 155 156 typedef struct _Arguments 157 { 158 const char 159 *method; 160 161 ssize_t 162 type; 163 } Arguments; 164 165 struct ArgumentList 166 { 167 ssize_t 168 integer_reference; 169 170 double 171 real_reference; 172 173 const char 174 *string_reference; 175 176 Image 177 *image_reference; 178 179 SV 180 *array_reference; 181 182 FILE 183 *file_reference; 184 185 size_t 186 length; 187 }; 188 189 struct PackageInfo 190 { 191 ImageInfo 192 *image_info; 193 }; 194 195 typedef void 196 *Image__Magick__@MAGICK_ABI_SUFFIX@; /* data type for the Image::Magick::@MAGICK_ABI_NAME@ package */ 197 198 /* 200 Static declarations. 201 */ 202 static struct 203 Methods 204 { 205 const char 206 *name; 207 208 Arguments 209 arguments[MaxArguments]; 210 } Methods[] = 211 { 212 { "Comment", { {"comment", StringReference} } }, 213 { "Label", { {"label", StringReference} } }, 214 { "AddNoise", { {"noise", MagickNoiseOptions}, {"attenuate", RealReference}, 215 {"channel", MagickChannelOptions} } }, 216 { "Colorize", { {"fill", StringReference}, {"blend", StringReference} } }, 217 { "Border", { {"geometry", StringReference}, {"width", IntegerReference}, 218 {"height", IntegerReference}, {"fill", StringReference}, 219 {"bordercolor", StringReference}, {"color", StringReference}, 220 {"compose", MagickComposeOptions} } }, 221 { "Blur", { {"geometry", StringReference}, {"radius", RealReference}, 222 {"sigma", RealReference}, {"channel", MagickChannelOptions} } }, 223 { "Chop", { {"geometry", StringReference}, {"width", IntegerReference}, 224 {"height", IntegerReference}, {"x", IntegerReference}, 225 {"y", IntegerReference}, {"gravity", MagickGravityOptions} } }, 226 { "Crop", { {"geometry", StringReference}, {"width", IntegerReference}, 227 {"height", IntegerReference}, {"x", IntegerReference}, 228 {"y", IntegerReference}, {"fuzz", StringReference}, 229 {"gravity", MagickGravityOptions} } }, 230 { "Despeckle", }, 231 { "Edge", { {"radius", RealReference} } }, 232 { "Emboss", { {"geometry", StringReference}, {"radius", RealReference}, 233 {"sigma", RealReference} } }, 234 { "Enhance", }, 235 { "Flip", }, 236 { "Flop", }, 237 { "Frame", { {"geometry", StringReference}, {"width", IntegerReference}, 238 {"height", IntegerReference}, {"inner", IntegerReference}, 239 {"outer", IntegerReference}, {"fill", StringReference}, 240 {"color", StringReference}, {"compose", MagickComposeOptions} } }, 241 { "Implode", { {"amount", RealReference}, 242 {"interpolate", MagickInterpolateOptions} } }, 243 { "Magnify", }, 244 { "MedianFilter", { {"geometry", StringReference}, 245 {"width", IntegerReference}, {"height", IntegerReference}, 246 {"channel", MagickChannelOptions} } }, 247 { "Minify", }, 248 { "OilPaint", { {"radius", RealReference}, {"sigma", RealReference} } }, 249 { "ReduceNoise", { {"geometry", StringReference}, 250 {"width", IntegerReference},{"height", IntegerReference}, 251 {"channel", MagickChannelOptions} } }, 252 { "Roll", { {"geometry", StringReference}, {"x", IntegerReference}, 253 {"y", IntegerReference} } }, 254 { "Rotate", { {"degrees", RealReference}, 255 {"background", StringReference} } }, 256 { "Sample", { {"geometry", StringReference}, {"width", IntegerReference}, 257 {"height", IntegerReference} } }, 258 { "Scale", { {"geometry", StringReference}, {"width", IntegerReference}, 259 {"height", IntegerReference} } }, 260 { "Shade", { {"geometry", StringReference}, {"azimuth", RealReference}, 261 {"elevation", RealReference}, {"gray", MagickBooleanOptions} } }, 262 { "Sharpen", { {"geometry", StringReference}, {"radius", RealReference}, 263 {"sigma", RealReference}, {"channel", MagickChannelOptions} } }, 264 { "Shear", { {"geometry", StringReference}, {"x", RealReference}, 265 {"y", RealReference}, { "fill", StringReference}, 266 {"color", StringReference} } }, 267 { "Spread", { {"radius", RealReference}, 268 {"interpolate", MagickInterpolateOptions} } }, 269 { "Swirl", { {"degrees", RealReference}, 270 {"interpolate", MagickInterpolateOptions} } }, 271 { "Resize", { {"geometry", StringReference}, {"width", IntegerReference}, 272 {"height", IntegerReference}, {"filter", MagickFilterOptions}, 273 {"support", StringReference } } }, 274 { "Zoom", { {"geometry", StringReference}, {"width", IntegerReference}, 275 {"height", IntegerReference}, {"filter", MagickFilterOptions}, 276 {"support", RealReference } } }, 277 { "Annotate", { {"text", StringReference}, {"font", StringReference}, 278 {"pointsize", RealReference}, {"density", StringReference}, 279 {"undercolor", StringReference}, {"stroke", StringReference}, 280 {"fill", StringReference}, {"geometry", StringReference}, 281 {"sans", StringReference}, {"x", RealReference}, 282 {"y", RealReference}, {"gravity", MagickGravityOptions}, 283 {"translate", StringReference}, {"scale", StringReference}, 284 {"rotate", RealReference}, {"skewX", RealReference}, 285 {"skewY", RealReference}, {"strokewidth", RealReference}, 286 {"antialias", MagickBooleanOptions}, {"family", StringReference}, 287 {"style", MagickStyleOptions}, {"stretch", MagickStretchOptions}, 288 {"weight", IntegerReference}, {"align", MagickAlignOptions}, 289 {"encoding", StringReference}, {"affine", ArrayReference}, 290 {"fill-pattern", ImageReference}, {"stroke-pattern", ImageReference}, 291 {"tile", ImageReference}, {"kerning", RealReference}, 292 {"interline-spacing", RealReference}, 293 {"interword-spacing", RealReference}, 294 {"direction", MagickDirectionOptions} } }, 295 { "ColorFloodfill", { {"geometry", StringReference}, 296 {"x", IntegerReference}, {"y", IntegerReference}, 297 {"fill", StringReference}, {"bordercolor", StringReference}, 298 {"fuzz", StringReference}, {"invert", MagickBooleanOptions} } }, 299 { "Composite", { {"image", ImageReference}, 300 {"compose", MagickComposeOptions}, {"geometry", StringReference}, 301 {"x", IntegerReference}, {"y", IntegerReference}, 302 {"gravity", MagickGravityOptions}, {"opacity", StringReference}, 303 {"tile", MagickBooleanOptions}, {"rotate", RealReference}, 304 {"color", StringReference}, {"mask", ImageReference}, 305 {"channel", MagickChannelOptions}, 306 {"interpolate", MagickInterpolateOptions}, {"args", StringReference}, 307 {"blend", StringReference}, {"crop-to-self", MagickBooleanOptions} } }, 308 { "Contrast", { {"sharpen", MagickBooleanOptions} } }, 309 { "CycleColormap", { {"display", IntegerReference} } }, 310 { "Draw", { {"primitive", MagickPrimitiveOptions}, 311 {"points", StringReference}, {"method", MagickMethodOptions}, 312 {"stroke", StringReference}, {"fill", StringReference}, 313 {"strokewidth", RealReference}, {"font", StringReference}, 314 {"bordercolor", StringReference}, {"x", RealReference}, 315 {"y", RealReference}, {"translate", StringReference}, 316 {"scale", StringReference}, {"rotate", RealReference}, 317 {"skewX", RealReference}, {"skewY", RealReference}, 318 {"tile", ImageReference}, {"pointsize", RealReference}, 319 {"antialias", MagickBooleanOptions}, {"density", StringReference}, 320 {"linewidth", RealReference}, {"affine", ArrayReference}, 321 {"stroke-dashoffset", RealReference}, 322 {"stroke-dasharray", ArrayReference}, 323 {"interpolate", MagickInterpolateOptions}, 324 {"origin", StringReference}, {"text", StringReference}, 325 {"fill-pattern", ImageReference}, {"stroke-pattern", ImageReference}, 326 {"vector-graphics", StringReference}, {"kerning", RealReference}, 327 {"interline-spacing", RealReference}, 328 {"interword-spacing", RealReference}, 329 {"direction", MagickDirectionOptions} } }, 330 { "Equalize", { {"channel", MagickChannelOptions} } }, 331 { "Gamma", { {"gamma", StringReference}, {"channel", MagickChannelOptions}, 332 {"red", RealReference}, {"green", RealReference}, 333 {"blue", RealReference} } }, 334 { "Map", { {"image", ImageReference}, 335 {"dither-method", MagickDitherOptions} } }, 336 { "MatteFloodfill", { {"geometry", StringReference}, 337 {"x", IntegerReference}, {"y", IntegerReference}, 338 {"opacity", StringReference}, {"bordercolor", StringReference}, 339 {"fuzz", StringReference}, {"invert", MagickBooleanOptions} } }, 340 { "Modulate", { {"factor", StringReference}, {"hue", RealReference}, 341 {"saturation", RealReference}, {"whiteness", RealReference}, 342 {"brightness", RealReference}, {"lightness", RealReference}, 343 {"blackness", RealReference} } }, 344 { "Negate", { {"gray", MagickBooleanOptions}, 345 {"channel", MagickChannelOptions} } }, 346 { "Normalize", { {"channel", MagickChannelOptions} } }, 347 { "NumberColors", }, 348 { "Opaque", { {"color", StringReference}, {"fill", StringReference}, 349 {"fuzz", StringReference}, {"channel", MagickChannelOptions}, 350 {"invert", MagickBooleanOptions} } }, 351 { "Quantize", { {"colors", IntegerReference}, 352 {"treedepth", IntegerReference}, {"colorspace", MagickColorspaceOptions}, 353 {"dither", MagickDitherOptions}, {"measure", MagickBooleanOptions}, 354 {"global", MagickBooleanOptions}, {"transparent-color", StringReference}, 355 {"dither-method", MagickDitherOptions} } }, 356 { "Raise", { {"geometry", StringReference}, {"width", IntegerReference}, 357 {"height", IntegerReference}, {"raise", MagickBooleanOptions} } }, 358 { "Segment", { {"geometry", StringReference}, 359 {"cluster-threshold", RealReference}, 360 {"smoothing-threshold", RealReference}, 361 {"colorspace", MagickColorspaceOptions}, 362 {"verbose", MagickBooleanOptions} } }, 363 { "Signature", }, 364 { "Solarize", { {"geometry", StringReference}, 365 {"threshold", StringReference} } }, 366 { "Sync", }, 367 { "Texture", { {"texture", ImageReference} } }, 368 { "Evaluate", { {"value", RealReference}, 369 {"operator", MagickEvaluateOptions}, 370 {"channel", MagickChannelOptions} } }, 371 { "Transparent", { {"color", StringReference}, {"opacity", StringReference}, 372 {"fuzz", StringReference}, {"invert", MagickBooleanOptions} } }, 373 { "Threshold", { {"threshold", StringReference}, 374 {"channel", MagickChannelOptions} } }, 375 { "Charcoal", { {"geometry", StringReference}, {"radius", RealReference}, 376 {"sigma", RealReference} } }, 377 { "Trim", { {"fuzz", StringReference} } }, 378 { "Wave", { {"geometry", StringReference}, {"amplitude", RealReference}, 379 {"wavelength", RealReference}, 380 {"interpolate", MagickInterpolateOptions} } }, 381 { "Separate", { {"channel", MagickChannelOptions} } }, 382 { "Condense", }, 383 { "Stereo", { {"image", ImageReference}, {"x", IntegerReference}, 384 {"y", IntegerReference} } }, 385 { "Stegano", { {"image", ImageReference}, {"offset", IntegerReference} } }, 386 { "Deconstruct", }, 387 { "GaussianBlur", { {"geometry", StringReference}, 388 {"radius", RealReference}, {"sigma", RealReference}, 389 {"channel", MagickChannelOptions} } }, 390 { "Convolve", { {"coefficients", ArrayReference}, 391 {"channel", MagickChannelOptions}, {"bias", StringReference}, 392 {"kernel", StringReference} } }, 393 { "Profile", { {"name", StringReference}, {"profile", StringReference}, 394 { "rendering-intent", MagickIntentOptions}, 395 { "black-point-compensation", MagickBooleanOptions} } }, 396 { "UnsharpMask", { {"geometry", StringReference}, 397 {"radius", RealReference}, {"sigma", RealReference}, 398 {"gain", RealReference}, {"threshold", RealReference}, 399 {"channel", MagickChannelOptions} } }, 400 { "MotionBlur", { {"geometry", StringReference}, 401 {"radius", RealReference}, {"sigma", RealReference}, 402 {"angle", RealReference}, {"channel", MagickChannelOptions} } }, 403 { "OrderedDither", { {"threshold", StringReference}, 404 {"channel", MagickChannelOptions} } }, 405 { "Shave", { {"geometry", StringReference}, {"width", IntegerReference}, 406 {"height", IntegerReference} } }, 407 { "Level", { {"levels", StringReference}, {"black-point", RealReference}, 408 {"white-point", RealReference}, {"gamma", RealReference}, 409 {"channel", MagickChannelOptions}, {"level", StringReference} } }, 410 { "Clip", { {"id", StringReference}, {"inside", MagickBooleanOptions} } }, 411 { "AffineTransform", { {"affine", ArrayReference}, 412 {"translate", StringReference}, {"scale", StringReference}, 413 {"rotate", RealReference}, {"skewX", RealReference}, 414 {"skewY", RealReference}, {"interpolate", MagickInterpolateOptions}, 415 {"background", StringReference} } }, 416 { "Difference", { {"image", ImageReference}, {"fuzz", StringReference} } }, 417 { "AdaptiveThreshold", { {"geometry", StringReference}, 418 {"width", IntegerReference}, {"height", IntegerReference} } }, 419 { "Resample", { {"density", StringReference}, {"x", RealReference}, 420 {"y", RealReference}, {"filter", MagickFilterOptions}, 421 {"support", RealReference } } }, 422 { "Describe", { {"file", FileReference} } }, 423 { "BlackThreshold", { {"threshold", StringReference}, 424 {"channel", MagickChannelOptions} } }, 425 { "WhiteThreshold", { {"threshold", StringReference}, 426 {"channel", MagickChannelOptions} } }, 427 { "RotationalBlur", { {"geometry", StringReference}, 428 {"angle", RealReference}, {"channel", MagickChannelOptions} } }, 429 { "Thumbnail", { {"geometry", StringReference}, {"width", IntegerReference}, 430 {"height", IntegerReference} } }, 431 { "Strip", }, 432 { "Tint", { {"fill", StringReference}, {"blend", StringReference} } }, 433 { "Channel", { {"channel", MagickChannelOptions} } }, 434 { "Splice", { {"geometry", StringReference}, {"width", IntegerReference}, 435 {"height", IntegerReference}, {"x", IntegerReference}, 436 {"y", IntegerReference}, {"fuzz", StringReference}, 437 {"background", StringReference}, {"gravity", MagickGravityOptions} } }, 438 { "Posterize", { {"levels", IntegerReference}, 439 {"dither", MagickBooleanOptions} } }, 440 { "Shadow", { {"geometry", StringReference}, {"alpha", RealReference}, 441 {"sigma", RealReference}, {"x", IntegerReference}, 442 {"y", IntegerReference} } }, 443 { "Identify", { {"file", FileReference}, {"features", StringReference}, 444 {"unique", MagickBooleanOptions} } }, 445 { "SepiaTone", { {"threshold", RealReference} } }, 446 { "SigmoidalContrast", { {"geometry", StringReference}, 447 {"contrast", RealReference}, {"mid-point", RealReference}, 448 {"channel", MagickChannelOptions}, {"sharpen", MagickBooleanOptions} } }, 449 { "Extent", { {"geometry", StringReference}, {"width", IntegerReference}, 450 {"height", IntegerReference}, {"x", IntegerReference}, 451 {"y", IntegerReference}, {"fuzz", StringReference}, 452 {"background", StringReference}, {"gravity", MagickGravityOptions} } }, 453 { "Vignette", { {"geometry", StringReference}, {"radius", RealReference}, 454 {"sigma", RealReference}, {"x", IntegerReference}, 455 {"y", IntegerReference}, {"background", StringReference} } }, 456 { "ContrastStretch", { {"levels", StringReference}, 457 {"black-point", RealReference},{"white-point", RealReference}, 458 {"channel", MagickChannelOptions} } }, 459 { "Sans0", }, 460 { "Sans1", }, 461 { "AdaptiveSharpen", { {"geometry", StringReference}, 462 {"radius", RealReference}, {"sigma", RealReference}, 463 {"bias", RealReference}, {"channel", MagickChannelOptions} } }, 464 { "Transpose", }, 465 { "Transverse", }, 466 { "AutoOrient", }, 467 { "AdaptiveBlur", { {"geometry", StringReference}, 468 {"radius", RealReference}, {"sigma", RealReference}, 469 {"channel", MagickChannelOptions} } }, 470 { "Sketch", { {"geometry", StringReference}, 471 {"radius", RealReference}, {"sigma", RealReference}, 472 {"angle", RealReference} } }, 473 { "UniqueColors", }, 474 { "AdaptiveResize", { {"geometry", StringReference}, 475 {"width", IntegerReference}, {"height", IntegerReference}, 476 {"filter", MagickFilterOptions}, {"support", StringReference }, 477 {"blur", RealReference } } }, 478 { "ClipMask", { {"mask", ImageReference} } }, 479 { "LinearStretch", { {"levels", StringReference}, 480 {"black-point", RealReference},{"white-point", RealReference} } }, 481 { "ColorMatrix", { {"matrix", ArrayReference} } }, 482 { "Mask", { {"mask", ImageReference} } }, 483 { "Polaroid", { {"caption", StringReference}, {"angle", RealReference}, 484 {"font", StringReference}, {"stroke", StringReference}, 485 {"fill", StringReference}, {"strokewidth", RealReference}, 486 {"pointsize", RealReference}, {"gravity", MagickGravityOptions}, 487 {"background", StringReference}, 488 {"interpolate", MagickInterpolateOptions} } }, 489 { "FloodfillPaint", { {"geometry", StringReference}, 490 {"x", IntegerReference}, {"y", IntegerReference}, 491 {"fill", StringReference}, {"bordercolor", StringReference}, 492 {"fuzz", StringReference}, {"channel", MagickChannelOptions}, 493 {"invert", MagickBooleanOptions} } }, 494 { "Distort", { {"points", ArrayReference}, {"method", MagickDistortOptions}, 495 {"virtual-pixel", MagickVirtualPixelOptions}, 496 {"best-fit", MagickBooleanOptions} } }, 497 { "Clut", { {"image", ImageReference}, 498 {"interpolate", MagickInterpolateOptions}, 499 {"channel", MagickChannelOptions} } }, 500 { "LiquidRescale", { {"geometry", StringReference}, 501 {"width", IntegerReference}, {"height", IntegerReference}, 502 {"delta-x", RealReference}, {"rigidity", RealReference } } }, 503 { "Encipher", { {"passphrase", StringReference} } }, 504 { "Decipher", { {"passphrase", StringReference} } }, 505 { "Deskew", { {"geometry", StringReference}, 506 {"threshold", StringReference} } }, 507 { "Remap", { {"image", ImageReference}, 508 {"dither-method", MagickDitherOptions} } }, 509 { "SparseColor", { {"points", ArrayReference}, 510 {"method", MagickSparseColorOptions}, 511 {"virtual-pixel", MagickVirtualPixelOptions}, 512 {"channel", MagickChannelOptions} } }, 513 { "Function", { {"parameters", ArrayReference}, 514 {"function", MagickFunctionOptions}, 515 {"virtual-pixel", MagickVirtualPixelOptions} } }, 516 { "SelectiveBlur", { {"geometry", StringReference}, 517 {"radius", RealReference}, {"sigma", RealReference}, 518 {"threshold", RealReference}, {"channel", MagickChannelOptions} } }, 519 { "HaldClut", { {"image", ImageReference}, 520 {"channel", MagickChannelOptions} } }, 521 { "BlueShift", { {"factor", StringReference} } }, 522 { "ForwardFourierTransform", { {"magnitude", MagickBooleanOptions} } }, 523 { "InverseFourierTransform", { {"magnitude", MagickBooleanOptions} } }, 524 { "ColorDecisionList", { 525 {"color-correction-collection", StringReference} } }, 526 { "AutoGamma", { {"channel", MagickChannelOptions} } }, 527 { "AutoLevel", { {"channel", MagickChannelOptions} } }, 528 { "LevelColors", { {"invert", MagickBooleanOptions}, 529 {"black-point", StringReference}, {"white-point", StringReference}, 530 {"channel", MagickChannelOptions}, {"invert", MagickBooleanOptions} } }, 531 { "Clamp", { {"channel", MagickChannelOptions} } }, 532 { "BrightnessContrast", { {"levels", StringReference}, 533 {"brightness", RealReference},{"contrast", RealReference}, 534 {"channel", MagickChannelOptions} } }, 535 { "Morphology", { {"kernel", StringReference}, 536 {"channel", MagickChannelOptions}, {"method", MagickMorphologyOptions}, 537 {"iterations", IntegerReference} } }, 538 { "Mode", { {"geometry", StringReference}, 539 {"width", IntegerReference},{"height", IntegerReference}, 540 {"channel", MagickChannelOptions} } }, 541 { "Statistic", { {"geometry", StringReference}, 542 {"width", IntegerReference},{"height", IntegerReference}, 543 {"channel", MagickChannelOptions}, {"type", MagickStatisticOptions} } }, 544 { "Perceptible", { {"epsilon", RealReference}, 545 {"channel", MagickChannelOptions} } }, 546 { "Poly", { {"terms", ArrayReference}, 547 {"channel", MagickChannelOptions} } }, 548 { "Grayscale", { {"method", MagickNoiseOptions} } }, 549 { "CannyEdge", { {"geometry", StringReference}, 550 {"radius", RealReference}, {"sigma", RealReference}, 551 {"lower-percent", RealReference}, {"upper-percent", RealReference} } }, 552 { "HoughLine", { {"geometry", StringReference}, 553 {"width", IntegerReference}, {"height", IntegerReference}, 554 {"threshold", IntegerReference} } }, 555 { "MeanShift", { {"geometry", StringReference}, 556 {"width", IntegerReference}, {"height", IntegerReference}, 557 {"distance", RealReference} } }, 558 { "Kuwahara", { {"geometry", StringReference}, {"radius", RealReference}, 559 {"sigma", RealReference}, {"channel", MagickChannelOptions} } }, 560 { "ConnectedComponents", { {"connectivity", IntegerReference} } }, 561 { "CopyPixels", { {"image", ImageReference}, {"geometry", StringReference}, 562 {"width", IntegerReference}, {"height", IntegerReference}, 563 {"x", IntegerReference}, {"y", IntegerReference}, 564 {"gravity", MagickGravityOptions}, {"offset", StringReference}, 565 {"dx", IntegerReference}, {"dy", IntegerReference} } }, 566 { "Color", { {"color", StringReference} } }, 567 { "WaveletDenoise", { {"geometry", StringReference}, 568 {"threshold", RealReference}, {"softness", RealReference}, 569 {"channel", MagickChannelOptions} } }, 570 }; 571 572 static SplayTreeInfo 573 *magick_registry = (SplayTreeInfo *) NULL; 574 575 /* 577 Forward declarations. 578 */ 579 static Image 580 *SetupList(pTHX_ SV *,struct PackageInfo **,SV ***,ExceptionInfo *); 581 582 static ssize_t 583 strEQcase(const char *,const char *); 584 585 /* 587 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 588 % % 589 % % 590 % % 591 % C l o n e P a c k a g e I n f o % 592 % % 593 % % 594 % % 595 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 596 % 597 % ClonePackageInfo makes a duplicate of the given info, or if info is NULL, 598 % a new one. 599 % 600 % The format of the ClonePackageInfo routine is: 601 % 602 % struct PackageInfo *ClonePackageInfo(struct PackageInfo *info, 603 % exception) 604 % 605 % A description of each parameter follows: 606 % 607 % o info: a structure of type info. 608 % 609 % o exception: Return any errors or warnings in this structure. 610 % 611 */ 612 static struct PackageInfo *ClonePackageInfo(struct PackageInfo *info, 613 ExceptionInfo *exception) 614 { 615 struct PackageInfo 616 *clone_info; 617 618 clone_info=(struct PackageInfo *) AcquireQuantumMemory(1,sizeof(*clone_info)); 619 if (clone_info == (struct PackageInfo *) NULL) 620 { 621 ThrowPerlException(exception,ResourceLimitError, 622 "UnableToClonePackageInfo",PackageName); 623 return((struct PackageInfo *) NULL); 624 } 625 if (info == (struct PackageInfo *) NULL) 626 { 627 clone_info->image_info=CloneImageInfo((ImageInfo *) NULL); 628 return(clone_info); 629 } 630 *clone_info=(*info); 631 clone_info->image_info=CloneImageInfo(info->image_info); 632 return(clone_info); 633 } 634 635 /* 637 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 638 % % 639 % % 640 % % 641 % c o n s t a n t % 642 % % 643 % % 644 % % 645 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 646 % 647 % constant() returns a double value for the specified name. 648 % 649 % The format of the constant routine is: 650 % 651 % double constant(char *name,ssize_t sans) 652 % 653 % A description of each parameter follows: 654 % 655 % o value: Method constant returns a double value for the specified name. 656 % 657 % o name: The name of the constant. 658 % 659 % o sans: This integer value is not used. 660 % 661 */ 662 static double constant(char *name,ssize_t sans) 663 { 664 (void) sans; 665 errno=0; 666 switch (*name) 667 { 668 case 'B': 669 { 670 if (strEQ(name,"BlobError")) 671 return(BlobError); 672 if (strEQ(name,"BlobWarning")) 673 return(BlobWarning); 674 break; 675 } 676 case 'C': 677 { 678 if (strEQ(name,"CacheError")) 679 return(CacheError); 680 if (strEQ(name,"CacheWarning")) 681 return(CacheWarning); 682 if (strEQ(name,"CoderError")) 683 return(CoderError); 684 if (strEQ(name,"CoderWarning")) 685 return(CoderWarning); 686 if (strEQ(name,"ConfigureError")) 687 return(ConfigureError); 688 if (strEQ(name,"ConfigureWarning")) 689 return(ConfigureWarning); 690 if (strEQ(name,"CorruptImageError")) 691 return(CorruptImageError); 692 if (strEQ(name,"CorruptImageWarning")) 693 return(CorruptImageWarning); 694 break; 695 } 696 case 'D': 697 { 698 if (strEQ(name,"DelegateError")) 699 return(DelegateError); 700 if (strEQ(name,"DelegateWarning")) 701 return(DelegateWarning); 702 if (strEQ(name,"DrawError")) 703 return(DrawError); 704 if (strEQ(name,"DrawWarning")) 705 return(DrawWarning); 706 break; 707 } 708 case 'E': 709 { 710 if (strEQ(name,"ErrorException")) 711 return(ErrorException); 712 if (strEQ(name,"ExceptionError")) 713 return(CoderError); 714 if (strEQ(name,"ExceptionWarning")) 715 return(CoderWarning); 716 break; 717 } 718 case 'F': 719 { 720 if (strEQ(name,"FatalErrorException")) 721 return(FatalErrorException); 722 if (strEQ(name,"FileOpenError")) 723 return(FileOpenError); 724 if (strEQ(name,"FileOpenWarning")) 725 return(FileOpenWarning); 726 break; 727 } 728 case 'I': 729 { 730 if (strEQ(name,"ImageError")) 731 return(ImageError); 732 if (strEQ(name,"ImageWarning")) 733 return(ImageWarning); 734 break; 735 } 736 case 'M': 737 { 738 if (strEQ(name,"MaxRGB")) 739 return(QuantumRange); 740 if (strEQ(name,"MissingDelegateError")) 741 return(MissingDelegateError); 742 if (strEQ(name,"MissingDelegateWarning")) 743 return(MissingDelegateWarning); 744 if (strEQ(name,"ModuleError")) 745 return(ModuleError); 746 if (strEQ(name,"ModuleWarning")) 747 return(ModuleWarning); 748 break; 749 } 750 case 'O': 751 { 752 if (strEQ(name,"Opaque")) 753 return(OpaqueAlpha); 754 if (strEQ(name,"OptionError")) 755 return(OptionError); 756 if (strEQ(name,"OptionWarning")) 757 return(OptionWarning); 758 break; 759 } 760 case 'Q': 761 { 762 if (strEQ(name,"MAGICKCORE_QUANTUM_DEPTH")) 763 return(MAGICKCORE_QUANTUM_DEPTH); 764 if (strEQ(name,"QuantumDepth")) 765 return(MAGICKCORE_QUANTUM_DEPTH); 766 if (strEQ(name,"QuantumRange")) 767 return(QuantumRange); 768 break; 769 } 770 case 'R': 771 { 772 if (strEQ(name,"ResourceLimitError")) 773 return(ResourceLimitError); 774 if (strEQ(name,"ResourceLimitWarning")) 775 return(ResourceLimitWarning); 776 if (strEQ(name,"RegistryError")) 777 return(RegistryError); 778 if (strEQ(name,"RegistryWarning")) 779 return(RegistryWarning); 780 break; 781 } 782 case 'S': 783 { 784 if (strEQ(name,"StreamError")) 785 return(StreamError); 786 if (strEQ(name,"StreamWarning")) 787 return(StreamWarning); 788 if (strEQ(name,"Success")) 789 return(0); 790 break; 791 } 792 case 'T': 793 { 794 if (strEQ(name,"Transparent")) 795 return(TransparentAlpha); 796 if (strEQ(name,"TypeError")) 797 return(TypeError); 798 if (strEQ(name,"TypeWarning")) 799 return(TypeWarning); 800 break; 801 } 802 case 'W': 803 { 804 if (strEQ(name,"WarningException")) 805 return(WarningException); 806 break; 807 } 808 case 'X': 809 { 810 if (strEQ(name,"XServerError")) 811 return(XServerError); 812 if (strEQ(name,"XServerWarning")) 813 return(XServerWarning); 814 break; 815 } 816 } 817 errno=EINVAL; 818 return(0); 819 } 820 821 /* 823 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 824 % % 825 % % 826 % % 827 % D e s t r o y P a c k a g e I n f o % 828 % % 829 % % 830 % % 831 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 832 % 833 % Method DestroyPackageInfo frees a previously created info structure. 834 % 835 % The format of the DestroyPackageInfo routine is: 836 % 837 % DestroyPackageInfo(struct PackageInfo *info) 838 % 839 % A description of each parameter follows: 840 % 841 % o info: a structure of type info. 842 % 843 */ 844 static void DestroyPackageInfo(struct PackageInfo *info) 845 { 846 info->image_info=DestroyImageInfo(info->image_info); 847 info=(struct PackageInfo *) RelinquishMagickMemory(info); 848 } 849 850 /* 852 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 853 % % 854 % % 855 % % 856 % G e t L i s t % 857 % % 858 % % 859 % % 860 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 861 % 862 % Method GetList is recursively called by SetupList to traverse the 863 % Image__Magick reference. If building an reference_vector (see SetupList), 864 % *current is the current position in *reference_vector and *last is the final 865 % entry in *reference_vector. 866 % 867 % The format of the GetList routine is: 868 % 869 % GetList(info) 870 % 871 % A description of each parameter follows: 872 % 873 % o info: a structure of type info. 874 % 875 */ 876 static Image *GetList(pTHX_ SV *reference,SV ***reference_vector, 877 ssize_t *current,ssize_t *last,ExceptionInfo *exception) 878 { 879 Image 880 *image; 881 882 if (reference == (SV *) NULL) 883 return(NULL); 884 switch (SvTYPE(reference)) 885 { 886 case SVt_PVAV: 887 { 888 AV 889 *av; 890 891 Image 892 *head, 893 *previous; 894 895 register ssize_t 896 i; 897 898 ssize_t 899 n; 900 901 /* 902 Array of images. 903 */ 904 previous=(Image *) NULL; 905 head=(Image *) NULL; 906 av=(AV *) reference; 907 n=av_len(av); 908 for (i=0; i <= n; i++) 909 { 910 SV 911 **rv; 912 913 rv=av_fetch(av,i,0); 914 if (rv && *rv && sv_isobject(*rv)) 915 { 916 image=GetList(aTHX_ SvRV(*rv),reference_vector,current,last, 917 exception); 918 if (image == (Image *) NULL) 919 continue; 920 if (image == previous) 921 { 922 image=CloneImage(image,0,0,MagickTrue,exception); 923 if (image == (Image *) NULL) 924 return(NULL); 925 } 926 image->previous=previous; 927 *(previous ? &previous->next : &head)=image; 928 for (previous=image; previous->next; previous=previous->next) ; 929 } 930 } 931 return(head); 932 } 933 case SVt_PVMG: 934 { 935 /* 936 Blessed scalar, one image. 937 */ 938 image=INT2PTR(Image *,SvIV(reference)); 939 if (image == (Image *) NULL) 940 return(NULL); 941 image->previous=(Image *) NULL; 942 image->next=(Image *) NULL; 943 if (reference_vector) 944 { 945 if (*current == *last) 946 { 947 *last+=256; 948 if (*reference_vector == (SV **) NULL) 949 *reference_vector=(SV **) AcquireQuantumMemory(*last, 950 sizeof(*reference_vector)); 951 else 952 *reference_vector=(SV **) ResizeQuantumMemory(*reference_vector, 953 *last,sizeof(*reference_vector)); 954 } 955 if (*reference_vector == (SV **) NULL) 956 { 957 ThrowPerlException(exception,ResourceLimitError, 958 "MemoryAllocationFailed",PackageName); 959 return((Image *) NULL); 960 } 961 (*reference_vector)[*current]=reference; 962 (*reference_vector)[++(*current)]=NULL; 963 } 964 return(image); 965 } 966 default: 967 break; 968 } 969 (void) fprintf(stderr,"GetList: UnrecognizedType %.20g\n", 970 (double) SvTYPE(reference)); 971 return((Image *) NULL); 972 } 973 974 /* 976 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 977 % % 978 % % 979 % % 980 % G e t P a c k a g e I n f o % 981 % % 982 % % 983 % % 984 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 985 % 986 % Method GetPackageInfo looks up or creates an info structure for the given 987 % Image__Magick reference. If it does create a new one, the information in 988 % package_info is used to initialize it. 989 % 990 % The format of the GetPackageInfo routine is: 991 % 992 % struct PackageInfo *GetPackageInfo(void *reference, 993 % struct PackageInfo *package_info,ExceptionInfo *exception) 994 % 995 % A description of each parameter follows: 996 % 997 % o info: a structure of type info. 998 % 999 % o exception: Return any errors or warnings in this structure. 1000 % 1001 */ 1002 static struct PackageInfo *GetPackageInfo(pTHX_ void *reference, 1003 struct PackageInfo *package_info,ExceptionInfo *exception) 1004 { 1005 char 1006 message[MagickPathExtent]; 1007 1008 struct PackageInfo 1009 *clone_info; 1010 1011 SV 1012 *sv; 1013 1014 (void) FormatLocaleString(message,MagickPathExtent,"%s::package%s%p", 1015 PackageName,XS_VERSION,reference); 1016 sv=perl_get_sv(message,(TRUE | 0x02)); 1017 if (sv == (SV *) NULL) 1018 { 1019 ThrowPerlException(exception,ResourceLimitError,"UnableToGetPackageInfo", 1020 message); 1021 return(package_info); 1022 } 1023 if (SvREFCNT(sv) == 0) 1024 (void) SvREFCNT_inc(sv); 1025 if (SvIOKp(sv) && (clone_info=INT2PTR(struct PackageInfo *,SvIV(sv)))) 1026 return(clone_info); 1027 clone_info=ClonePackageInfo(package_info,exception); 1028 sv_setiv(sv,PTR2IV(clone_info)); 1029 return(clone_info); 1030 } 1031 1032 /* 1034 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1035 % % 1036 % % 1037 % % 1038 % S e t A t t r i b u t e % 1039 % % 1040 % % 1041 % % 1042 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 1043 % 1044 % SetAttribute() sets the attribute to the value in sval. This can change 1045 % either or both of image or info. 1046 % 1047 % The format of the SetAttribute routine is: 1048 % 1049 % SetAttribute(struct PackageInfo *info,Image *image,char *attribute, 1050 % SV *sval,ExceptionInfo *exception) 1051 % 1052 % A description of each parameter follows: 1053 % 1054 % o list: a list of strings. 1055 % 1056 % o string: a character string. 1057 % 1058 */ 1059 1060 static double SiPrefixToDoubleInterval(const char *string,const double interval) 1061 { 1062 char 1063 *q; 1064 1065 double 1066 value; 1067 1068 value=InterpretSiPrefixValue(string,&q); 1069 if (*q == '%') 1070 value*=interval/100.0; 1071 return(value); 1072 } 1073 1074 static inline double StringToDouble(const char *string,char **sentinal) 1075 { 1076 return(InterpretLocaleValue(string,sentinal)); 1077 } 1078 1079 static double StringToDoubleInterval(const char *string,const double interval) 1080 { 1081 char 1082 *q; 1083 1084 double 1085 value; 1086 1087 value=InterpretLocaleValue(string,&q); 1088 if (*q == '%') 1089 value*=interval/100.0; 1090 return(value); 1091 } 1092 1093 static inline ssize_t StringToLong(const char *value) 1094 { 1095 return(strtol(value,(char **) NULL,10)); 1096 } 1097 1098 static void SetAttribute(pTHX_ struct PackageInfo *info,Image *image, 1099 const char *attribute,SV *sval,ExceptionInfo *exception) 1100 { 1101 GeometryInfo 1102 geometry_info; 1103 1104 long 1105 x, 1106 y; 1107 1108 PixelInfo 1109 pixel; 1110 1111 MagickStatusType 1112 flags; 1113 1114 PixelInfo 1115 *color, 1116 target_color; 1117 1118 ssize_t 1119 sp; 1120 1121 switch (*attribute) 1122 { 1123 case 'A': 1124 case 'a': 1125 { 1126 if (LocaleCompare(attribute,"adjoin") == 0) 1127 { 1128 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions,MagickFalse, 1129 SvPV(sval,na)) : SvIV(sval); 1130 if (sp < 0) 1131 { 1132 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1133 SvPV(sval,na)); 1134 break; 1135 } 1136 if (info) 1137 info->image_info->adjoin=sp != 0 ? MagickTrue : MagickFalse; 1138 break; 1139 } 1140 if (LocaleCompare(attribute,"alpha") == 0) 1141 { 1142 sp=SvPOK(sval) ? ParseCommandOption(MagickAlphaChannelOptions, 1143 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1144 if (sp < 0) 1145 { 1146 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1147 SvPV(sval,na)); 1148 break; 1149 } 1150 for ( ; image; image=image->next) 1151 (void) SetImageAlphaChannel(image,(AlphaChannelOption) sp, 1152 exception); 1153 break; 1154 } 1155 if (LocaleCompare(attribute,"antialias") == 0) 1156 { 1157 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions,MagickFalse, 1158 SvPV(sval,na)) : SvIV(sval); 1159 if (sp < 0) 1160 { 1161 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1162 SvPV(sval,na)); 1163 break; 1164 } 1165 if (info) 1166 info->image_info->antialias=sp != 0 ? MagickTrue : MagickFalse; 1167 break; 1168 } 1169 if (LocaleCompare(attribute,"area-limit") == 0) 1170 { 1171 MagickSizeType 1172 limit; 1173 1174 limit=MagickResourceInfinity; 1175 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 1176 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 1177 100.0); 1178 (void) SetMagickResourceLimit(AreaResource,limit); 1179 break; 1180 } 1181 if (LocaleCompare(attribute,"attenuate") == 0) 1182 { 1183 if (info) 1184 (void) SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1185 break; 1186 } 1187 if (LocaleCompare(attribute,"authenticate") == 0) 1188 { 1189 if (info) 1190 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1191 break; 1192 } 1193 if (info) 1194 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1195 for ( ; image; image=image->next) 1196 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1197 break; 1198 } 1199 case 'B': 1200 case 'b': 1201 { 1202 if (LocaleCompare(attribute,"background") == 0) 1203 { 1204 (void) QueryColorCompliance(SvPV(sval,na),AllCompliance,&target_color, 1205 exception); 1206 if (info) 1207 info->image_info->background_color=target_color; 1208 for ( ; image; image=image->next) 1209 image->background_color=target_color; 1210 break; 1211 } 1212 if (LocaleCompare(attribute,"blue-primary") == 0) 1213 { 1214 for ( ; image; image=image->next) 1215 { 1216 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1217 image->chromaticity.blue_primary.x=geometry_info.rho; 1218 image->chromaticity.blue_primary.y=geometry_info.sigma; 1219 if ((flags & SigmaValue) == 0) 1220 image->chromaticity.blue_primary.y= 1221 image->chromaticity.blue_primary.x; 1222 } 1223 break; 1224 } 1225 if (LocaleCompare(attribute,"bordercolor") == 0) 1226 { 1227 (void) QueryColorCompliance(SvPV(sval,na),AllCompliance,&target_color, 1228 exception); 1229 if (info) 1230 info->image_info->border_color=target_color; 1231 for ( ; image; image=image->next) 1232 image->border_color=target_color; 1233 break; 1234 } 1235 if (info) 1236 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1237 for ( ; image; image=image->next) 1238 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1239 break; 1240 } 1241 case 'C': 1242 case 'c': 1243 { 1244 if (LocaleCompare(attribute,"cache-threshold") == 0) 1245 { 1246 (void) SetMagickResourceLimit(MemoryResource,(MagickSizeType) 1247 SiPrefixToDoubleInterval(SvPV(sval,na),100.0)); 1248 (void) SetMagickResourceLimit(MapResource,(MagickSizeType) 1249 (2.0*SiPrefixToDoubleInterval(SvPV(sval,na),100.0))); 1250 break; 1251 } 1252 if (LocaleCompare(attribute,"clip-mask") == 0) 1253 { 1254 Image 1255 *clip_mask; 1256 1257 clip_mask=(Image *) NULL; 1258 if (SvPOK(sval)) 1259 clip_mask=SetupList(aTHX_ SvRV(sval),&info,(SV ***) NULL,exception); 1260 for ( ; image; image=image->next) 1261 SetImageMask(image,ReadPixelMask,clip_mask,exception); 1262 break; 1263 } 1264 if (LocaleNCompare(attribute,"colormap",8) == 0) 1265 { 1266 for ( ; image; image=image->next) 1267 { 1268 int 1269 items; 1270 1271 long 1272 i; 1273 1274 if (image->storage_class == DirectClass) 1275 continue; 1276 i=0; 1277 items=sscanf(attribute,"%*[^[][%ld",&i); 1278 (void) items; 1279 if (i > (ssize_t) image->colors) 1280 i%=image->colors; 1281 if ((strchr(SvPV(sval,na),',') == 0) || 1282 (strchr(SvPV(sval,na),')') != 0)) 1283 QueryColorCompliance(SvPV(sval,na),AllCompliance, 1284 image->colormap+i,exception); 1285 else 1286 { 1287 color=image->colormap+i; 1288 pixel.red=color->red; 1289 pixel.green=color->green; 1290 pixel.blue=color->blue; 1291 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1292 pixel.red=geometry_info.rho; 1293 pixel.green=geometry_info.sigma; 1294 pixel.blue=geometry_info.xi; 1295 color->red=ClampToQuantum(pixel.red); 1296 color->green=ClampToQuantum(pixel.green); 1297 color->blue=ClampToQuantum(pixel.blue); 1298 } 1299 } 1300 break; 1301 } 1302 if (LocaleCompare(attribute,"colorspace") == 0) 1303 { 1304 sp=SvPOK(sval) ? ParseCommandOption(MagickColorspaceOptions, 1305 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1306 if (sp < 0) 1307 { 1308 ThrowPerlException(exception,OptionError,"UnrecognizedColorspace", 1309 SvPV(sval,na)); 1310 break; 1311 } 1312 for ( ; image; image=image->next) 1313 (void) TransformImageColorspace(image,(ColorspaceType) sp, 1314 exception); 1315 break; 1316 } 1317 if (LocaleCompare(attribute,"comment") == 0) 1318 { 1319 for ( ; image; image=image->next) 1320 (void) SetImageProperty(image,"Comment",InterpretImageProperties( 1321 info ? info->image_info : (ImageInfo *) NULL,image, 1322 SvPV(sval,na),exception),exception); 1323 break; 1324 } 1325 if (LocaleCompare(attribute,"compression") == 0) 1326 { 1327 sp=SvPOK(sval) ? ParseCommandOption(MagickCompressOptions, 1328 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1329 if (sp < 0) 1330 { 1331 ThrowPerlException(exception,OptionError, 1332 "UnrecognizedImageCompression",SvPV(sval,na)); 1333 break; 1334 } 1335 if (info) 1336 info->image_info->compression=(CompressionType) sp; 1337 for ( ; image; image=image->next) 1338 image->compression=(CompressionType) sp; 1339 break; 1340 } 1341 if (info) 1342 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1343 for ( ; image; image=image->next) 1344 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1345 break; 1346 } 1347 case 'D': 1348 case 'd': 1349 { 1350 if (LocaleCompare(attribute,"debug") == 0) 1351 { 1352 SetLogEventMask(SvPV(sval,na)); 1353 break; 1354 } 1355 if (LocaleCompare(attribute,"delay") == 0) 1356 { 1357 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1358 for ( ; image; image=image->next) 1359 { 1360 image->delay=(size_t) floor(geometry_info.rho+0.5); 1361 if ((flags & SigmaValue) != 0) 1362 image->ticks_per_second=(ssize_t) 1363 floor(geometry_info.sigma+0.5); 1364 } 1365 break; 1366 } 1367 if (LocaleCompare(attribute,"disk-limit") == 0) 1368 { 1369 MagickSizeType 1370 limit; 1371 1372 limit=MagickResourceInfinity; 1373 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 1374 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 1375 100.0); 1376 (void) SetMagickResourceLimit(DiskResource,limit); 1377 break; 1378 } 1379 if (LocaleCompare(attribute,"density") == 0) 1380 { 1381 if (IsGeometry(SvPV(sval,na)) == MagickFalse) 1382 { 1383 ThrowPerlException(exception,OptionError,"MissingGeometry", 1384 SvPV(sval,na)); 1385 break; 1386 } 1387 if (info) 1388 (void) CloneString(&info->image_info->density,SvPV(sval,na)); 1389 for ( ; image; image=image->next) 1390 { 1391 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1392 image->resolution.x=geometry_info.rho; 1393 image->resolution.y=geometry_info.sigma; 1394 if ((flags & SigmaValue) == 0) 1395 image->resolution.y=image->resolution.x; 1396 } 1397 break; 1398 } 1399 if (LocaleCompare(attribute,"depth") == 0) 1400 { 1401 if (info) 1402 info->image_info->depth=SvIV(sval); 1403 for ( ; image; image=image->next) 1404 (void) SetImageDepth(image,SvIV(sval),exception); 1405 break; 1406 } 1407 if (LocaleCompare(attribute,"dispose") == 0) 1408 { 1409 sp=SvPOK(sval) ? ParseCommandOption(MagickDisposeOptions,MagickFalse, 1410 SvPV(sval,na)) : SvIV(sval); 1411 if (sp < 0) 1412 { 1413 ThrowPerlException(exception,OptionError, 1414 "UnrecognizedDisposeMethod",SvPV(sval,na)); 1415 break; 1416 } 1417 for ( ; image; image=image->next) 1418 image->dispose=(DisposeType) sp; 1419 break; 1420 } 1421 if (LocaleCompare(attribute,"dither") == 0) 1422 { 1423 if (info) 1424 { 1425 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions, 1426 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1427 if (sp < 0) 1428 { 1429 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1430 SvPV(sval,na)); 1431 break; 1432 } 1433 info->image_info->dither=sp != 0 ? MagickTrue : MagickFalse; 1434 } 1435 break; 1436 } 1437 if (LocaleCompare(attribute,"display") == 0) 1438 { 1439 display: 1440 if (info) 1441 (void) CloneString(&info->image_info->server_name,SvPV(sval,na)); 1442 break; 1443 } 1444 if (info) 1445 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1446 for ( ; image; image=image->next) 1447 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1448 break; 1449 } 1450 case 'E': 1451 case 'e': 1452 { 1453 if (LocaleCompare(attribute,"endian") == 0) 1454 { 1455 sp=SvPOK(sval) ? ParseCommandOption(MagickEndianOptions,MagickFalse, 1456 SvPV(sval,na)) : SvIV(sval); 1457 if (sp < 0) 1458 { 1459 ThrowPerlException(exception,OptionError,"UnrecognizedEndianType", 1460 SvPV(sval,na)); 1461 break; 1462 } 1463 if (info) 1464 info->image_info->endian=(EndianType) sp; 1465 for ( ; image; image=image->next) 1466 image->endian=(EndianType) sp; 1467 break; 1468 } 1469 if (LocaleCompare(attribute,"extract") == 0) 1470 { 1471 /* 1472 Set image extract geometry. 1473 */ 1474 (void) CloneString(&info->image_info->extract,SvPV(sval,na)); 1475 break; 1476 } 1477 if (info) 1478 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1479 for ( ; image; image=image->next) 1480 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1481 break; 1482 } 1483 case 'F': 1484 case 'f': 1485 { 1486 if (LocaleCompare(attribute,"filename") == 0) 1487 { 1488 if (info) 1489 (void) CopyMagickString(info->image_info->filename,SvPV(sval,na), 1490 MagickPathExtent); 1491 for ( ; image; image=image->next) 1492 (void) CopyMagickString(image->filename,SvPV(sval,na), 1493 MagickPathExtent); 1494 break; 1495 } 1496 if (LocaleCompare(attribute,"file") == 0) 1497 { 1498 FILE 1499 *file; 1500 1501 PerlIO 1502 *io_info; 1503 1504 if (info == (struct PackageInfo *) NULL) 1505 break; 1506 io_info=IoIFP(sv_2io(sval)); 1507 if (io_info == (PerlIO *) NULL) 1508 { 1509 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 1510 PackageName); 1511 break; 1512 } 1513 file=PerlIO_findFILE(io_info); 1514 if (file == (FILE *) NULL) 1515 { 1516 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 1517 PackageName); 1518 break; 1519 } 1520 SetImageInfoFile(info->image_info,file); 1521 break; 1522 } 1523 if (LocaleCompare(attribute,"fill") == 0) 1524 { 1525 if (info) 1526 (void) SetImageOption(info->image_info,"fill",SvPV(sval,na)); 1527 break; 1528 } 1529 if (LocaleCompare(attribute,"font") == 0) 1530 { 1531 if (info) 1532 (void) CloneString(&info->image_info->font,SvPV(sval,na)); 1533 break; 1534 } 1535 if (LocaleCompare(attribute,"foreground") == 0) 1536 break; 1537 if (LocaleCompare(attribute,"fuzz") == 0) 1538 { 1539 if (info) 1540 info->image_info->fuzz=StringToDoubleInterval(SvPV(sval,na),(double) 1541 QuantumRange+1.0); 1542 for ( ; image; image=image->next) 1543 image->fuzz=StringToDoubleInterval(SvPV(sval,na),(double) 1544 QuantumRange+1.0); 1545 break; 1546 } 1547 if (info) 1548 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1549 for ( ; image; image=image->next) 1550 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1551 break; 1552 } 1553 case 'G': 1554 case 'g': 1555 { 1556 if (LocaleCompare(attribute,"gamma") == 0) 1557 { 1558 for ( ; image; image=image->next) 1559 image->gamma=SvNV(sval); 1560 break; 1561 } 1562 if (LocaleCompare(attribute,"gravity") == 0) 1563 { 1564 sp=SvPOK(sval) ? ParseCommandOption(MagickGravityOptions,MagickFalse, 1565 SvPV(sval,na)) : SvIV(sval); 1566 if (sp < 0) 1567 { 1568 ThrowPerlException(exception,OptionError, 1569 "UnrecognizedGravityType",SvPV(sval,na)); 1570 break; 1571 } 1572 if (info) 1573 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1574 for ( ; image; image=image->next) 1575 image->gravity=(GravityType) sp; 1576 break; 1577 } 1578 if (LocaleCompare(attribute,"green-primary") == 0) 1579 { 1580 for ( ; image; image=image->next) 1581 { 1582 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1583 image->chromaticity.green_primary.x=geometry_info.rho; 1584 image->chromaticity.green_primary.y=geometry_info.sigma; 1585 if ((flags & SigmaValue) == 0) 1586 image->chromaticity.green_primary.y= 1587 image->chromaticity.green_primary.x; 1588 } 1589 break; 1590 } 1591 if (info) 1592 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1593 for ( ; image; image=image->next) 1594 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1595 break; 1596 } 1597 case 'I': 1598 case 'i': 1599 { 1600 if (LocaleNCompare(attribute,"index",5) == 0) 1601 { 1602 int 1603 items; 1604 1605 long 1606 index; 1607 1608 register Quantum 1609 *q; 1610 1611 CacheView 1612 *image_view; 1613 1614 for ( ; image; image=image->next) 1615 { 1616 if (image->storage_class != PseudoClass) 1617 continue; 1618 x=0; 1619 y=0; 1620 items=sscanf(attribute,"%*[^[][%ld%*[,/]%ld",&x,&y); 1621 (void) items; 1622 image_view=AcquireAuthenticCacheView(image,exception); 1623 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); 1624 if (q != (Quantum *) NULL) 1625 { 1626 items=sscanf(SvPV(sval,na),"%ld",&index); 1627 if ((index >= 0) && (index < (ssize_t) image->colors)) 1628 SetPixelIndex(image,index,q); 1629 (void) SyncCacheViewAuthenticPixels(image_view,exception); 1630 } 1631 image_view=DestroyCacheView(image_view); 1632 } 1633 break; 1634 } 1635 if (LocaleCompare(attribute,"iterations") == 0) 1636 { 1637 iterations: 1638 for ( ; image; image=image->next) 1639 image->iterations=SvIV(sval); 1640 break; 1641 } 1642 if (LocaleCompare(attribute,"interlace") == 0) 1643 { 1644 sp=SvPOK(sval) ? ParseCommandOption(MagickInterlaceOptions, 1645 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1646 if (sp < 0) 1647 { 1648 ThrowPerlException(exception,OptionError, 1649 "UnrecognizedInterlaceType",SvPV(sval,na)); 1650 break; 1651 } 1652 if (info) 1653 info->image_info->interlace=(InterlaceType) sp; 1654 for ( ; image; image=image->next) 1655 image->interlace=(InterlaceType) sp; 1656 break; 1657 } 1658 if (info) 1659 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1660 for ( ; image; image=image->next) 1661 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1662 break; 1663 } 1664 case 'L': 1665 case 'l': 1666 { 1667 if (LocaleCompare(attribute,"label") == 0) 1668 { 1669 for ( ; image; image=image->next) 1670 (void) SetImageProperty(image,"label",InterpretImageProperties( 1671 info ? info->image_info : (ImageInfo *) NULL,image, 1672 SvPV(sval,na),exception),exception); 1673 break; 1674 } 1675 if (LocaleCompare(attribute,"loop") == 0) 1676 goto iterations; 1677 if (info) 1678 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1679 for ( ; image; image=image->next) 1680 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1681 break; 1682 } 1683 case 'M': 1684 case 'm': 1685 { 1686 if (LocaleCompare(attribute,"magick") == 0) 1687 { 1688 if (info) 1689 (void) FormatLocaleString(info->image_info->filename,MagickPathExtent, 1690 "%s:",SvPV(sval,na)); 1691 for ( ; image; image=image->next) 1692 (void) CopyMagickString(image->magick,SvPV(sval,na),MagickPathExtent); 1693 break; 1694 } 1695 if (LocaleCompare(attribute,"map-limit") == 0) 1696 { 1697 MagickSizeType 1698 limit; 1699 1700 limit=MagickResourceInfinity; 1701 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 1702 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 1703 100.0); 1704 (void) SetMagickResourceLimit(MapResource,limit); 1705 break; 1706 } 1707 if (LocaleCompare(attribute,"mask") == 0) 1708 { 1709 Image 1710 *mask; 1711 1712 mask=(Image *) NULL; 1713 if (SvPOK(sval)) 1714 mask=SetupList(aTHX_ SvRV(sval),&info,(SV ***) NULL,exception); 1715 for ( ; image; image=image->next) 1716 SetImageMask(image,ReadPixelMask,mask,exception); 1717 break; 1718 } 1719 if (LocaleCompare(attribute,"mattecolor") == 0) 1720 { 1721 (void) QueryColorCompliance(SvPV(sval,na),AllCompliance,&target_color, 1722 exception); 1723 if (info) 1724 info->image_info->alpha_color=target_color; 1725 for ( ; image; image=image->next) 1726 image->alpha_color=target_color; 1727 break; 1728 } 1729 if (LocaleCompare(attribute,"matte") == 0) 1730 { 1731 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions,MagickFalse, 1732 SvPV(sval,na)) : SvIV(sval); 1733 if (sp < 0) 1734 { 1735 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1736 SvPV(sval,na)); 1737 break; 1738 } 1739 for ( ; image; image=image->next) 1740 image->alpha_trait=sp != 0 ? BlendPixelTrait : UndefinedPixelTrait; 1741 break; 1742 } 1743 if (LocaleCompare(attribute,"memory-limit") == 0) 1744 { 1745 MagickSizeType 1746 limit; 1747 1748 limit=MagickResourceInfinity; 1749 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 1750 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 1751 100.0); 1752 (void) SetMagickResourceLimit(MemoryResource,limit); 1753 break; 1754 } 1755 if (LocaleCompare(attribute,"monochrome") == 0) 1756 { 1757 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions,MagickFalse, 1758 SvPV(sval,na)) : SvIV(sval); 1759 if (sp < 0) 1760 { 1761 ThrowPerlException(exception,OptionError,"UnrecognizedType", 1762 SvPV(sval,na)); 1763 break; 1764 } 1765 if (info) 1766 info->image_info->monochrome=sp != 0 ? MagickTrue : MagickFalse; 1767 for ( ; image; image=image->next) 1768 (void) SetImageType(image,BilevelType,exception); 1769 break; 1770 } 1771 if (info) 1772 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1773 for ( ; image; image=image->next) 1774 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1775 break; 1776 } 1777 case 'O': 1778 case 'o': 1779 { 1780 if (LocaleCompare(attribute,"option") == 0) 1781 { 1782 if (info) 1783 DefineImageOption(info->image_info,SvPV(sval,na)); 1784 break; 1785 } 1786 if (LocaleCompare(attribute,"orientation") == 0) 1787 { 1788 sp=SvPOK(sval) ? ParseCommandOption(MagickOrientationOptions, 1789 MagickFalse,SvPV(sval,na)) : SvIV(sval); 1790 if (sp < 0) 1791 { 1792 ThrowPerlException(exception,OptionError, 1793 "UnrecognizedOrientationType",SvPV(sval,na)); 1794 break; 1795 } 1796 if (info) 1797 info->image_info->orientation=(OrientationType) sp; 1798 for ( ; image; image=image->next) 1799 image->orientation=(OrientationType) sp; 1800 break; 1801 } 1802 if (info) 1803 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1804 for ( ; image; image=image->next) 1805 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1806 break; 1807 } 1808 case 'P': 1809 case 'p': 1810 { 1811 if (LocaleCompare(attribute,"page") == 0) 1812 { 1813 char 1814 *geometry; 1815 1816 geometry=GetPageGeometry(SvPV(sval,na)); 1817 if (info) 1818 (void) CloneString(&info->image_info->page,geometry); 1819 for ( ; image; image=image->next) 1820 (void) ParsePageGeometry(image,geometry,&image->page,exception); 1821 geometry=(char *) RelinquishMagickMemory(geometry); 1822 break; 1823 } 1824 if (LocaleNCompare(attribute,"pixel",5) == 0) 1825 { 1826 int 1827 items; 1828 1829 PixelInfo 1830 pixel; 1831 1832 register Quantum 1833 *q; 1834 1835 CacheView 1836 *image_view; 1837 1838 for ( ; image; image=image->next) 1839 { 1840 if (SetImageStorageClass(image,DirectClass,exception) == MagickFalse) 1841 break; 1842 x=0; 1843 y=0; 1844 items=sscanf(attribute,"%*[^[][%ld%*[,/]%ld",&x,&y); 1845 (void) items; 1846 image_view=AcquireVirtualCacheView(image,exception); 1847 q=GetCacheViewAuthenticPixels(image_view,x,y,1,1,exception); 1848 if (q != (Quantum *) NULL) 1849 { 1850 if ((strchr(SvPV(sval,na),',') == 0) || 1851 (strchr(SvPV(sval,na),')') != 0)) 1852 QueryColorCompliance(SvPV(sval,na),AllCompliance, 1853 &pixel,exception); 1854 else 1855 { 1856 GetPixelInfo(image,&pixel); 1857 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1858 pixel.red=geometry_info.rho; 1859 if ((flags & SigmaValue) != 0) 1860 pixel.green=geometry_info.sigma; 1861 if ((flags & XiValue) != 0) 1862 pixel.blue=geometry_info.xi; 1863 if ((flags & PsiValue) != 0) 1864 pixel.alpha=geometry_info.psi; 1865 if ((flags & ChiValue) != 0) 1866 pixel.black=geometry_info.chi; 1867 } 1868 SetPixelRed(image,ClampToQuantum(pixel.red),q); 1869 SetPixelGreen(image,ClampToQuantum(pixel.green),q); 1870 SetPixelBlue(image,ClampToQuantum(pixel.blue),q); 1871 if (image->colorspace == CMYKColorspace) 1872 SetPixelBlack(image,ClampToQuantum(pixel.black),q); 1873 SetPixelAlpha(image,ClampToQuantum(pixel.alpha),q); 1874 (void) SyncCacheViewAuthenticPixels(image_view,exception); 1875 } 1876 image_view=DestroyCacheView(image_view); 1877 } 1878 break; 1879 } 1880 if (LocaleCompare(attribute,"pointsize") == 0) 1881 { 1882 if (info) 1883 { 1884 (void) ParseGeometry(SvPV(sval,na),&geometry_info); 1885 info->image_info->pointsize=geometry_info.rho; 1886 } 1887 break; 1888 } 1889 if (info) 1890 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1891 for ( ; image; image=image->next) 1892 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1893 break; 1894 } 1895 case 'Q': 1896 case 'q': 1897 { 1898 if (LocaleCompare(attribute,"quality") == 0) 1899 { 1900 if (info) 1901 info->image_info->quality=SvIV(sval); 1902 for ( ; image; image=image->next) 1903 image->quality=SvIV(sval); 1904 break; 1905 } 1906 if (info) 1907 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1908 for ( ; image; image=image->next) 1909 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1910 break; 1911 } 1912 case 'R': 1913 case 'r': 1914 { 1915 if (LocaleCompare(attribute,"read-mask") == 0) 1916 { 1917 Image 1918 *mask; 1919 1920 mask=(Image *) NULL; 1921 if (SvPOK(sval)) 1922 mask=SetupList(aTHX_ SvRV(sval),&info,(SV ***) NULL,exception); 1923 for ( ; image; image=image->next) 1924 SetImageMask(image,ReadPixelMask,mask,exception); 1925 break; 1926 } 1927 if (LocaleCompare(attribute,"red-primary") == 0) 1928 { 1929 for ( ; image; image=image->next) 1930 { 1931 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 1932 image->chromaticity.red_primary.x=geometry_info.rho; 1933 image->chromaticity.red_primary.y=geometry_info.sigma; 1934 if ((flags & SigmaValue) == 0) 1935 image->chromaticity.red_primary.y= 1936 image->chromaticity.red_primary.x; 1937 } 1938 break; 1939 } 1940 if (LocaleCompare(attribute,"render") == 0) 1941 { 1942 sp=SvPOK(sval) ? ParseCommandOption(MagickIntentOptions,MagickFalse, 1943 SvPV(sval,na)) : SvIV(sval); 1944 if (sp < 0) 1945 { 1946 ThrowPerlException(exception,OptionError,"UnrecognizedIntentType", 1947 SvPV(sval,na)); 1948 break; 1949 } 1950 for ( ; image; image=image->next) 1951 image->rendering_intent=(RenderingIntent) sp; 1952 break; 1953 } 1954 if (LocaleCompare(attribute,"repage") == 0) 1955 { 1956 RectangleInfo 1957 geometry; 1958 1959 for ( ; image; image=image->next) 1960 { 1961 flags=ParseAbsoluteGeometry(SvPV(sval,na),&geometry); 1962 if ((flags & WidthValue) != 0) 1963 { 1964 if ((flags & HeightValue) == 0) 1965 geometry.height=geometry.width; 1966 image->page.width=geometry.width; 1967 image->page.height=geometry.height; 1968 } 1969 if ((flags & AspectValue) != 0) 1970 { 1971 if ((flags & XValue) != 0) 1972 image->page.x+=geometry.x; 1973 if ((flags & YValue) != 0) 1974 image->page.y+=geometry.y; 1975 } 1976 else 1977 { 1978 if ((flags & XValue) != 0) 1979 { 1980 image->page.x=geometry.x; 1981 if (((flags & WidthValue) != 0) && (geometry.x > 0)) 1982 image->page.width=image->columns+geometry.x; 1983 } 1984 if ((flags & YValue) != 0) 1985 { 1986 image->page.y=geometry.y; 1987 if (((flags & HeightValue) != 0) && (geometry.y > 0)) 1988 image->page.height=image->rows+geometry.y; 1989 } 1990 } 1991 } 1992 break; 1993 } 1994 if (info) 1995 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 1996 for ( ; image; image=image->next) 1997 SetImageProperty(image,attribute,SvPV(sval,na),exception); 1998 break; 1999 } 2000 case 'S': 2001 case 's': 2002 { 2003 if (LocaleCompare(attribute,"sampling-factor") == 0) 2004 { 2005 if (IsGeometry(SvPV(sval,na)) == MagickFalse) 2006 { 2007 ThrowPerlException(exception,OptionError,"MissingGeometry", 2008 SvPV(sval,na)); 2009 break; 2010 } 2011 if (info) 2012 (void) CloneString(&info->image_info->sampling_factor, 2013 SvPV(sval,na)); 2014 break; 2015 } 2016 if (LocaleCompare(attribute,"scene") == 0) 2017 { 2018 for ( ; image; image=image->next) 2019 image->scene=SvIV(sval); 2020 break; 2021 } 2022 if (LocaleCompare(attribute,"server") == 0) 2023 goto display; 2024 if (LocaleCompare(attribute,"size") == 0) 2025 { 2026 if (info) 2027 { 2028 if (IsGeometry(SvPV(sval,na)) == MagickFalse) 2029 { 2030 ThrowPerlException(exception,OptionError,"MissingGeometry", 2031 SvPV(sval,na)); 2032 break; 2033 } 2034 (void) CloneString(&info->image_info->size,SvPV(sval,na)); 2035 } 2036 break; 2037 } 2038 if (LocaleCompare(attribute,"stroke") == 0) 2039 { 2040 if (info) 2041 (void) SetImageOption(info->image_info,"stroke",SvPV(sval,na)); 2042 break; 2043 } 2044 if (info) 2045 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2046 for ( ; image; image=image->next) 2047 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2048 break; 2049 } 2050 case 'T': 2051 case 't': 2052 { 2053 if (LocaleCompare(attribute,"texture") == 0) 2054 { 2055 if (info) 2056 (void) CloneString(&info->image_info->texture,SvPV(sval,na)); 2057 break; 2058 } 2059 if (LocaleCompare(attribute,"thread-limit") == 0) 2060 { 2061 MagickSizeType 2062 limit; 2063 2064 limit=MagickResourceInfinity; 2065 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 2066 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 2067 100.0); 2068 (void) SetMagickResourceLimit(ThreadResource,limit); 2069 break; 2070 } 2071 if (LocaleCompare(attribute,"tile-offset") == 0) 2072 { 2073 char 2074 *geometry; 2075 2076 geometry=GetPageGeometry(SvPV(sval,na)); 2077 if (info) 2078 (void) CloneString(&info->image_info->page,geometry); 2079 for ( ; image; image=image->next) 2080 (void) ParsePageGeometry(image,geometry,&image->tile_offset, 2081 exception); 2082 geometry=(char *) RelinquishMagickMemory(geometry); 2083 break; 2084 } 2085 if (LocaleCompare(attribute,"time-limit") == 0) 2086 { 2087 MagickSizeType 2088 limit; 2089 2090 limit=MagickResourceInfinity; 2091 if (LocaleCompare(SvPV(sval,na),"unlimited") != 0) 2092 limit=(MagickSizeType) SiPrefixToDoubleInterval(SvPV(sval,na), 2093 100.0); 2094 (void) SetMagickResourceLimit(TimeResource,limit); 2095 break; 2096 } 2097 if (LocaleCompare(attribute,"transparent-color") == 0) 2098 { 2099 (void) QueryColorCompliance(SvPV(sval,na),AllCompliance,&target_color, 2100 exception); 2101 if (info) 2102 info->image_info->transparent_color=target_color; 2103 for ( ; image; image=image->next) 2104 image->transparent_color=target_color; 2105 break; 2106 } 2107 if (LocaleCompare(attribute,"type") == 0) 2108 { 2109 sp=SvPOK(sval) ? ParseCommandOption(MagickTypeOptions,MagickFalse, 2110 SvPV(sval,na)) : SvIV(sval); 2111 if (sp < 0) 2112 { 2113 ThrowPerlException(exception,OptionError,"UnrecognizedType", 2114 SvPV(sval,na)); 2115 break; 2116 } 2117 if (info) 2118 info->image_info->type=(ImageType) sp; 2119 for ( ; image; image=image->next) 2120 SetImageType(image,(ImageType) sp,exception); 2121 break; 2122 } 2123 if (info) 2124 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2125 for ( ; image; image=image->next) 2126 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2127 break; 2128 } 2129 case 'U': 2130 case 'u': 2131 { 2132 if (LocaleCompare(attribute,"units") == 0) 2133 { 2134 sp=SvPOK(sval) ? ParseCommandOption(MagickResolutionOptions, 2135 MagickFalse,SvPV(sval,na)) : SvIV(sval); 2136 if (sp < 0) 2137 { 2138 ThrowPerlException(exception,OptionError,"UnrecognizedUnitsType", 2139 SvPV(sval,na)); 2140 break; 2141 } 2142 if (info) 2143 info->image_info->units=(ResolutionType) sp; 2144 for ( ; image; image=image->next) 2145 { 2146 ResolutionType 2147 units; 2148 2149 units=(ResolutionType) sp; 2150 if (image->units != units) 2151 switch (image->units) 2152 { 2153 case UndefinedResolution: 2154 case PixelsPerInchResolution: 2155 { 2156 if (units == PixelsPerCentimeterResolution) 2157 { 2158 image->resolution.x*=2.54; 2159 image->resolution.y*=2.54; 2160 } 2161 break; 2162 } 2163 case PixelsPerCentimeterResolution: 2164 { 2165 if (units == PixelsPerInchResolution) 2166 { 2167 image->resolution.x/=2.54; 2168 image->resolution.y/=2.54; 2169 } 2170 break; 2171 } 2172 } 2173 image->units=units; 2174 } 2175 break; 2176 } 2177 if (info) 2178 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2179 for ( ; image; image=image->next) 2180 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2181 break; 2182 } 2183 case 'V': 2184 case 'v': 2185 { 2186 if (LocaleCompare(attribute,"verbose") == 0) 2187 { 2188 sp=SvPOK(sval) ? ParseCommandOption(MagickBooleanOptions,MagickFalse, 2189 SvPV(sval,na)) : SvIV(sval); 2190 if (sp < 0) 2191 { 2192 ThrowPerlException(exception,OptionError,"UnrecognizedType", 2193 SvPV(sval,na)); 2194 break; 2195 } 2196 if (info) 2197 info->image_info->verbose=sp != 0 ? MagickTrue : MagickFalse; 2198 break; 2199 } 2200 if (LocaleCompare(attribute,"virtual-pixel") == 0) 2201 { 2202 sp=SvPOK(sval) ? ParseCommandOption(MagickVirtualPixelOptions, 2203 MagickFalse,SvPV(sval,na)) : SvIV(sval); 2204 if (sp < 0) 2205 { 2206 ThrowPerlException(exception,OptionError, 2207 "UnrecognizedVirtualPixelMethod",SvPV(sval,na)); 2208 break; 2209 } 2210 for ( ; image; image=image->next) 2211 SetImageVirtualPixelMethod(image,(VirtualPixelMethod) sp,exception); 2212 break; 2213 } 2214 if (info) 2215 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2216 for ( ; image; image=image->next) 2217 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2218 break; 2219 } 2220 case 'W': 2221 case 'w': 2222 { 2223 if (LocaleCompare(attribute,"white-point") == 0) 2224 { 2225 for ( ; image; image=image->next) 2226 { 2227 flags=ParseGeometry(SvPV(sval,na),&geometry_info); 2228 image->chromaticity.white_point.x=geometry_info.rho; 2229 image->chromaticity.white_point.y=geometry_info.sigma; 2230 if ((flags & SigmaValue) == 0) 2231 image->chromaticity.white_point.y= 2232 image->chromaticity.white_point.x; 2233 } 2234 break; 2235 } 2236 if (LocaleCompare(attribute,"write-mask") == 0) 2237 { 2238 Image 2239 *mask; 2240 2241 mask=(Image *) NULL; 2242 if (SvPOK(sval)) 2243 mask=SetupList(aTHX_ SvRV(sval),&info,(SV ***) NULL,exception); 2244 for ( ; image; image=image->next) 2245 SetImageMask(image,WritePixelMask,mask,exception); 2246 break; 2247 } 2248 if (info) 2249 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2250 for ( ; image; image=image->next) 2251 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2252 break; 2253 } 2254 default: 2255 { 2256 if (info) 2257 SetImageOption(info->image_info,attribute,SvPV(sval,na)); 2258 for ( ; image; image=image->next) 2259 SetImageProperty(image,attribute,SvPV(sval,na),exception); 2260 break; 2261 } 2262 } 2263 } 2264 2265 /* 2267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2268 % % 2269 % % 2270 % % 2271 % S e t u p L i s t % 2272 % % 2273 % % 2274 % % 2275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2276 % 2277 % Method SetupList returns the list of all the images linked by their 2278 % image->next and image->previous link lists for use with ImageMagick. If 2279 % info is non-NULL, an info structure is returned in *info. If 2280 % reference_vector is non-NULL,an array of SV* are returned in 2281 % *reference_vector. Reference_vector is used when the images are going to be 2282 % replaced with new Image*'s. 2283 % 2284 % The format of the SetupList routine is: 2285 % 2286 % Image *SetupList(SV *reference,struct PackageInfo **info, 2287 % SV ***reference_vector,ExceptionInfo *exception) 2288 % 2289 % A description of each parameter follows: 2290 % 2291 % o list: a list of strings. 2292 % 2293 % o string: a character string. 2294 % 2295 % o exception: Return any errors or warnings in this structure. 2296 % 2297 */ 2298 static Image *SetupList(pTHX_ SV *reference,struct PackageInfo **info, 2299 SV ***reference_vector,ExceptionInfo *exception) 2300 { 2301 Image 2302 *image; 2303 2304 ssize_t 2305 current, 2306 last; 2307 2308 if (reference_vector) 2309 *reference_vector=NULL; 2310 if (info) 2311 *info=NULL; 2312 current=0; 2313 last=0; 2314 image=GetList(aTHX_ reference,reference_vector,¤t,&last,exception); 2315 if (info && (SvTYPE(reference) == SVt_PVAV)) 2316 *info=GetPackageInfo(aTHX_ (void *) reference,(struct PackageInfo *) NULL, 2317 exception); 2318 return(image); 2319 } 2320 2321 /* 2323 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2324 % % 2325 % % 2326 % % 2327 % s t r E Q c a s e % 2328 % % 2329 % % 2330 % % 2331 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2332 % 2333 % strEQcase() compares two strings and returns 0 if they are the 2334 % same or if the second string runs out first. The comparison is case 2335 % insensitive. 2336 % 2337 % The format of the strEQcase routine is: 2338 % 2339 % ssize_t strEQcase(const char *p,const char *q) 2340 % 2341 % A description of each parameter follows: 2342 % 2343 % o p: a character string. 2344 % 2345 % o q: a character string. 2346 % 2347 % 2348 */ 2349 static ssize_t strEQcase(const char *p,const char *q) 2350 { 2351 char 2352 c; 2353 2354 register ssize_t 2355 i; 2356 2357 for (i=0 ; (c=(*q)) != 0; i++) 2358 { 2359 if ((isUPPER((unsigned char) c) ? toLOWER(c) : c) != 2360 (isUPPER((unsigned char) *p) ? toLOWER(*p) : *p)) 2361 return(0); 2362 p++; 2363 q++; 2364 } 2365 return(((*q == 0) && (*p == 0)) ? i : 0); 2366 } 2367 2368 /* 2370 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2371 % % 2372 % % 2373 % % 2374 % I m a g e : : M a g i c k % 2375 % % 2376 % % 2377 % % 2378 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 2379 % 2380 % 2381 */ 2382 MODULE = Image::Magick::@MAGICK_ABI_SUFFIX@ PACKAGE = Image::Magick::@MAGICK_ABI_SUFFIX@ 2383 2384 PROTOTYPES: ENABLE 2385 2386 BOOT: 2387 MagickCoreGenesis("PerlMagick",MagickFalse); 2388 SetWarningHandler(NULL); 2389 SetErrorHandler(NULL); 2390 magick_registry=NewSplayTree((int (*)(const void *,const void *)) 2391 NULL,(void *(*)(void *)) NULL,(void *(*)(void *)) NULL); 2392 2393 void 2394 UNLOAD() 2395 PPCODE: 2396 { 2397 if (magick_registry != (SplayTreeInfo *) NULL) 2398 magick_registry=DestroySplayTree(magick_registry); 2399 MagickCoreTerminus(); 2400 } 2401 2402 double 2403 constant(name,argument) 2404 char *name 2405 ssize_t argument 2406 2407 # 2409 ############################################################################### 2410 # # 2411 # # 2412 # # 2413 # A n i m a t e # 2414 # # 2415 # # 2416 # # 2417 ############################################################################### 2418 # 2419 # 2420 void 2421 Animate(ref,...) 2422 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 2423 ALIAS: 2424 AnimateImage = 1 2425 animate = 2 2426 animateimage = 3 2427 PPCODE: 2428 { 2429 ExceptionInfo 2430 *exception; 2431 2432 Image 2433 *image; 2434 2435 register ssize_t 2436 i; 2437 2438 struct PackageInfo 2439 *info, 2440 *package_info; 2441 2442 SV 2443 *perl_exception, 2444 *reference; 2445 2446 PERL_UNUSED_VAR(ref); 2447 PERL_UNUSED_VAR(ix); 2448 exception=AcquireExceptionInfo(); 2449 perl_exception=newSVpv("",0); 2450 package_info=(struct PackageInfo *) NULL; 2451 if (sv_isobject(ST(0)) == 0) 2452 { 2453 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2454 PackageName); 2455 goto PerlException; 2456 } 2457 reference=SvRV(ST(0)); 2458 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 2459 if (image == (Image *) NULL) 2460 { 2461 ThrowPerlException(exception,OptionError,"NoImagesDefined", 2462 PackageName); 2463 goto PerlException; 2464 } 2465 package_info=ClonePackageInfo(info,exception); 2466 if (items == 2) 2467 SetAttribute(aTHX_ package_info,NULL,"server",ST(1),exception); 2468 else 2469 if (items > 2) 2470 for (i=2; i < items; i+=2) 2471 SetAttribute(aTHX_ package_info,image,SvPV(ST(i-1),na),ST(i), 2472 exception); 2473 (void) AnimateImages(package_info->image_info,image,exception); 2474 (void) CatchImageException(image); 2475 2476 PerlException: 2477 if (package_info != (struct PackageInfo *) NULL) 2478 DestroyPackageInfo(package_info); 2479 InheritPerlException(exception,perl_exception); 2480 exception=DestroyExceptionInfo(exception); 2481 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 2482 SvPOK_on(perl_exception); 2483 ST(0)=sv_2mortal(perl_exception); 2484 XSRETURN(1); 2485 } 2486 2487 # 2489 ############################################################################### 2490 # # 2491 # # 2492 # # 2493 # A p p e n d # 2494 # # 2495 # # 2496 # # 2497 ############################################################################### 2498 # 2499 # 2500 void 2501 Append(ref,...) 2502 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 2503 ALIAS: 2504 AppendImage = 1 2505 append = 2 2506 appendimage = 3 2507 PPCODE: 2508 { 2509 AV 2510 *av; 2511 2512 char 2513 *attribute; 2514 2515 ExceptionInfo 2516 *exception; 2517 2518 HV 2519 *hv; 2520 2521 Image 2522 *image; 2523 2524 register ssize_t 2525 i; 2526 2527 ssize_t 2528 stack; 2529 2530 struct PackageInfo 2531 *info; 2532 2533 SV 2534 *av_reference, 2535 *perl_exception, 2536 *reference, 2537 *rv, 2538 *sv; 2539 2540 PERL_UNUSED_VAR(ref); 2541 PERL_UNUSED_VAR(ix); 2542 exception=AcquireExceptionInfo(); 2543 perl_exception=newSVpv("",0); 2544 sv=NULL; 2545 attribute=NULL; 2546 av=NULL; 2547 if (sv_isobject(ST(0)) == 0) 2548 { 2549 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2550 PackageName); 2551 goto PerlException; 2552 } 2553 reference=SvRV(ST(0)); 2554 hv=SvSTASH(reference); 2555 av=newAV(); 2556 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 2557 SvREFCNT_dec(av); 2558 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 2559 if (image == (Image *) NULL) 2560 { 2561 ThrowPerlException(exception,OptionError,"NoImagesDefined", 2562 PackageName); 2563 goto PerlException; 2564 } 2565 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 2566 /* 2567 Get options. 2568 */ 2569 stack=MagickTrue; 2570 for (i=2; i < items; i+=2) 2571 { 2572 attribute=(char *) SvPV(ST(i-1),na); 2573 switch (*attribute) 2574 { 2575 case 'S': 2576 case 's': 2577 { 2578 if (LocaleCompare(attribute,"stack") == 0) 2579 { 2580 stack=ParseCommandOption(MagickBooleanOptions,MagickFalse, 2581 SvPV(ST(i),na)); 2582 if (stack < 0) 2583 { 2584 ThrowPerlException(exception,OptionError,"UnrecognizedType", 2585 SvPV(ST(i),na)); 2586 return; 2587 } 2588 break; 2589 } 2590 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 2591 attribute); 2592 break; 2593 } 2594 default: 2595 { 2596 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 2597 attribute); 2598 break; 2599 } 2600 } 2601 } 2602 image=AppendImages(image,stack != 0 ? MagickTrue : MagickFalse,exception); 2603 if (image == (Image *) NULL) 2604 goto PerlException; 2605 for ( ; image; image=image->next) 2606 { 2607 AddImageToRegistry(sv,image); 2608 rv=newRV(sv); 2609 av_push(av,sv_bless(rv,hv)); 2610 SvREFCNT_dec(sv); 2611 } 2612 exception=DestroyExceptionInfo(exception); 2613 ST(0)=av_reference; 2614 SvREFCNT_dec(perl_exception); 2615 XSRETURN(1); 2616 2617 PerlException: 2618 InheritPerlException(exception,perl_exception); 2619 exception=DestroyExceptionInfo(exception); 2620 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 2621 SvPOK_on(perl_exception); 2622 ST(0)=sv_2mortal(perl_exception); 2623 XSRETURN(1); 2624 } 2625 2626 # 2628 ############################################################################### 2629 # # 2630 # # 2631 # # 2632 # A v e r a g e # 2633 # # 2634 # # 2635 # # 2636 ############################################################################### 2637 # 2638 # 2639 void 2640 Average(ref) 2641 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 2642 ALIAS: 2643 AverageImage = 1 2644 average = 2 2645 averageimage = 3 2646 PPCODE: 2647 { 2648 AV 2649 *av; 2650 2651 char 2652 *p; 2653 2654 ExceptionInfo 2655 *exception; 2656 2657 HV 2658 *hv; 2659 2660 Image 2661 *image; 2662 2663 struct PackageInfo 2664 *info; 2665 2666 SV 2667 *perl_exception, 2668 *reference, 2669 *rv, 2670 *sv; 2671 2672 PERL_UNUSED_VAR(ref); 2673 PERL_UNUSED_VAR(ix); 2674 exception=AcquireExceptionInfo(); 2675 perl_exception=newSVpv("",0); 2676 sv=NULL; 2677 if (sv_isobject(ST(0)) == 0) 2678 { 2679 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2680 PackageName); 2681 goto PerlException; 2682 } 2683 reference=SvRV(ST(0)); 2684 hv=SvSTASH(reference); 2685 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 2686 if (image == (Image *) NULL) 2687 { 2688 ThrowPerlException(exception,OptionError,"NoImagesDefined", 2689 PackageName); 2690 goto PerlException; 2691 } 2692 image=EvaluateImages(image,MeanEvaluateOperator,exception); 2693 if (image == (Image *) NULL) 2694 goto PerlException; 2695 /* 2696 Create blessed Perl array for the returned image. 2697 */ 2698 av=newAV(); 2699 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 2700 SvREFCNT_dec(av); 2701 AddImageToRegistry(sv,image); 2702 rv=newRV(sv); 2703 av_push(av,sv_bless(rv,hv)); 2704 SvREFCNT_dec(sv); 2705 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 2706 (void) FormatLocaleString(info->image_info->filename,MagickPathExtent, 2707 "average-%.*s",(int) (MagickPathExtent-9), 2708 ((p=strrchr(image->filename,'/')) ? p+1 : image->filename)); 2709 (void) CopyMagickString(image->filename,info->image_info->filename, 2710 MagickPathExtent); 2711 SetImageInfo(info->image_info,0,exception); 2712 exception=DestroyExceptionInfo(exception); 2713 SvREFCNT_dec(perl_exception); 2714 XSRETURN(1); 2715 2716 PerlException: 2717 InheritPerlException(exception,perl_exception); 2718 exception=DestroyExceptionInfo(exception); 2719 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 2720 SvPOK_on(perl_exception); 2721 ST(0)=sv_2mortal(perl_exception); 2722 XSRETURN(1); 2723 } 2724 2725 # 2727 ############################################################################### 2728 # # 2729 # # 2730 # # 2731 # B l o b T o I m a g e # 2732 # # 2733 # # 2734 # # 2735 ############################################################################### 2736 # 2737 # 2738 void 2739 BlobToImage(ref,...) 2740 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 2741 ALIAS: 2742 BlobToImage = 1 2743 blobtoimage = 2 2744 blobto = 3 2745 PPCODE: 2746 { 2747 AV 2748 *av; 2749 2750 char 2751 **keep, 2752 **list; 2753 2754 ExceptionInfo 2755 *exception; 2756 2757 HV 2758 *hv; 2759 2760 Image 2761 *image; 2762 2763 register char 2764 **p; 2765 2766 register ssize_t 2767 i; 2768 2769 ssize_t 2770 ac, 2771 n, 2772 number_images; 2773 2774 STRLEN 2775 *length; 2776 2777 struct PackageInfo 2778 *info; 2779 2780 SV 2781 *perl_exception, 2782 *reference, 2783 *rv, 2784 *sv; 2785 2786 PERL_UNUSED_VAR(ref); 2787 PERL_UNUSED_VAR(ix); 2788 exception=AcquireExceptionInfo(); 2789 perl_exception=newSVpv("",0); 2790 sv=NULL; 2791 number_images=0; 2792 ac=(items < 2) ? 1 : items-1; 2793 length=(STRLEN *) NULL; 2794 list=(char **) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*list)); 2795 if (list == (char **) NULL) 2796 { 2797 ThrowPerlException(exception,ResourceLimitError, 2798 "MemoryAllocationFailed",PackageName); 2799 goto PerlException; 2800 } 2801 length=(STRLEN *) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*length)); 2802 if (length == (STRLEN *) NULL) 2803 { 2804 ThrowPerlException(exception,ResourceLimitError, 2805 "MemoryAllocationFailed",PackageName); 2806 goto PerlException; 2807 } 2808 if (sv_isobject(ST(0)) == 0) 2809 { 2810 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2811 PackageName); 2812 goto PerlException; 2813 } 2814 reference=SvRV(ST(0)); 2815 hv=SvSTASH(reference); 2816 if (SvTYPE(reference) != SVt_PVAV) 2817 { 2818 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2819 PackageName); 2820 goto PerlException; 2821 } 2822 av=(AV *) reference; 2823 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 2824 exception); 2825 n=1; 2826 if (items <= 1) 2827 { 2828 ThrowPerlException(exception,OptionError,"NoBlobDefined",PackageName); 2829 goto PerlException; 2830 } 2831 for (n=0, i=0; i < ac; i++) 2832 { 2833 list[n]=(char *) (SvPV(ST(i+1),length[n])); 2834 if ((items >= 3) && strEQcase((char *) SvPV(ST(i+1),na),"blob")) 2835 { 2836 list[n]=(char *) (SvPV(ST(i+2),length[n])); 2837 continue; 2838 } 2839 n++; 2840 } 2841 list[n]=(char *) NULL; 2842 keep=list; 2843 for (i=number_images=0; i < n; i++) 2844 { 2845 image=BlobToImage(info->image_info,list[i],length[i],exception); 2846 if (image == (Image *) NULL) 2847 break; 2848 for ( ; image; image=image->next) 2849 { 2850 AddImageToRegistry(sv,image); 2851 rv=newRV(sv); 2852 av_push(av,sv_bless(rv,hv)); 2853 SvREFCNT_dec(sv); 2854 number_images++; 2855 } 2856 } 2857 /* 2858 Free resources. 2859 */ 2860 for (i=0; i < n; i++) 2861 if (list[i] != (char *) NULL) 2862 for (p=keep; list[i] != *p++; ) 2863 if (*p == (char *) NULL) 2864 { 2865 list[i]=(char *) RelinquishMagickMemory(list[i]); 2866 break; 2867 } 2868 2869 PerlException: 2870 if (list) 2871 list=(char **) RelinquishMagickMemory(list); 2872 if (length) 2873 length=(STRLEN *) RelinquishMagickMemory(length); 2874 InheritPerlException(exception,perl_exception); 2875 exception=DestroyExceptionInfo(exception); 2876 sv_setiv(perl_exception,(IV) number_images); 2877 SvPOK_on(perl_exception); 2878 ST(0)=sv_2mortal(perl_exception); 2879 XSRETURN(1); 2880 } 2881 2882 # 2884 ############################################################################### 2885 # # 2886 # # 2887 # # 2888 # C h a n n e l F x # 2889 # # 2890 # # 2891 # # 2892 ############################################################################### 2893 # 2894 # 2895 void 2896 ChannelFx(ref,...) 2897 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 2898 ALIAS: 2899 ChannelFxImage = 1 2900 channelfx = 2 2901 channelfximage = 3 2902 PPCODE: 2903 { 2904 AV 2905 *av; 2906 2907 char 2908 *attribute, 2909 expression[MagickPathExtent]; 2910 2911 ChannelType 2912 channel, 2913 channel_mask; 2914 2915 ExceptionInfo 2916 *exception; 2917 2918 HV 2919 *hv; 2920 2921 Image 2922 *image; 2923 2924 register ssize_t 2925 i; 2926 2927 struct PackageInfo 2928 *info; 2929 2930 SV 2931 *av_reference, 2932 *perl_exception, 2933 *reference, 2934 *rv, 2935 *sv; 2936 2937 PERL_UNUSED_VAR(ref); 2938 PERL_UNUSED_VAR(ix); 2939 exception=AcquireExceptionInfo(); 2940 perl_exception=newSVpv("",0); 2941 sv=NULL; 2942 attribute=NULL; 2943 av=NULL; 2944 if (sv_isobject(ST(0)) == 0) 2945 { 2946 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 2947 PackageName); 2948 goto PerlException; 2949 } 2950 reference=SvRV(ST(0)); 2951 hv=SvSTASH(reference); 2952 av=newAV(); 2953 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 2954 SvREFCNT_dec(av); 2955 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 2956 if (image == (Image *) NULL) 2957 { 2958 ThrowPerlException(exception,OptionError,"NoImagesDefined", 2959 PackageName); 2960 goto PerlException; 2961 } 2962 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 2963 /* 2964 Get options. 2965 */ 2966 channel=DefaultChannels; 2967 (void) CopyMagickString(expression,"u",MagickPathExtent); 2968 if (items == 2) 2969 (void) CopyMagickString(expression,(char *) SvPV(ST(1),na),MagickPathExtent); 2970 else 2971 for (i=2; i < items; i+=2) 2972 { 2973 attribute=(char *) SvPV(ST(i-1),na); 2974 switch (*attribute) 2975 { 2976 case 'C': 2977 case 'c': 2978 { 2979 if (LocaleCompare(attribute,"channel") == 0) 2980 { 2981 ssize_t 2982 option; 2983 2984 option=ParseChannelOption(SvPV(ST(i),na)); 2985 if (option < 0) 2986 { 2987 ThrowPerlException(exception,OptionError, 2988 "UnrecognizedType",SvPV(ST(i),na)); 2989 return; 2990 } 2991 channel=(ChannelType) option; 2992 break; 2993 } 2994 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 2995 attribute); 2996 break; 2997 } 2998 case 'E': 2999 case 'e': 3000 { 3001 if (LocaleCompare(attribute,"expression") == 0) 3002 { 3003 (void) CopyMagickString(expression,SvPV(ST(i),na), 3004 MagickPathExtent); 3005 break; 3006 } 3007 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3008 attribute); 3009 break; 3010 } 3011 default: 3012 { 3013 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3014 attribute); 3015 break; 3016 } 3017 } 3018 } 3019 channel_mask=SetImageChannelMask(image,channel); 3020 image=ChannelFxImage(image,expression,exception); 3021 if (image != (Image *) NULL) 3022 (void) SetImageChannelMask(image,channel_mask); 3023 if (image == (Image *) NULL) 3024 goto PerlException; 3025 for ( ; image; image=image->next) 3026 { 3027 AddImageToRegistry(sv,image); 3028 rv=newRV(sv); 3029 av_push(av,sv_bless(rv,hv)); 3030 SvREFCNT_dec(sv); 3031 } 3032 exception=DestroyExceptionInfo(exception); 3033 ST(0)=av_reference; 3034 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 3035 XSRETURN(1); 3036 3037 PerlException: 3038 InheritPerlException(exception,perl_exception); 3039 exception=DestroyExceptionInfo(exception); 3040 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3041 SvPOK_on(perl_exception); 3042 ST(0)=sv_2mortal(perl_exception); 3043 XSRETURN(1); 3044 } 3045 3046 # 3048 ############################################################################### 3049 # # 3050 # # 3051 # # 3052 # C l o n e # 3053 # # 3054 # # 3055 # # 3056 ############################################################################### 3057 # 3058 # 3059 void 3060 Clone(ref) 3061 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3062 ALIAS: 3063 CopyImage = 1 3064 copy = 2 3065 copyimage = 3 3066 CloneImage = 4 3067 clone = 5 3068 cloneimage = 6 3069 Clone = 7 3070 PPCODE: 3071 { 3072 AV 3073 *av; 3074 3075 ExceptionInfo 3076 *exception; 3077 3078 HV 3079 *hv; 3080 3081 Image 3082 *clone, 3083 *image; 3084 3085 struct PackageInfo 3086 *info; 3087 3088 SV 3089 *perl_exception, 3090 *reference, 3091 *rv, 3092 *sv; 3093 3094 PERL_UNUSED_VAR(ref); 3095 PERL_UNUSED_VAR(ix); 3096 exception=AcquireExceptionInfo(); 3097 perl_exception=newSVpv("",0); 3098 sv=NULL; 3099 if (sv_isobject(ST(0)) == 0) 3100 { 3101 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3102 PackageName); 3103 goto PerlException; 3104 } 3105 reference=SvRV(ST(0)); 3106 hv=SvSTASH(reference); 3107 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3108 if (image == (Image *) NULL) 3109 { 3110 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3111 PackageName); 3112 goto PerlException; 3113 } 3114 /* 3115 Create blessed Perl array for the returned image. 3116 */ 3117 av=newAV(); 3118 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 3119 SvREFCNT_dec(av); 3120 for ( ; image; image=image->next) 3121 { 3122 clone=CloneImage(image,0,0,MagickTrue,exception); 3123 if (clone == (Image *) NULL) 3124 break; 3125 AddImageToRegistry(sv,clone); 3126 rv=newRV(sv); 3127 av_push(av,sv_bless(rv,hv)); 3128 SvREFCNT_dec(sv); 3129 } 3130 exception=DestroyExceptionInfo(exception); 3131 SvREFCNT_dec(perl_exception); 3132 XSRETURN(1); 3133 3134 PerlException: 3135 InheritPerlException(exception,perl_exception); 3136 exception=DestroyExceptionInfo(exception); 3137 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3138 SvPOK_on(perl_exception); 3139 ST(0)=sv_2mortal(perl_exception); 3140 XSRETURN(1); 3141 } 3142 3143 # 3145 ############################################################################### 3146 # # 3147 # # 3148 # # 3149 # C L O N E # 3150 # # 3151 # # 3152 # # 3153 ############################################################################### 3154 # 3155 # 3156 void 3157 CLONE(ref,...) 3158 SV *ref; 3159 CODE: 3160 { 3161 PERL_UNUSED_VAR(ref); 3162 if (magick_registry != (SplayTreeInfo *) NULL) 3163 { 3164 register Image 3165 *p; 3166 3167 ResetSplayTreeIterator(magick_registry); 3168 p=(Image *) GetNextKeyInSplayTree(magick_registry); 3169 while (p != (Image *) NULL) 3170 { 3171 ReferenceImage(p); 3172 p=(Image *) GetNextKeyInSplayTree(magick_registry); 3173 } 3174 } 3175 } 3176 3177 # 3179 ############################################################################### 3180 # # 3181 # # 3182 # # 3183 # C o a l e s c e # 3184 # # 3185 # # 3186 # # 3187 ############################################################################### 3188 # 3189 # 3190 void 3191 Coalesce(ref) 3192 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3193 ALIAS: 3194 CoalesceImage = 1 3195 coalesce = 2 3196 coalesceimage = 3 3197 PPCODE: 3198 { 3199 AV 3200 *av; 3201 3202 ExceptionInfo 3203 *exception; 3204 3205 HV 3206 *hv; 3207 3208 Image 3209 *image; 3210 3211 struct PackageInfo 3212 *info; 3213 3214 SV 3215 *av_reference, 3216 *perl_exception, 3217 *reference, 3218 *rv, 3219 *sv; 3220 3221 PERL_UNUSED_VAR(ref); 3222 PERL_UNUSED_VAR(ix); 3223 exception=AcquireExceptionInfo(); 3224 perl_exception=newSVpv("",0); 3225 sv=NULL; 3226 if (sv_isobject(ST(0)) == 0) 3227 { 3228 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3229 PackageName); 3230 goto PerlException; 3231 } 3232 reference=SvRV(ST(0)); 3233 hv=SvSTASH(reference); 3234 av=newAV(); 3235 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 3236 SvREFCNT_dec(av); 3237 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3238 if (image == (Image *) NULL) 3239 { 3240 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3241 PackageName); 3242 goto PerlException; 3243 } 3244 image=CoalesceImages(image,exception); 3245 if (image == (Image *) NULL) 3246 goto PerlException; 3247 for ( ; image; image=image->next) 3248 { 3249 AddImageToRegistry(sv,image); 3250 rv=newRV(sv); 3251 av_push(av,sv_bless(rv,hv)); 3252 SvREFCNT_dec(sv); 3253 } 3254 exception=DestroyExceptionInfo(exception); 3255 ST(0)=av_reference; 3256 SvREFCNT_dec(perl_exception); 3257 XSRETURN(1); 3258 3259 PerlException: 3260 InheritPerlException(exception,perl_exception); 3261 exception=DestroyExceptionInfo(exception); 3262 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3263 SvPOK_on(perl_exception); 3264 ST(0)=sv_2mortal(perl_exception); 3265 XSRETURN(1); 3266 } 3267 3268 # 3270 ############################################################################### 3271 # # 3272 # # 3273 # # 3274 # C o m p a r e # 3275 # # 3276 # # 3277 # # 3278 ############################################################################### 3279 # 3280 # 3281 void 3282 Compare(ref,...) 3283 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3284 ALIAS: 3285 CompareImages = 1 3286 compare = 2 3287 compareimage = 3 3288 PPCODE: 3289 { 3290 AV 3291 *av; 3292 3293 char 3294 *attribute; 3295 3296 double 3297 distortion; 3298 3299 ExceptionInfo 3300 *exception; 3301 3302 HV 3303 *hv; 3304 3305 Image 3306 *difference_image, 3307 *image, 3308 *reconstruct_image; 3309 3310 MetricType 3311 metric; 3312 3313 register ssize_t 3314 i; 3315 3316 ssize_t 3317 option; 3318 3319 struct PackageInfo 3320 *info; 3321 3322 SV 3323 *av_reference, 3324 *perl_exception, 3325 *reference, 3326 *rv, 3327 *sv; 3328 3329 PERL_UNUSED_VAR(ref); 3330 PERL_UNUSED_VAR(ix); 3331 exception=AcquireExceptionInfo(); 3332 perl_exception=newSVpv("",0); 3333 sv=NULL; 3334 av=NULL; 3335 attribute=NULL; 3336 if (sv_isobject(ST(0)) == 0) 3337 { 3338 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3339 PackageName); 3340 goto PerlException; 3341 } 3342 reference=SvRV(ST(0)); 3343 hv=SvSTASH(reference); 3344 av=newAV(); 3345 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 3346 SvREFCNT_dec(av); 3347 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3348 if (image == (Image *) NULL) 3349 { 3350 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3351 PackageName); 3352 goto PerlException; 3353 } 3354 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 3355 /* 3356 Get attribute. 3357 */ 3358 reconstruct_image=image; 3359 metric=RootMeanSquaredErrorMetric; 3360 for (i=2; i < items; i+=2) 3361 { 3362 attribute=(char *) SvPV(ST(i-1),na); 3363 switch (*attribute) 3364 { 3365 case 'C': 3366 case 'c': 3367 { 3368 if (LocaleCompare(attribute,"channel") == 0) 3369 { 3370 ssize_t 3371 option; 3372 3373 option=ParseChannelOption(SvPV(ST(i),na)); 3374 if (option < 0) 3375 { 3376 ThrowPerlException(exception,OptionError, 3377 "UnrecognizedType",SvPV(ST(i),na)); 3378 return; 3379 } 3380 (void) SetPixelChannelMask(image,(ChannelType) option); 3381 break; 3382 } 3383 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3384 attribute); 3385 break; 3386 } 3387 case 'F': 3388 case 'f': 3389 { 3390 if (LocaleCompare(attribute,"fuzz") == 0) 3391 { 3392 image->fuzz=StringToDoubleInterval(SvPV(ST(i),na),100.0); 3393 break; 3394 } 3395 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3396 attribute); 3397 break; 3398 } 3399 case 'I': 3400 case 'i': 3401 { 3402 if (LocaleCompare(attribute,"image") == 0) 3403 { 3404 reconstruct_image=SetupList(aTHX_ SvRV(ST(i)), 3405 (struct PackageInfo **) NULL,(SV ***) NULL,exception); 3406 break; 3407 } 3408 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3409 attribute); 3410 break; 3411 } 3412 case 'M': 3413 case 'm': 3414 { 3415 if (LocaleCompare(attribute,"metric") == 0) 3416 { 3417 option=ParseCommandOption(MagickMetricOptions,MagickFalse, 3418 SvPV(ST(i),na)); 3419 if (option < 0) 3420 { 3421 ThrowPerlException(exception,OptionError,"UnrecognizedType", 3422 SvPV(ST(i),na)); 3423 break; 3424 } 3425 metric=(MetricType) option; 3426 break; 3427 } 3428 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3429 attribute); 3430 break; 3431 } 3432 default: 3433 { 3434 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3435 attribute); 3436 break; 3437 } 3438 } 3439 } 3440 difference_image=CompareImages(image,reconstruct_image,metric,&distortion, 3441 exception); 3442 if (difference_image != (Image *) NULL) 3443 { 3444 difference_image->error.mean_error_per_pixel=distortion; 3445 AddImageToRegistry(sv,difference_image); 3446 rv=newRV(sv); 3447 av_push(av,sv_bless(rv,hv)); 3448 SvREFCNT_dec(sv); 3449 } 3450 exception=DestroyExceptionInfo(exception); 3451 ST(0)=av_reference; 3452 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 3453 XSRETURN(1); 3454 3455 PerlException: 3456 InheritPerlException(exception,perl_exception); 3457 exception=DestroyExceptionInfo(exception); 3458 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3459 SvPOK_on(perl_exception); 3460 ST(0)=sv_2mortal(perl_exception); 3461 XSRETURN(1); 3462 } 3463 3464 # 3466 ############################################################################### 3467 # # 3468 # # 3469 # # 3470 # C o m p l e x I m a g e s # 3471 # # 3472 # # 3473 # # 3474 ############################################################################### 3475 # 3476 # 3477 void 3478 ComplexImages(ref) 3479 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3480 ALIAS: 3481 ComplexImages = 1 3482 compleximages = 2 3483 PPCODE: 3484 { 3485 AV 3486 *av; 3487 3488 char 3489 *attribute, 3490 *p; 3491 3492 ComplexOperator 3493 op; 3494 3495 ExceptionInfo 3496 *exception; 3497 3498 HV 3499 *hv; 3500 3501 Image 3502 *image; 3503 3504 register ssize_t 3505 i; 3506 3507 struct PackageInfo 3508 *info; 3509 3510 SV 3511 *perl_exception, 3512 *reference, 3513 *rv, 3514 *sv; 3515 3516 PERL_UNUSED_VAR(ref); 3517 PERL_UNUSED_VAR(ix); 3518 exception=AcquireExceptionInfo(); 3519 perl_exception=newSVpv("",0); 3520 sv=NULL; 3521 if (sv_isobject(ST(0)) == 0) 3522 { 3523 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3524 PackageName); 3525 goto PerlException; 3526 } 3527 reference=SvRV(ST(0)); 3528 hv=SvSTASH(reference); 3529 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3530 if (image == (Image *) NULL) 3531 { 3532 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3533 PackageName); 3534 goto PerlException; 3535 } 3536 op=UndefinedComplexOperator; 3537 if (items == 2) 3538 { 3539 ssize_t 3540 in; 3541 3542 in=ParseCommandOption(MagickComplexOptions,MagickFalse,(char *) 3543 SvPV(ST(1),na)); 3544 if (in < 0) 3545 { 3546 ThrowPerlException(exception,OptionError,"UnrecognizedType", 3547 SvPV(ST(1),na)); 3548 return; 3549 } 3550 op=(ComplexOperator) in; 3551 } 3552 else 3553 for (i=2; i < items; i+=2) 3554 { 3555 attribute=(char *) SvPV(ST(i-1),na); 3556 switch (*attribute) 3557 { 3558 case 'O': 3559 case 'o': 3560 { 3561 if (LocaleCompare(attribute,"operator") == 0) 3562 { 3563 ssize_t 3564 in; 3565 3566 in=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 3567 MagickComplexOptions,MagickFalse,SvPV(ST(i),na)); 3568 if (in < 0) 3569 { 3570 ThrowPerlException(exception,OptionError,"UnrecognizedType", 3571 SvPV(ST(i),na)); 3572 return; 3573 } 3574 op=(ComplexOperator) in; 3575 break; 3576 } 3577 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3578 attribute); 3579 break; 3580 } 3581 default: 3582 { 3583 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3584 attribute); 3585 break; 3586 } 3587 } 3588 } 3589 image=ComplexImages(image,op,exception); 3590 if (image == (Image *) NULL) 3591 goto PerlException; 3592 /* 3593 Create blessed Perl array for the returned image. 3594 */ 3595 av=newAV(); 3596 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 3597 SvREFCNT_dec(av); 3598 AddImageToRegistry(sv,image); 3599 rv=newRV(sv); 3600 av_push(av,sv_bless(rv,hv)); 3601 SvREFCNT_dec(sv); 3602 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 3603 (void) FormatLocaleString(info->image_info->filename,MagickPathExtent, 3604 "complex-%.*s",(int) (MagickPathExtent-9), 3605 ((p=strrchr(image->filename,'/')) ? p+1 : image->filename)); 3606 (void) CopyMagickString(image->filename,info->image_info->filename, 3607 MagickPathExtent); 3608 SetImageInfo(info->image_info,0,exception); 3609 exception=DestroyExceptionInfo(exception); 3610 SvREFCNT_dec(perl_exception); 3611 XSRETURN(1); 3612 3613 PerlException: 3614 InheritPerlException(exception,perl_exception); 3615 exception=DestroyExceptionInfo(exception); 3616 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3617 SvPOK_on(perl_exception); 3618 ST(0)=sv_2mortal(perl_exception); 3619 XSRETURN(1); 3620 } 3621 3622 # 3624 ############################################################################### 3625 # # 3626 # # 3627 # # 3628 # C o m p a r e L a y e r s # 3629 # # 3630 # # 3631 # # 3632 ############################################################################### 3633 # 3634 # 3635 void 3636 CompareLayers(ref) 3637 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3638 ALIAS: 3639 CompareImagesLayers = 1 3640 comparelayers = 2 3641 compareimagelayers = 3 3642 PPCODE: 3643 { 3644 AV 3645 *av; 3646 3647 char 3648 *attribute; 3649 3650 ExceptionInfo 3651 *exception; 3652 3653 HV 3654 *hv; 3655 3656 Image 3657 *image; 3658 3659 LayerMethod 3660 method; 3661 3662 register ssize_t 3663 i; 3664 3665 ssize_t 3666 option; 3667 3668 struct PackageInfo 3669 *info; 3670 3671 SV 3672 *av_reference, 3673 *perl_exception, 3674 *reference, 3675 *rv, 3676 *sv; 3677 3678 PERL_UNUSED_VAR(ref); 3679 PERL_UNUSED_VAR(ix); 3680 exception=AcquireExceptionInfo(); 3681 perl_exception=newSVpv("",0); 3682 sv=NULL; 3683 if (sv_isobject(ST(0)) == 0) 3684 { 3685 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3686 PackageName); 3687 goto PerlException; 3688 } 3689 reference=SvRV(ST(0)); 3690 hv=SvSTASH(reference); 3691 av=newAV(); 3692 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 3693 SvREFCNT_dec(av); 3694 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3695 if (image == (Image *) NULL) 3696 { 3697 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3698 PackageName); 3699 goto PerlException; 3700 } 3701 method=CompareAnyLayer; 3702 for (i=2; i < items; i+=2) 3703 { 3704 attribute=(char *) SvPV(ST(i-1),na); 3705 switch (*attribute) 3706 { 3707 case 'M': 3708 case 'm': 3709 { 3710 if (LocaleCompare(attribute,"method") == 0) 3711 { 3712 option=ParseCommandOption(MagickLayerOptions,MagickFalse, 3713 SvPV(ST(i),na)); 3714 if (option < 0) 3715 { 3716 ThrowPerlException(exception,OptionError,"UnrecognizedType", 3717 SvPV(ST(i),na)); 3718 break; 3719 } 3720 method=(LayerMethod) option; 3721 break; 3722 } 3723 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3724 attribute); 3725 break; 3726 } 3727 default: 3728 { 3729 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 3730 attribute); 3731 break; 3732 } 3733 } 3734 } 3735 image=CompareImagesLayers(image,method,exception); 3736 if (image == (Image *) NULL) 3737 goto PerlException; 3738 for ( ; image; image=image->next) 3739 { 3740 AddImageToRegistry(sv,image); 3741 rv=newRV(sv); 3742 av_push(av,sv_bless(rv,hv)); 3743 SvREFCNT_dec(sv); 3744 } 3745 exception=DestroyExceptionInfo(exception); 3746 ST(0)=av_reference; 3747 SvREFCNT_dec(perl_exception); 3748 XSRETURN(1); 3749 3750 PerlException: 3751 InheritPerlException(exception,perl_exception); 3752 exception=DestroyExceptionInfo(exception); 3753 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3754 SvPOK_on(perl_exception); 3755 ST(0)=sv_2mortal(perl_exception); 3756 XSRETURN(1); 3757 } 3758 3759 # 3761 ############################################################################### 3762 # # 3763 # # 3764 # # 3765 # D e s t r o y # 3766 # # 3767 # # 3768 # # 3769 ############################################################################### 3770 # 3771 # 3772 void 3773 DESTROY(ref) 3774 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3775 PPCODE: 3776 { 3777 SV 3778 *reference; 3779 3780 PERL_UNUSED_VAR(ref); 3781 if (sv_isobject(ST(0)) == 0) 3782 croak("ReferenceIsNotMyType"); 3783 reference=SvRV(ST(0)); 3784 switch (SvTYPE(reference)) 3785 { 3786 case SVt_PVAV: 3787 { 3788 char 3789 message[MagickPathExtent]; 3790 3791 const SV 3792 *key; 3793 3794 HV 3795 *hv; 3796 3797 GV 3798 **gvp; 3799 3800 struct PackageInfo 3801 *info; 3802 3803 SV 3804 *sv; 3805 3806 /* 3807 Array (AV *) reference 3808 */ 3809 (void) FormatLocaleString(message,MagickPathExtent,"package%s%p", 3810 XS_VERSION,reference); 3811 hv=gv_stashpv(PackageName, FALSE); 3812 if (!hv) 3813 break; 3814 gvp=(GV **) hv_fetch(hv,message,(long) strlen(message),FALSE); 3815 if (!gvp) 3816 break; 3817 sv=GvSV(*gvp); 3818 if (sv && (SvREFCNT(sv) == 1) && SvIOK(sv)) 3819 { 3820 info=INT2PTR(struct PackageInfo *,SvIV(sv)); 3821 DestroyPackageInfo(info); 3822 } 3823 key=hv_delete(hv,message,(long) strlen(message),G_DISCARD); 3824 (void) key; 3825 break; 3826 } 3827 case SVt_PVMG: 3828 { 3829 Image 3830 *image; 3831 3832 /* 3833 Blessed scalar = (Image *) SvIV(reference) 3834 */ 3835 image=INT2PTR(Image *,SvIV(reference)); 3836 if (image != (Image *) NULL) 3837 DeleteImageFromRegistry(reference,image); 3838 break; 3839 } 3840 default: 3841 break; 3842 } 3843 } 3844 3845 # 3847 ############################################################################### 3848 # # 3849 # # 3850 # # 3851 # D i s p l a y # 3852 # # 3853 # # 3854 # # 3855 ############################################################################### 3856 # 3857 # 3858 void 3859 Display(ref,...) 3860 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3861 ALIAS: 3862 DisplayImage = 1 3863 display = 2 3864 displayimage = 3 3865 PPCODE: 3866 { 3867 ExceptionInfo 3868 *exception; 3869 3870 Image 3871 *image; 3872 3873 register ssize_t 3874 i; 3875 3876 struct PackageInfo 3877 *info, 3878 *package_info; 3879 3880 SV 3881 *perl_exception, 3882 *reference; 3883 3884 PERL_UNUSED_VAR(ref); 3885 PERL_UNUSED_VAR(ix); 3886 exception=AcquireExceptionInfo(); 3887 perl_exception=newSVpv("",0); 3888 package_info=(struct PackageInfo *) NULL; 3889 if (sv_isobject(ST(0)) == 0) 3890 { 3891 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3892 PackageName); 3893 goto PerlException; 3894 } 3895 reference=SvRV(ST(0)); 3896 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3897 if (image == (Image *) NULL) 3898 { 3899 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3900 PackageName); 3901 goto PerlException; 3902 } 3903 package_info=ClonePackageInfo(info,exception); 3904 if (items == 2) 3905 SetAttribute(aTHX_ package_info,NULL,"server",ST(1),exception); 3906 else 3907 if (items > 2) 3908 for (i=2; i < items; i+=2) 3909 SetAttribute(aTHX_ package_info,image,SvPV(ST(i-1),na),ST(i), 3910 exception); 3911 (void) DisplayImages(package_info->image_info,image,exception); 3912 (void) CatchImageException(image); 3913 3914 PerlException: 3915 if (package_info != (struct PackageInfo *) NULL) 3916 DestroyPackageInfo(package_info); 3917 InheritPerlException(exception,perl_exception); 3918 exception=DestroyExceptionInfo(exception); 3919 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 3920 SvPOK_on(perl_exception); 3921 ST(0)=sv_2mortal(perl_exception); 3922 XSRETURN(1); 3923 } 3924 3925 # 3927 ############################################################################### 3928 # # 3929 # # 3930 # # 3931 # E v a l u a t e I m a g e s # 3932 # # 3933 # # 3934 # # 3935 ############################################################################### 3936 # 3937 # 3938 void 3939 EvaluateImages(ref) 3940 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 3941 ALIAS: 3942 EvaluateImages = 1 3943 evaluateimages = 2 3944 PPCODE: 3945 { 3946 AV 3947 *av; 3948 3949 char 3950 *attribute, 3951 *p; 3952 3953 ExceptionInfo 3954 *exception; 3955 3956 HV 3957 *hv; 3958 3959 Image 3960 *image; 3961 3962 MagickEvaluateOperator 3963 op; 3964 3965 register ssize_t 3966 i; 3967 3968 struct PackageInfo 3969 *info; 3970 3971 SV 3972 *perl_exception, 3973 *reference, 3974 *rv, 3975 *sv; 3976 3977 PERL_UNUSED_VAR(ref); 3978 PERL_UNUSED_VAR(ix); 3979 exception=AcquireExceptionInfo(); 3980 perl_exception=newSVpv("",0); 3981 sv=NULL; 3982 if (sv_isobject(ST(0)) == 0) 3983 { 3984 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 3985 PackageName); 3986 goto PerlException; 3987 } 3988 reference=SvRV(ST(0)); 3989 hv=SvSTASH(reference); 3990 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 3991 if (image == (Image *) NULL) 3992 { 3993 ThrowPerlException(exception,OptionError,"NoImagesDefined", 3994 PackageName); 3995 goto PerlException; 3996 } 3997 op=MeanEvaluateOperator; 3998 if (items == 2) 3999 { 4000 ssize_t 4001 in; 4002 4003 in=ParseCommandOption(MagickEvaluateOptions,MagickFalse,(char *) 4004 SvPV(ST(1),na)); 4005 if (in < 0) 4006 { 4007 ThrowPerlException(exception,OptionError,"UnrecognizedType", 4008 SvPV(ST(1),na)); 4009 return; 4010 } 4011 op=(MagickEvaluateOperator) in; 4012 } 4013 else 4014 for (i=2; i < items; i+=2) 4015 { 4016 attribute=(char *) SvPV(ST(i-1),na); 4017 switch (*attribute) 4018 { 4019 case 'O': 4020 case 'o': 4021 { 4022 if (LocaleCompare(attribute,"operator") == 0) 4023 { 4024 ssize_t 4025 in; 4026 4027 in=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 4028 MagickEvaluateOptions,MagickFalse,SvPV(ST(i),na)); 4029 if (in < 0) 4030 { 4031 ThrowPerlException(exception,OptionError,"UnrecognizedType", 4032 SvPV(ST(i),na)); 4033 return; 4034 } 4035 op=(MagickEvaluateOperator) in; 4036 break; 4037 } 4038 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4039 attribute); 4040 break; 4041 } 4042 default: 4043 { 4044 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4045 attribute); 4046 break; 4047 } 4048 } 4049 } 4050 image=EvaluateImages(image,op,exception); 4051 if (image == (Image *) NULL) 4052 goto PerlException; 4053 /* 4054 Create blessed Perl array for the returned image. 4055 */ 4056 av=newAV(); 4057 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 4058 SvREFCNT_dec(av); 4059 AddImageToRegistry(sv,image); 4060 rv=newRV(sv); 4061 av_push(av,sv_bless(rv,hv)); 4062 SvREFCNT_dec(sv); 4063 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 4064 (void) FormatLocaleString(info->image_info->filename,MagickPathExtent, 4065 "evaluate-%.*s",(int) (MagickPathExtent-9), 4066 ((p=strrchr(image->filename,'/')) ? p+1 : image->filename)); 4067 (void) CopyMagickString(image->filename,info->image_info->filename, 4068 MagickPathExtent); 4069 SetImageInfo(info->image_info,0,exception); 4070 exception=DestroyExceptionInfo(exception); 4071 SvREFCNT_dec(perl_exception); 4072 XSRETURN(1); 4073 4074 PerlException: 4075 InheritPerlException(exception,perl_exception); 4076 exception=DestroyExceptionInfo(exception); 4077 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 4078 SvPOK_on(perl_exception); 4079 ST(0)=sv_2mortal(perl_exception); 4080 XSRETURN(1); 4081 } 4082 4083 # 4085 ############################################################################### 4086 # # 4087 # # 4088 # # 4089 # F e a t u r e s # 4090 # # 4091 # # 4092 # # 4093 ############################################################################### 4094 # 4095 # 4096 void 4097 Features(ref,...) 4098 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 4099 ALIAS: 4100 FeaturesImage = 1 4101 features = 2 4102 featuresimage = 3 4103 PPCODE: 4104 { 4105 #define ChannelFeatures(channel,direction) \ 4106 { \ 4107 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4108 channel_features[channel].angular_second_moment[direction]); \ 4109 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4110 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4111 channel_features[channel].contrast[direction]); \ 4112 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4113 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4114 channel_features[channel].contrast[direction]); \ 4115 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4116 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4117 channel_features[channel].variance_sum_of_squares[direction]); \ 4118 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4119 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4120 channel_features[channel].inverse_difference_moment[direction]); \ 4121 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4122 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4123 channel_features[channel].sum_average[direction]); \ 4124 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4125 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4126 channel_features[channel].sum_variance[direction]); \ 4127 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4128 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4129 channel_features[channel].sum_entropy[direction]); \ 4130 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4131 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4132 channel_features[channel].entropy[direction]); \ 4133 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4134 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4135 channel_features[channel].difference_variance[direction]); \ 4136 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4137 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4138 channel_features[channel].difference_entropy[direction]); \ 4139 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4140 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4141 channel_features[channel].measure_of_correlation_1[direction]); \ 4142 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4143 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4144 channel_features[channel].measure_of_correlation_2[direction]); \ 4145 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4146 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 4147 channel_features[channel].maximum_correlation_coefficient[direction]); \ 4148 PUSHs(sv_2mortal(newSVpv(message,0))); \ 4149 } 4150 4151 AV 4152 *av; 4153 4154 char 4155 *attribute, 4156 message[MagickPathExtent]; 4157 4158 ChannelFeatures 4159 *channel_features; 4160 4161 double 4162 distance; 4163 4164 ExceptionInfo 4165 *exception; 4166 4167 Image 4168 *image; 4169 4170 register ssize_t 4171 i; 4172 4173 ssize_t 4174 count; 4175 4176 struct PackageInfo 4177 *info; 4178 4179 SV 4180 *perl_exception, 4181 *reference; 4182 4183 PERL_UNUSED_VAR(ref); 4184 PERL_UNUSED_VAR(ix); 4185 exception=AcquireExceptionInfo(); 4186 perl_exception=newSVpv("",0); 4187 av=NULL; 4188 if (sv_isobject(ST(0)) == 0) 4189 { 4190 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 4191 PackageName); 4192 goto PerlException; 4193 } 4194 reference=SvRV(ST(0)); 4195 av=newAV(); 4196 SvREFCNT_dec(av); 4197 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 4198 if (image == (Image *) NULL) 4199 { 4200 ThrowPerlException(exception,OptionError,"NoImagesDefined", 4201 PackageName); 4202 goto PerlException; 4203 } 4204 distance=1.0; 4205 for (i=2; i < items; i+=2) 4206 { 4207 attribute=(char *) SvPV(ST(i-1),na); 4208 switch (*attribute) 4209 { 4210 case 'D': 4211 case 'd': 4212 { 4213 if (LocaleCompare(attribute,"distance") == 0) 4214 { 4215 distance=StringToLong((char *) SvPV(ST(1),na)); 4216 break; 4217 } 4218 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4219 attribute); 4220 break; 4221 } 4222 default: 4223 { 4224 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4225 attribute); 4226 break; 4227 } 4228 } 4229 } 4230 count=0; 4231 for ( ; image; image=image->next) 4232 { 4233 channel_features=GetImageFeatures(image,distance,exception); 4234 if (channel_features == (ChannelFeatures *) NULL) 4235 continue; 4236 count++; 4237 EXTEND(sp,280*count); 4238 for (i=0; i < 4; i++) 4239 { 4240 ChannelFeatures(RedChannel,i); 4241 ChannelFeatures(GreenChannel,i); 4242 ChannelFeatures(BlueChannel,i); 4243 if (image->colorspace == CMYKColorspace) 4244 ChannelFeatures(BlackChannel,i); 4245 if (image->alpha_trait != UndefinedPixelTrait) 4246 ChannelFeatures(AlphaChannel,i); 4247 } 4248 channel_features=(ChannelFeatures *) 4249 RelinquishMagickMemory(channel_features); 4250 } 4251 4252 PerlException: 4253 InheritPerlException(exception,perl_exception); 4254 exception=DestroyExceptionInfo(exception); 4255 SvREFCNT_dec(perl_exception); 4256 } 4257 4258 # 4260 ############################################################################### 4261 # # 4262 # # 4263 # # 4264 # F l a t t e n # 4265 # # 4266 # # 4267 # # 4268 ############################################################################### 4269 # 4270 # 4271 void 4272 Flatten(ref) 4273 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 4274 ALIAS: 4275 FlattenImage = 1 4276 flatten = 2 4277 flattenimage = 3 4278 PPCODE: 4279 { 4280 AV 4281 *av; 4282 4283 char 4284 *attribute, 4285 *p; 4286 4287 ExceptionInfo 4288 *exception; 4289 4290 HV 4291 *hv; 4292 4293 Image 4294 *image; 4295 4296 PixelInfo 4297 background_color; 4298 4299 register ssize_t 4300 i; 4301 4302 struct PackageInfo 4303 *info; 4304 4305 SV 4306 *perl_exception, 4307 *reference, 4308 *rv, 4309 *sv; 4310 4311 PERL_UNUSED_VAR(ref); 4312 PERL_UNUSED_VAR(ix); 4313 exception=AcquireExceptionInfo(); 4314 perl_exception=newSVpv("",0); 4315 sv=NULL; 4316 if (sv_isobject(ST(0)) == 0) 4317 { 4318 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 4319 PackageName); 4320 goto PerlException; 4321 } 4322 reference=SvRV(ST(0)); 4323 hv=SvSTASH(reference); 4324 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 4325 if (image == (Image *) NULL) 4326 { 4327 ThrowPerlException(exception,OptionError,"NoImagesDefined", 4328 PackageName); 4329 goto PerlException; 4330 } 4331 background_color=image->background_color; 4332 if (items == 2) 4333 (void) QueryColorCompliance((char *) SvPV(ST(1),na),AllCompliance, 4334 &background_color,exception); 4335 else 4336 for (i=2; i < items; i+=2) 4337 { 4338 attribute=(char *) SvPV(ST(i-1),na); 4339 switch (*attribute) 4340 { 4341 case 'B': 4342 case 'b': 4343 { 4344 if (LocaleCompare(attribute,"background") == 0) 4345 { 4346 (void) QueryColorCompliance((char *) SvPV(ST(1),na), 4347 AllCompliance,&background_color,exception); 4348 break; 4349 } 4350 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4351 attribute); 4352 break; 4353 } 4354 default: 4355 { 4356 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4357 attribute); 4358 break; 4359 } 4360 } 4361 } 4362 image->background_color=background_color; 4363 image=MergeImageLayers(image,FlattenLayer,exception); 4364 if (image == (Image *) NULL) 4365 goto PerlException; 4366 /* 4367 Create blessed Perl array for the returned image. 4368 */ 4369 av=newAV(); 4370 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 4371 SvREFCNT_dec(av); 4372 AddImageToRegistry(sv,image); 4373 rv=newRV(sv); 4374 av_push(av,sv_bless(rv,hv)); 4375 SvREFCNT_dec(sv); 4376 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 4377 (void) FormatLocaleString(info->image_info->filename,MagickPathExtent, 4378 "flatten-%.*s",(int) (MagickPathExtent-9), 4379 ((p=strrchr(image->filename,'/')) ? p+1 : image->filename)); 4380 (void) CopyMagickString(image->filename,info->image_info->filename, 4381 MagickPathExtent); 4382 SetImageInfo(info->image_info,0,exception); 4383 exception=DestroyExceptionInfo(exception); 4384 SvREFCNT_dec(perl_exception); 4385 XSRETURN(1); 4386 4387 PerlException: 4388 InheritPerlException(exception,perl_exception); 4389 exception=DestroyExceptionInfo(exception); 4390 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 4391 SvPOK_on(perl_exception); /* return messages in string context */ 4392 ST(0)=sv_2mortal(perl_exception); 4393 XSRETURN(1); 4394 } 4395 4396 # 4398 ############################################################################### 4399 # # 4400 # # 4401 # # 4402 # F x # 4403 # # 4404 # # 4405 # # 4406 ############################################################################### 4407 # 4408 # 4409 void 4410 Fx(ref,...) 4411 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 4412 ALIAS: 4413 FxImage = 1 4414 fx = 2 4415 fximage = 3 4416 PPCODE: 4417 { 4418 AV 4419 *av; 4420 4421 char 4422 *attribute, 4423 expression[MagickPathExtent]; 4424 4425 ChannelType 4426 channel, 4427 channel_mask; 4428 4429 ExceptionInfo 4430 *exception; 4431 4432 HV 4433 *hv; 4434 4435 Image 4436 *image; 4437 4438 register ssize_t 4439 i; 4440 4441 struct PackageInfo 4442 *info; 4443 4444 SV 4445 *av_reference, 4446 *perl_exception, 4447 *reference, 4448 *rv, 4449 *sv; 4450 4451 PERL_UNUSED_VAR(ref); 4452 PERL_UNUSED_VAR(ix); 4453 exception=AcquireExceptionInfo(); 4454 perl_exception=newSVpv("",0); 4455 sv=NULL; 4456 attribute=NULL; 4457 av=NULL; 4458 if (sv_isobject(ST(0)) == 0) 4459 { 4460 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 4461 PackageName); 4462 goto PerlException; 4463 } 4464 reference=SvRV(ST(0)); 4465 hv=SvSTASH(reference); 4466 av=newAV(); 4467 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 4468 SvREFCNT_dec(av); 4469 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 4470 if (image == (Image *) NULL) 4471 { 4472 ThrowPerlException(exception,OptionError,"NoImagesDefined", 4473 PackageName); 4474 goto PerlException; 4475 } 4476 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 4477 /* 4478 Get options. 4479 */ 4480 channel=DefaultChannels; 4481 (void) CopyMagickString(expression,"u",MagickPathExtent); 4482 if (items == 2) 4483 (void) CopyMagickString(expression,(char *) SvPV(ST(1),na),MagickPathExtent); 4484 else 4485 for (i=2; i < items; i+=2) 4486 { 4487 attribute=(char *) SvPV(ST(i-1),na); 4488 switch (*attribute) 4489 { 4490 case 'C': 4491 case 'c': 4492 { 4493 if (LocaleCompare(attribute,"channel") == 0) 4494 { 4495 ssize_t 4496 option; 4497 4498 option=ParseChannelOption(SvPV(ST(i),na)); 4499 if (option < 0) 4500 { 4501 ThrowPerlException(exception,OptionError, 4502 "UnrecognizedType",SvPV(ST(i),na)); 4503 return; 4504 } 4505 channel=(ChannelType) option; 4506 break; 4507 } 4508 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4509 attribute); 4510 break; 4511 } 4512 case 'E': 4513 case 'e': 4514 { 4515 if (LocaleCompare(attribute,"expression") == 0) 4516 { 4517 (void) CopyMagickString(expression,SvPV(ST(i),na), 4518 MagickPathExtent); 4519 break; 4520 } 4521 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4522 attribute); 4523 break; 4524 } 4525 default: 4526 { 4527 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4528 attribute); 4529 break; 4530 } 4531 } 4532 } 4533 channel_mask=SetImageChannelMask(image,channel); 4534 image=FxImage(image,expression,exception); 4535 if (image != (Image *) NULL) 4536 (void) SetImageChannelMask(image,channel_mask); 4537 if (image == (Image *) NULL) 4538 goto PerlException; 4539 for ( ; image; image=image->next) 4540 { 4541 AddImageToRegistry(sv,image); 4542 rv=newRV(sv); 4543 av_push(av,sv_bless(rv,hv)); 4544 SvREFCNT_dec(sv); 4545 } 4546 exception=DestroyExceptionInfo(exception); 4547 ST(0)=av_reference; 4548 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 4549 XSRETURN(1); 4550 4551 PerlException: 4552 InheritPerlException(exception,perl_exception); 4553 exception=DestroyExceptionInfo(exception); 4554 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 4555 SvPOK_on(perl_exception); 4556 ST(0)=sv_2mortal(perl_exception); 4557 XSRETURN(1); 4558 } 4559 4560 # 4562 ############################################################################### 4563 # # 4564 # # 4565 # # 4566 # G e t # 4567 # # 4568 # # 4569 # # 4570 ############################################################################### 4571 # 4572 # 4573 void 4574 Get(ref,...) 4575 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 4576 ALIAS: 4577 GetAttributes = 1 4578 GetAttribute = 2 4579 get = 3 4580 getattributes = 4 4581 getattribute = 5 4582 PPCODE: 4583 { 4584 char 4585 *attribute, 4586 color[MagickPathExtent]; 4587 4588 const char 4589 *value; 4590 4591 ExceptionInfo 4592 *exception; 4593 4594 Image 4595 *image; 4596 4597 long 4598 j; 4599 4600 register ssize_t 4601 i; 4602 4603 struct PackageInfo 4604 *info; 4605 4606 SV 4607 *perl_exception, 4608 *reference, 4609 *s; 4610 4611 PERL_UNUSED_VAR(ref); 4612 PERL_UNUSED_VAR(ix); 4613 exception=AcquireExceptionInfo(); 4614 perl_exception=newSVpv("",0); 4615 if (sv_isobject(ST(0)) == 0) 4616 { 4617 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 4618 PackageName); 4619 XSRETURN_EMPTY; 4620 } 4621 reference=SvRV(ST(0)); 4622 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 4623 if (image == (Image *) NULL && !info) 4624 XSRETURN_EMPTY; 4625 EXTEND(sp,items); 4626 for (i=1; i < items; i++) 4627 { 4628 attribute=(char *) SvPV(ST(i),na); 4629 s=NULL; 4630 switch (*attribute) 4631 { 4632 case 'A': 4633 case 'a': 4634 { 4635 if (LocaleCompare(attribute,"adjoin") == 0) 4636 { 4637 if (info) 4638 s=newSViv((ssize_t) info->image_info->adjoin); 4639 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4640 continue; 4641 } 4642 if (LocaleCompare(attribute,"antialias") == 0) 4643 { 4644 if (info) 4645 s=newSViv((ssize_t) info->image_info->antialias); 4646 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4647 continue; 4648 } 4649 if (LocaleCompare(attribute,"area") == 0) 4650 { 4651 s=newSViv(GetMagickResource(AreaResource)); 4652 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4653 continue; 4654 } 4655 if (LocaleCompare(attribute,"attenuate") == 0) 4656 { 4657 const char 4658 *value; 4659 4660 value=GetImageProperty(image,attribute,exception); 4661 if (value != (const char *) NULL) 4662 s=newSVpv(value,0); 4663 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4664 continue; 4665 } 4666 if (LocaleCompare(attribute,"authenticate") == 0) 4667 { 4668 if (info) 4669 { 4670 const char 4671 *option; 4672 4673 option=GetImageOption(info->image_info,attribute); 4674 if (option != (const char *) NULL) 4675 s=newSVpv(option,0); 4676 } 4677 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4678 continue; 4679 } 4680 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4681 attribute); 4682 break; 4683 } 4684 case 'B': 4685 case 'b': 4686 { 4687 if (LocaleCompare(attribute,"background") == 0) 4688 { 4689 if (image == (Image *) NULL) 4690 break; 4691 (void) FormatLocaleString(color,MagickPathExtent, 4692 "%.20g,%.20g,%.20g,%.20g",(double) image->background_color.red, 4693 (double) image->background_color.green, 4694 (double) image->background_color.blue, 4695 (double) image->background_color.alpha); 4696 s=newSVpv(color,0); 4697 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4698 continue; 4699 } 4700 if (LocaleCompare(attribute,"base-columns") == 0) 4701 { 4702 if (image != (Image *) NULL) 4703 s=newSViv((ssize_t) image->magick_columns); 4704 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4705 continue; 4706 } 4707 if (LocaleCompare(attribute,"base-filename") == 0) 4708 { 4709 if (image != (Image *) NULL) 4710 s=newSVpv(image->magick_filename,0); 4711 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4712 continue; 4713 } 4714 if (LocaleCompare(attribute,"base-height") == 0) 4715 { 4716 if (image != (Image *) NULL) 4717 s=newSViv((ssize_t) image->magick_rows); 4718 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4719 continue; 4720 } 4721 if (LocaleCompare(attribute,"base-rows") == 0) 4722 { 4723 if (image != (Image *) NULL) 4724 s=newSViv((ssize_t) image->magick_rows); 4725 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4726 continue; 4727 } 4728 if (LocaleCompare(attribute,"base-width") == 0) 4729 { 4730 if (image != (Image *) NULL) 4731 s=newSViv((ssize_t) image->magick_columns); 4732 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4733 continue; 4734 } 4735 if (LocaleCompare(attribute,"blue-primary") == 0) 4736 { 4737 if (image == (Image *) NULL) 4738 break; 4739 (void) FormatLocaleString(color,MagickPathExtent,"%.15g,%.15g", 4740 image->chromaticity.blue_primary.x, 4741 image->chromaticity.blue_primary.y); 4742 s=newSVpv(color,0); 4743 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4744 continue; 4745 } 4746 if (LocaleCompare(attribute,"bordercolor") == 0) 4747 { 4748 if (image == (Image *) NULL) 4749 break; 4750 (void) FormatLocaleString(color,MagickPathExtent, 4751 "%.20g,%.20g,%.20g,%.20g",(double) image->border_color.red, 4752 (double) image->border_color.green, 4753 (double) image->border_color.blue, 4754 (double) image->border_color.alpha); 4755 s=newSVpv(color,0); 4756 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4757 continue; 4758 } 4759 if (LocaleCompare(attribute,"bounding-box") == 0) 4760 { 4761 char 4762 geometry[MagickPathExtent]; 4763 4764 RectangleInfo 4765 page; 4766 4767 if (image == (Image *) NULL) 4768 break; 4769 page=GetImageBoundingBox(image,exception); 4770 (void) FormatLocaleString(geometry,MagickPathExtent, 4771 "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) 4772 page.height,(double) page.x,(double) page.y); 4773 s=newSVpv(geometry,0); 4774 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4775 continue; 4776 } 4777 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4778 attribute); 4779 break; 4780 } 4781 case 'C': 4782 case 'c': 4783 { 4784 if (LocaleCompare(attribute,"class") == 0) 4785 { 4786 if (image == (Image *) NULL) 4787 break; 4788 s=newSViv(image->storage_class); 4789 (void) sv_setpv(s,CommandOptionToMnemonic(MagickClassOptions, 4790 image->storage_class)); 4791 SvIOK_on(s); 4792 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4793 continue; 4794 } 4795 if (LocaleCompare(attribute,"clip-mask") == 0) 4796 { 4797 if (image != (Image *) NULL) 4798 { 4799 Image 4800 *mask_image; 4801 4802 SV 4803 *sv; 4804 4805 sv=NULL; 4806 if (image->read_mask == MagickFalse) 4807 ClipImage(image,exception); 4808 mask_image=GetImageMask(image,ReadPixelMask,exception); 4809 if (mask_image != (Image *) NULL) 4810 { 4811 AddImageToRegistry(sv,mask_image); 4812 s=sv_bless(newRV(sv),SvSTASH(reference)); 4813 } 4814 } 4815 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4816 continue; 4817 } 4818 if (LocaleCompare(attribute,"clip-path") == 0) 4819 { 4820 if (image != (Image *) NULL) 4821 { 4822 Image 4823 *mask_image; 4824 4825 SV 4826 *sv; 4827 4828 sv=NULL; 4829 if (image->read_mask != MagickFalse) 4830 ClipImage(image,exception); 4831 mask_image=GetImageMask(image,ReadPixelMask,exception); 4832 if (mask_image != (Image *) NULL) 4833 { 4834 AddImageToRegistry(sv,mask_image); 4835 s=sv_bless(newRV(sv),SvSTASH(reference)); 4836 } 4837 } 4838 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4839 continue; 4840 } 4841 if (LocaleCompare(attribute,"compression") == 0) 4842 { 4843 j=info ? info->image_info->compression : image ? 4844 image->compression : UndefinedCompression; 4845 if (info) 4846 if (info->image_info->compression == UndefinedCompression) 4847 j=image->compression; 4848 s=newSViv(j); 4849 (void) sv_setpv(s,CommandOptionToMnemonic(MagickCompressOptions, 4850 j)); 4851 SvIOK_on(s); 4852 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4853 continue; 4854 } 4855 if (LocaleCompare(attribute,"colorspace") == 0) 4856 { 4857 j=image ? image->colorspace : RGBColorspace; 4858 s=newSViv(j); 4859 (void) sv_setpv(s,CommandOptionToMnemonic(MagickColorspaceOptions, 4860 j)); 4861 SvIOK_on(s); 4862 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4863 continue; 4864 } 4865 if (LocaleCompare(attribute,"colors") == 0) 4866 { 4867 if (image != (Image *) NULL) 4868 s=newSViv((ssize_t) GetNumberColors(image,(FILE *) NULL, 4869 exception)); 4870 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4871 continue; 4872 } 4873 if (LocaleNCompare(attribute,"colormap",8) == 0) 4874 { 4875 int 4876 items; 4877 4878 if (image == (Image *) NULL || !image->colormap) 4879 break; 4880 j=0; 4881 items=sscanf(attribute,"%*[^[][%ld",&j); 4882 (void) items; 4883 if (j > (ssize_t) image->colors) 4884 j%=image->colors; 4885 (void) FormatLocaleString(color,MagickPathExtent, 4886 "%.20g,%.20g,%.20g,%.20g",(double) image->colormap[j].red, 4887 (double) image->colormap[j].green, 4888 (double) image->colormap[j].blue, 4889 (double) image->colormap[j].alpha); 4890 s=newSVpv(color,0); 4891 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4892 continue; 4893 } 4894 if (LocaleCompare(attribute,"columns") == 0) 4895 { 4896 if (image != (Image *) NULL) 4897 s=newSViv((ssize_t) image->columns); 4898 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4899 continue; 4900 } 4901 if (LocaleCompare(attribute,"comment") == 0) 4902 { 4903 const char 4904 *value; 4905 4906 value=GetImageProperty(image,attribute,exception); 4907 if (value != (const char *) NULL) 4908 s=newSVpv(value,0); 4909 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4910 continue; 4911 } 4912 if (LocaleCompare(attribute,"copyright") == 0) 4913 { 4914 s=newSVpv(GetMagickCopyright(),0); 4915 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4916 continue; 4917 } 4918 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4919 attribute); 4920 break; 4921 } 4922 case 'D': 4923 case 'd': 4924 { 4925 if (LocaleCompare(attribute,"density") == 0) 4926 { 4927 char 4928 geometry[MagickPathExtent]; 4929 4930 if (image == (Image *) NULL) 4931 break; 4932 (void) FormatLocaleString(geometry,MagickPathExtent,"%.15gx%.15g", 4933 image->resolution.x,image->resolution.y); 4934 s=newSVpv(geometry,0); 4935 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4936 continue; 4937 } 4938 if (LocaleCompare(attribute,"delay") == 0) 4939 { 4940 if (image != (Image *) NULL) 4941 s=newSViv((ssize_t) image->delay); 4942 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4943 continue; 4944 } 4945 if (LocaleCompare(attribute,"depth") == 0) 4946 { 4947 s=newSViv(MAGICKCORE_QUANTUM_DEPTH); 4948 if (image != (Image *) NULL) 4949 s=newSViv((ssize_t) GetImageDepth(image,exception)); 4950 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4951 continue; 4952 } 4953 if (LocaleCompare(attribute,"directory") == 0) 4954 { 4955 if (image && image->directory) 4956 s=newSVpv(image->directory,0); 4957 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4958 continue; 4959 } 4960 if (LocaleCompare(attribute,"dispose") == 0) 4961 { 4962 if (image == (Image *) NULL) 4963 break; 4964 4965 s=newSViv(image->dispose); 4966 (void) sv_setpv(s, 4967 CommandOptionToMnemonic(MagickDisposeOptions,image->dispose)); 4968 SvIOK_on(s); 4969 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4970 continue; 4971 } 4972 if (LocaleCompare(attribute,"disk") == 0) 4973 { 4974 s=newSViv(GetMagickResource(DiskResource)); 4975 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4976 continue; 4977 } 4978 if (LocaleCompare(attribute,"dither") == 0) 4979 { 4980 if (info) 4981 s=newSViv((ssize_t) info->image_info->dither); 4982 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4983 continue; 4984 } 4985 if (LocaleCompare(attribute,"display") == 0) /* same as server */ 4986 { 4987 if (info && info->image_info->server_name) 4988 s=newSVpv(info->image_info->server_name,0); 4989 PUSHs(s ? sv_2mortal(s) : &sv_undef); 4990 continue; 4991 } 4992 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 4993 attribute); 4994 break; 4995 } 4996 case 'E': 4997 case 'e': 4998 { 4999 if (LocaleCompare(attribute,"elapsed-time") == 0) 5000 { 5001 if (image != (Image *) NULL) 5002 s=newSVnv(GetElapsedTime(&image->timer)); 5003 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5004 continue; 5005 } 5006 if (LocaleCompare(attribute,"endian") == 0) 5007 { 5008 j=info ? info->image_info->endian : image ? image->endian : 5009 UndefinedEndian; 5010 s=newSViv(j); 5011 (void) sv_setpv(s,CommandOptionToMnemonic(MagickEndianOptions,j)); 5012 SvIOK_on(s); 5013 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5014 continue; 5015 } 5016 if (LocaleCompare(attribute,"error") == 0) 5017 { 5018 if (image != (Image *) NULL) 5019 s=newSVnv(image->error.mean_error_per_pixel); 5020 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5021 continue; 5022 } 5023 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5024 attribute); 5025 break; 5026 } 5027 case 'F': 5028 case 'f': 5029 { 5030 if (LocaleCompare(attribute,"filesize") == 0) 5031 { 5032 if (image != (Image *) NULL) 5033 s=newSViv((ssize_t) GetBlobSize(image)); 5034 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5035 continue; 5036 } 5037 if (LocaleCompare(attribute,"filename") == 0) 5038 { 5039 if (info && info->image_info->filename && 5040 *info->image_info->filename) 5041 s=newSVpv(info->image_info->filename,0); 5042 if (image != (Image *) NULL) 5043 s=newSVpv(image->filename,0); 5044 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5045 continue; 5046 } 5047 if (LocaleCompare(attribute,"filter") == 0) 5048 { 5049 s=image ? newSViv(image->filter) : newSViv(0); 5050 (void) sv_setpv(s,CommandOptionToMnemonic(MagickFilterOptions, 5051 image->filter)); 5052 SvIOK_on(s); 5053 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5054 continue; 5055 } 5056 if (LocaleCompare(attribute,"font") == 0) 5057 { 5058 if (info && info->image_info->font) 5059 s=newSVpv(info->image_info->font,0); 5060 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5061 continue; 5062 } 5063 if (LocaleCompare(attribute,"foreground") == 0) 5064 continue; 5065 if (LocaleCompare(attribute,"format") == 0) 5066 { 5067 const MagickInfo 5068 *magick_info; 5069 5070 magick_info=(const MagickInfo *) NULL; 5071 if (info && (*info->image_info->magick != '\0')) 5072 magick_info=GetMagickInfo(info->image_info->magick,exception); 5073 if (image != (Image *) NULL) 5074 magick_info=GetMagickInfo(image->magick,exception); 5075 if ((magick_info != (const MagickInfo *) NULL) && 5076 (*magick_info->description != '\0')) 5077 s=newSVpv((char *) magick_info->description,0); 5078 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5079 continue; 5080 } 5081 if (LocaleCompare(attribute,"fuzz") == 0) 5082 { 5083 if (info) 5084 s=newSVnv(info->image_info->fuzz); 5085 if (image != (Image *) NULL) 5086 s=newSVnv(image->fuzz); 5087 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5088 continue; 5089 } 5090 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5091 attribute); 5092 break; 5093 } 5094 case 'G': 5095 case 'g': 5096 { 5097 if (LocaleCompare(attribute,"gamma") == 0) 5098 { 5099 if (image != (Image *) NULL) 5100 s=newSVnv(image->gamma); 5101 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5102 continue; 5103 } 5104 if (LocaleCompare(attribute,"geometry") == 0) 5105 { 5106 if (image && image->geometry) 5107 s=newSVpv(image->geometry,0); 5108 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5109 continue; 5110 } 5111 if (LocaleCompare(attribute,"gravity") == 0) 5112 { 5113 s=image ? newSViv(image->gravity) : newSViv(0); 5114 (void) sv_setpv(s,CommandOptionToMnemonic(MagickGravityOptions, 5115 image->gravity)); 5116 SvIOK_on(s); 5117 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5118 continue; 5119 } 5120 if (LocaleCompare(attribute,"green-primary") == 0) 5121 { 5122 if (image == (Image *) NULL) 5123 break; 5124 (void) FormatLocaleString(color,MagickPathExtent,"%.15g,%.15g", 5125 image->chromaticity.green_primary.x, 5126 image->chromaticity.green_primary.y); 5127 s=newSVpv(color,0); 5128 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5129 continue; 5130 } 5131 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5132 attribute); 5133 break; 5134 } 5135 case 'H': 5136 case 'h': 5137 { 5138 if (LocaleCompare(attribute,"height") == 0) 5139 { 5140 if (image != (Image *) NULL) 5141 s=newSViv((ssize_t) image->rows); 5142 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5143 continue; 5144 } 5145 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5146 attribute); 5147 break; 5148 } 5149 case 'I': 5150 case 'i': 5151 { 5152 if (LocaleCompare(attribute,"icc") == 0) 5153 { 5154 if (image != (Image *) NULL) 5155 { 5156 const StringInfo 5157 *profile; 5158 5159 profile=GetImageProfile(image,"icc"); 5160 if (profile != (StringInfo *) NULL) 5161 s=newSVpv((const char *) GetStringInfoDatum(profile), 5162 GetStringInfoLength(profile)); 5163 } 5164 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5165 continue; 5166 } 5167 if (LocaleCompare(attribute,"icm") == 0) 5168 { 5169 if (image != (Image *) NULL) 5170 { 5171 const StringInfo 5172 *profile; 5173 5174 profile=GetImageProfile(image,"icm"); 5175 if (profile != (const StringInfo *) NULL) 5176 s=newSVpv((const char *) GetStringInfoDatum(profile), 5177 GetStringInfoLength(profile)); 5178 } 5179 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5180 continue; 5181 } 5182 if (LocaleCompare(attribute,"id") == 0) 5183 { 5184 if (image != (Image *) NULL) 5185 { 5186 char 5187 key[MagickPathExtent]; 5188 5189 MagickBooleanType 5190 status; 5191 5192 static ssize_t 5193 id = 0; 5194 5195 (void) FormatLocaleString(key,MagickPathExtent,"%.20g\n",(double) 5196 id); 5197 status=SetImageRegistry(ImageRegistryType,key,image, 5198 exception); 5199 (void) status; 5200 s=newSViv(id++); 5201 } 5202 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5203 continue; 5204 } 5205 if (LocaleNCompare(attribute,"index",5) == 0) 5206 { 5207 char 5208 name[MagickPathExtent]; 5209 5210 int 5211 items; 5212 5213 long 5214 x, 5215 y; 5216 5217 register const Quantum 5218 *p; 5219 5220 CacheView 5221 *image_view; 5222 5223 if (image == (Image *) NULL) 5224 break; 5225 if (image->storage_class != PseudoClass) 5226 break; 5227 x=0; 5228 y=0; 5229 items=sscanf(attribute,"%*[^[][%ld%*[,/]%ld",&x,&y); 5230 (void) items; 5231 image_view=AcquireVirtualCacheView(image,exception); 5232 p=GetCacheViewVirtualPixels(image_view,x,y,1,1,exception); 5233 if (p != (const Quantum *) NULL) 5234 { 5235 (void) FormatLocaleString(name,MagickPathExtent,QuantumFormat, 5236 GetPixelIndex(image,p)); 5237 s=newSVpv(name,0); 5238 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5239 } 5240 image_view=DestroyCacheView(image_view); 5241 continue; 5242 } 5243 if (LocaleCompare(attribute,"iptc") == 0) 5244 { 5245 if (image != (Image *) NULL) 5246 { 5247 const StringInfo 5248 *profile; 5249 5250 profile=GetImageProfile(image,"iptc"); 5251 if (profile != (const StringInfo *) NULL) 5252 s=newSVpv((const char *) GetStringInfoDatum(profile), 5253 GetStringInfoLength(profile)); 5254 } 5255 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5256 continue; 5257 } 5258 if (LocaleCompare(attribute,"iterations") == 0) /* same as loop */ 5259 { 5260 if (image != (Image *) NULL) 5261 s=newSViv((ssize_t) image->iterations); 5262 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5263 continue; 5264 } 5265 if (LocaleCompare(attribute,"interlace") == 0) 5266 { 5267 j=info ? info->image_info->interlace : image ? image->interlace : 5268 UndefinedInterlace; 5269 s=newSViv(j); 5270 (void) sv_setpv(s,CommandOptionToMnemonic(MagickInterlaceOptions, 5271 j)); 5272 SvIOK_on(s); 5273 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5274 continue; 5275 } 5276 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5277 attribute); 5278 break; 5279 } 5280 case 'L': 5281 case 'l': 5282 { 5283 if (LocaleCompare(attribute,"label") == 0) 5284 { 5285 const char 5286 *value; 5287 5288 if (image == (Image *) NULL) 5289 break; 5290 value=GetImageProperty(image,"Label",exception); 5291 if (value != (const char *) NULL) 5292 s=newSVpv(value,0); 5293 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5294 continue; 5295 } 5296 if (LocaleCompare(attribute,"loop") == 0) /* same as iterations */ 5297 { 5298 if (image != (Image *) NULL) 5299 s=newSViv((ssize_t) image->iterations); 5300 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5301 continue; 5302 } 5303 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5304 attribute); 5305 break; 5306 } 5307 case 'M': 5308 case 'm': 5309 { 5310 if (LocaleCompare(attribute,"magick") == 0) 5311 { 5312 if (info && *info->image_info->magick) 5313 s=newSVpv(info->image_info->magick,0); 5314 if (image != (Image *) NULL) 5315 s=newSVpv(image->magick,0); 5316 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5317 continue; 5318 } 5319 if (LocaleCompare(attribute,"map") == 0) 5320 { 5321 s=newSViv(GetMagickResource(MapResource)); 5322 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5323 continue; 5324 } 5325 if (LocaleCompare(attribute,"maximum-error") == 0) 5326 { 5327 if (image != (Image *) NULL) 5328 s=newSVnv(image->error.normalized_maximum_error); 5329 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5330 continue; 5331 } 5332 if (LocaleCompare(attribute,"memory") == 0) 5333 { 5334 s=newSViv(GetMagickResource(MemoryResource)); 5335 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5336 continue; 5337 } 5338 if (LocaleCompare(attribute,"mean-error") == 0) 5339 { 5340 if (image != (Image *) NULL) 5341 s=newSVnv(image->error.normalized_mean_error); 5342 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5343 continue; 5344 } 5345 if (LocaleCompare(attribute,"mime") == 0) 5346 { 5347 if (info && *info->image_info->magick) 5348 s=newSVpv(MagickToMime(info->image_info->magick),0); 5349 if (image != (Image *) NULL) 5350 s=newSVpv(MagickToMime(image->magick),0); 5351 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5352 continue; 5353 } 5354 if (LocaleCompare(attribute,"mattecolor") == 0) 5355 { 5356 if (image == (Image *) NULL) 5357 break; 5358 (void) FormatLocaleString(color,MagickPathExtent, 5359 "%.20g,%.20g,%.20g,%.20g",(double) image->alpha_color.red, 5360 (double) image->alpha_color.green, 5361 (double) image->alpha_color.blue, 5362 (double) image->alpha_color.alpha); 5363 s=newSVpv(color,0); 5364 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5365 continue; 5366 } 5367 if (LocaleCompare(attribute,"matte") == 0) 5368 { 5369 if (image != (Image *) NULL) 5370 s=newSViv((ssize_t) image->alpha_trait != UndefinedPixelTrait ? 5371 1 : 0); 5372 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5373 continue; 5374 } 5375 if (LocaleCompare(attribute,"mime") == 0) 5376 { 5377 const char 5378 *magick; 5379 5380 magick=NULL; 5381 if (info && *info->image_info->magick) 5382 magick=info->image_info->magick; 5383 if (image != (Image *) NULL) 5384 magick=image->magick; 5385 if (magick) 5386 { 5387 char 5388 *mime; 5389 5390 mime=MagickToMime(magick); 5391 s=newSVpv(mime,0); 5392 mime=(char *) RelinquishMagickMemory(mime); 5393 } 5394 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5395 continue; 5396 } 5397 if (LocaleCompare(attribute,"monochrome") == 0) 5398 { 5399 if (image == (Image *) NULL) 5400 continue; 5401 j=info ? info->image_info->monochrome : 5402 SetImageMonochrome(image,exception); 5403 s=newSViv(j); 5404 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5405 continue; 5406 } 5407 if (LocaleCompare(attribute,"montage") == 0) 5408 { 5409 if (image && image->montage) 5410 s=newSVpv(image->montage,0); 5411 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5412 continue; 5413 } 5414 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5415 attribute); 5416 break; 5417 } 5418 case 'O': 5419 case 'o': 5420 { 5421 if (LocaleCompare(attribute,"orientation") == 0) 5422 { 5423 j=info ? info->image_info->orientation : image ? 5424 image->orientation : UndefinedOrientation; 5425 s=newSViv(j); 5426 (void) sv_setpv(s,CommandOptionToMnemonic(MagickOrientationOptions, 5427 j)); 5428 SvIOK_on(s); 5429 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5430 continue; 5431 } 5432 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5433 attribute); 5434 break; 5435 } 5436 case 'P': 5437 case 'p': 5438 { 5439 if (LocaleCompare(attribute,"page") == 0) 5440 { 5441 if (info && info->image_info->page) 5442 s=newSVpv(info->image_info->page,0); 5443 if (image != (Image *) NULL) 5444 { 5445 char 5446 geometry[MagickPathExtent]; 5447 5448 (void) FormatLocaleString(geometry,MagickPathExtent, 5449 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width, 5450 (double) image->page.height,(double) image->page.x,(double) 5451 image->page.y); 5452 s=newSVpv(geometry,0); 5453 } 5454 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5455 continue; 5456 } 5457 if (LocaleCompare(attribute,"page.x") == 0) 5458 { 5459 if (image != (Image *) NULL) 5460 s=newSViv((ssize_t) image->page.x); 5461 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5462 continue; 5463 } 5464 if (LocaleCompare(attribute,"page.y") == 0) 5465 { 5466 if (image != (Image *) NULL) 5467 s=newSViv((ssize_t) image->page.y); 5468 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5469 continue; 5470 } 5471 if (LocaleNCompare(attribute,"pixel",5) == 0) 5472 { 5473 char 5474 tuple[MagickPathExtent]; 5475 5476 int 5477 items; 5478 5479 long 5480 x, 5481 y; 5482 5483 register const Quantum 5484 *p; 5485 5486 if (image == (Image *) NULL) 5487 break; 5488 x=0; 5489 y=0; 5490 items=sscanf(attribute,"%*[^[][%ld%*[,/]%ld",&x,&y); 5491 (void) items; 5492 p=GetVirtualPixels(image,x,y,1,1,exception); 5493 if (image->colorspace != CMYKColorspace) 5494 (void) FormatLocaleString(tuple,MagickPathExtent,QuantumFormat "," 5495 QuantumFormat "," QuantumFormat "," QuantumFormat, 5496 GetPixelRed(image,p),GetPixelGreen(image,p), 5497 GetPixelBlue(image,p),GetPixelAlpha(image,p)); 5498 else 5499 (void) FormatLocaleString(tuple,MagickPathExtent,QuantumFormat "," 5500 QuantumFormat "," QuantumFormat "," QuantumFormat "," 5501 QuantumFormat,GetPixelRed(image,p),GetPixelGreen(image,p), 5502 GetPixelBlue(image,p),GetPixelBlack(image,p), 5503 GetPixelAlpha(image,p)); 5504 s=newSVpv(tuple,0); 5505 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5506 continue; 5507 } 5508 if (LocaleCompare(attribute,"pointsize") == 0) 5509 { 5510 if (info) 5511 s=newSViv((ssize_t) info->image_info->pointsize); 5512 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5513 continue; 5514 } 5515 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5516 attribute); 5517 break; 5518 } 5519 case 'Q': 5520 case 'q': 5521 { 5522 if (LocaleCompare(attribute,"quality") == 0) 5523 { 5524 if (info) 5525 s=newSViv((ssize_t) info->image_info->quality); 5526 if (image != (Image *) NULL) 5527 s=newSViv((ssize_t) image->quality); 5528 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5529 continue; 5530 } 5531 if (LocaleCompare(attribute,"quantum") == 0) 5532 { 5533 if (info) 5534 s=newSViv((ssize_t) MAGICKCORE_QUANTUM_DEPTH); 5535 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5536 continue; 5537 } 5538 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5539 attribute); 5540 break; 5541 } 5542 case 'R': 5543 case 'r': 5544 { 5545 if (LocaleCompare(attribute,"rendering-intent") == 0) 5546 { 5547 s=newSViv(image->rendering_intent); 5548 (void) sv_setpv(s,CommandOptionToMnemonic(MagickIntentOptions, 5549 image->rendering_intent)); 5550 SvIOK_on(s); 5551 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5552 continue; 5553 } 5554 if (LocaleCompare(attribute,"red-primary") == 0) 5555 { 5556 if (image == (Image *) NULL) 5557 break; 5558 (void) FormatLocaleString(color,MagickPathExtent,"%.15g,%.15g", 5559 image->chromaticity.red_primary.x, 5560 image->chromaticity.red_primary.y); 5561 s=newSVpv(color,0); 5562 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5563 continue; 5564 } 5565 if (LocaleCompare(attribute,"rows") == 0) 5566 { 5567 if (image != (Image *) NULL) 5568 s=newSViv((ssize_t) image->rows); 5569 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5570 continue; 5571 } 5572 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5573 attribute); 5574 break; 5575 } 5576 case 'S': 5577 case 's': 5578 { 5579 if (LocaleCompare(attribute,"sampling-factor") == 0) 5580 { 5581 if (info && info->image_info->sampling_factor) 5582 s=newSVpv(info->image_info->sampling_factor,0); 5583 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5584 continue; 5585 } 5586 if (LocaleCompare(attribute,"server") == 0) /* same as display */ 5587 { 5588 if (info && info->image_info->server_name) 5589 s=newSVpv(info->image_info->server_name,0); 5590 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5591 continue; 5592 } 5593 if (LocaleCompare(attribute,"size") == 0) 5594 { 5595 if (info && info->image_info->size) 5596 s=newSVpv(info->image_info->size,0); 5597 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5598 continue; 5599 } 5600 if (LocaleCompare(attribute,"scene") == 0) 5601 { 5602 if (image != (Image *) NULL) 5603 s=newSViv((ssize_t) image->scene); 5604 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5605 continue; 5606 } 5607 if (LocaleCompare(attribute,"scenes") == 0) 5608 { 5609 if (image != (Image *) NULL) 5610 s=newSViv((ssize_t) info->image_info->number_scenes); 5611 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5612 continue; 5613 } 5614 if (LocaleCompare(attribute,"signature") == 0) 5615 { 5616 const char 5617 *value; 5618 5619 if (image == (Image *) NULL) 5620 break; 5621 (void) SignatureImage(image,exception); 5622 value=GetImageProperty(image,"Signature",exception); 5623 if (value != (const char *) NULL) 5624 s=newSVpv(value,0); 5625 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5626 continue; 5627 } 5628 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5629 attribute); 5630 break; 5631 } 5632 case 'T': 5633 case 't': 5634 { 5635 if (LocaleCompare(attribute,"taint") == 0) 5636 { 5637 if (image != (Image *) NULL) 5638 s=newSViv((ssize_t) IsTaintImage(image)); 5639 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5640 continue; 5641 } 5642 if (LocaleCompare(attribute,"texture") == 0) 5643 { 5644 if (info && info->image_info->texture) 5645 s=newSVpv(info->image_info->texture,0); 5646 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5647 continue; 5648 } 5649 if (LocaleCompare(attribute,"total-ink-density") == 0) 5650 { 5651 s=newSViv(MAGICKCORE_QUANTUM_DEPTH); 5652 if (image != (Image *) NULL) 5653 s=newSVnv(GetImageTotalInkDensity(image,exception)); 5654 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5655 continue; 5656 } 5657 if (LocaleCompare(attribute,"transparent-color") == 0) 5658 { 5659 if (image == (Image *) NULL) 5660 break; 5661 (void) FormatLocaleString(color,MagickPathExtent, 5662 "%.20g,%.20g,%.20g,%.20g",(double) image->transparent_color.red, 5663 (double) image->transparent_color.green, 5664 (double) image->transparent_color.blue, 5665 (double) image->transparent_color.alpha); 5666 s=newSVpv(color,0); 5667 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5668 continue; 5669 } 5670 if (LocaleCompare(attribute,"type") == 0) 5671 { 5672 if (image == (Image *) NULL) 5673 break; 5674 j=(ssize_t) GetImageType(image); 5675 s=newSViv(j); 5676 (void) sv_setpv(s,CommandOptionToMnemonic(MagickTypeOptions,j)); 5677 SvIOK_on(s); 5678 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5679 continue; 5680 } 5681 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5682 attribute); 5683 break; 5684 } 5685 case 'U': 5686 case 'u': 5687 { 5688 if (LocaleCompare(attribute,"units") == 0) 5689 { 5690 j=info ? info->image_info->units : image ? image->units : 5691 UndefinedResolution; 5692 if (info && (info->image_info->units == UndefinedResolution)) 5693 if (image) 5694 j=image->units; 5695 if (j == UndefinedResolution) 5696 s=newSVpv("undefined units",0); 5697 else 5698 if (j == PixelsPerInchResolution) 5699 s=newSVpv("pixels / inch",0); 5700 else 5701 s=newSVpv("pixels / centimeter",0); 5702 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5703 continue; 5704 } 5705 if (LocaleCompare(attribute,"user-time") == 0) 5706 { 5707 if (image != (Image *) NULL) 5708 s=newSVnv(GetUserTime(&image->timer)); 5709 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5710 continue; 5711 } 5712 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5713 attribute); 5714 break; 5715 } 5716 case 'V': 5717 case 'v': 5718 { 5719 if (LocaleCompare(attribute,"verbose") == 0) 5720 { 5721 if (info) 5722 s=newSViv((ssize_t) info->image_info->verbose); 5723 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5724 continue; 5725 } 5726 if (LocaleCompare(attribute,"version") == 0) 5727 { 5728 s=newSVpv(GetMagickVersion((size_t *) NULL),0); 5729 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5730 continue; 5731 } 5732 if (LocaleCompare(attribute,"virtual-pixel") == 0) 5733 { 5734 if (image == (Image *) NULL) 5735 break; 5736 j=(ssize_t) GetImageVirtualPixelMethod(image); 5737 s=newSViv(j); 5738 (void) sv_setpv(s,CommandOptionToMnemonic( 5739 MagickVirtualPixelOptions,j)); 5740 SvIOK_on(s); 5741 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5742 continue; 5743 } 5744 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5745 attribute); 5746 break; 5747 } 5748 case 'W': 5749 case 'w': 5750 { 5751 if (LocaleCompare(attribute,"white-point") == 0) 5752 { 5753 if (image == (Image *) NULL) 5754 break; 5755 (void) FormatLocaleString(color,MagickPathExtent,"%.15g,%.15g", 5756 image->chromaticity.white_point.x, 5757 image->chromaticity.white_point.y); 5758 s=newSVpv(color,0); 5759 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5760 continue; 5761 } 5762 if (LocaleCompare(attribute,"width") == 0) 5763 { 5764 if (image != (Image *) NULL) 5765 s=newSViv((ssize_t) image->columns); 5766 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5767 continue; 5768 } 5769 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5770 attribute); 5771 break; 5772 } 5773 case 'X': 5774 case 'x': 5775 { 5776 if (LocaleCompare(attribute,"xmp") == 0) 5777 { 5778 if (image != (Image *) NULL) 5779 { 5780 const StringInfo 5781 *profile; 5782 5783 profile=GetImageProfile(image,"xmp"); 5784 if (profile != (StringInfo *) NULL) 5785 s=newSVpv((const char *) GetStringInfoDatum(profile), 5786 GetStringInfoLength(profile)); 5787 } 5788 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5789 continue; 5790 } 5791 if (LocaleCompare(attribute,"x-resolution") == 0) 5792 { 5793 if (image != (Image *) NULL) 5794 s=newSVnv(image->resolution.x); 5795 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5796 continue; 5797 } 5798 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5799 attribute); 5800 break; 5801 } 5802 case 'Y': 5803 case 'y': 5804 { 5805 if (LocaleCompare(attribute,"y-resolution") == 0) 5806 { 5807 if (image != (Image *) NULL) 5808 s=newSVnv(image->resolution.y); 5809 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5810 continue; 5811 } 5812 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5813 attribute); 5814 break; 5815 } 5816 default: 5817 break; 5818 } 5819 if (image == (Image *) NULL) 5820 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5821 attribute) 5822 else 5823 { 5824 value=GetImageProperty(image,attribute,exception); 5825 if (value != (const char *) NULL) 5826 { 5827 s=newSVpv(value,0); 5828 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5829 } 5830 else 5831 if (*attribute != '%') 5832 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5833 attribute) 5834 else 5835 { 5836 char 5837 *meta; 5838 5839 meta=InterpretImageProperties(info ? info->image_info : 5840 (ImageInfo *) NULL,image,attribute,exception); 5841 s=newSVpv(meta,0); 5842 PUSHs(s ? sv_2mortal(s) : &sv_undef); 5843 meta=(char *) RelinquishMagickMemory(meta); 5844 } 5845 } 5846 } 5847 exception=DestroyExceptionInfo(exception); 5848 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 5849 } 5850 5851 # 5853 ############################################################################### 5854 # # 5855 # # 5856 # # 5857 # G e t A u t h e n t i c P i x e l s # 5858 # # 5859 # # 5860 # # 5861 ############################################################################### 5862 # 5863 # 5864 void * 5865 GetAuthenticPixels(ref,...) 5866 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 5867 ALIAS: 5868 getauthenticpixels = 1 5869 GetImagePixels = 2 5870 getimagepixels = 3 5871 CODE: 5872 { 5873 char 5874 *attribute; 5875 5876 ExceptionInfo 5877 *exception; 5878 5879 Image 5880 *image; 5881 5882 RectangleInfo 5883 region; 5884 5885 ssize_t 5886 i; 5887 5888 struct PackageInfo 5889 *info; 5890 5891 SV 5892 *perl_exception, 5893 *reference; 5894 5895 void 5896 *blob = NULL; 5897 5898 PERL_UNUSED_VAR(ref); 5899 PERL_UNUSED_VAR(ix); 5900 exception=AcquireExceptionInfo(); 5901 perl_exception=newSVpv("",0); 5902 if (sv_isobject(ST(0)) == 0) 5903 { 5904 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 5905 PackageName); 5906 goto PerlException; 5907 } 5908 reference=SvRV(ST(0)); 5909 5910 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 5911 if (image == (Image *) NULL) 5912 { 5913 ThrowPerlException(exception,OptionError,"NoImagesDefined", 5914 PackageName); 5915 goto PerlException; 5916 } 5917 5918 region.x=0; 5919 region.y=0; 5920 region.width=image->columns; 5921 region.height=1; 5922 if (items == 1) 5923 (void) ParseAbsoluteGeometry(SvPV(ST(1),na),®ion); 5924 for (i=2; i < items; i+=2) 5925 { 5926 attribute=(char *) SvPV(ST(i-1),na); 5927 switch (*attribute) 5928 { 5929 case 'g': 5930 case 'G': 5931 { 5932 if (LocaleCompare(attribute,"geometry") == 0) 5933 { 5934 (void) ParseAbsoluteGeometry(SvPV(ST(i),na),®ion); 5935 break; 5936 } 5937 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 5938 attribute); 5939 break; 5940 } 5941 case 'H': 5942 case 'h': 5943 { 5944 if (LocaleCompare(attribute,"height") == 0) 5945 { 5946 region.height=SvIV(ST(i)); 5947 continue; 5948 } 5949 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 5950 attribute); 5951 break; 5952 } 5953 case 'X': 5954 case 'x': 5955 { 5956 if (LocaleCompare(attribute,"x") == 0) 5957 { 5958 region.x=SvIV(ST(i)); 5959 continue; 5960 } 5961 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 5962 attribute); 5963 break; 5964 } 5965 case 'Y': 5966 case 'y': 5967 { 5968 if (LocaleCompare(attribute,"y") == 0) 5969 { 5970 region.y=SvIV(ST(i)); 5971 continue; 5972 } 5973 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 5974 attribute); 5975 break; 5976 } 5977 case 'W': 5978 case 'w': 5979 { 5980 if (LocaleCompare(attribute,"width") == 0) 5981 { 5982 region.width=SvIV(ST(i)); 5983 continue; 5984 } 5985 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 5986 attribute); 5987 break; 5988 } 5989 } 5990 } 5991 blob=(void *) GetAuthenticPixels(image,region.x,region.y,region.width, 5992 region.height,exception); 5993 if (blob != (void *) NULL) 5994 goto PerlEnd; 5995 5996 PerlException: 5997 InheritPerlException(exception,perl_exception); 5998 exception=DestroyExceptionInfo(exception); 5999 SvREFCNT_dec(perl_exception); /* throw away all errors */ 6000 6001 PerlEnd: 6002 RETVAL = blob; 6003 } 6004 OUTPUT: 6005 RETVAL 6006 6007 # 6009 ############################################################################### 6010 # # 6011 # # 6012 # # 6013 # G e t V i r t u a l P i x e l s # 6014 # # 6015 # # 6016 # # 6017 ############################################################################### 6018 # 6019 # 6020 void * 6021 GetVirtualPixels(ref,...) 6022 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6023 ALIAS: 6024 getvirtualpixels = 1 6025 AcquireImagePixels = 2 6026 acquireimagepixels = 3 6027 CODE: 6028 { 6029 char 6030 *attribute; 6031 6032 const void 6033 *blob = NULL; 6034 6035 ExceptionInfo 6036 *exception; 6037 6038 Image 6039 *image; 6040 6041 RectangleInfo 6042 region; 6043 6044 ssize_t 6045 i; 6046 6047 struct PackageInfo 6048 *info; 6049 6050 SV 6051 *perl_exception, 6052 *reference; 6053 6054 PERL_UNUSED_VAR(ref); 6055 PERL_UNUSED_VAR(ix); 6056 exception=AcquireExceptionInfo(); 6057 perl_exception=newSVpv("",0); 6058 if (sv_isobject(ST(0)) == 0) 6059 { 6060 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 6061 PackageName); 6062 goto PerlException; 6063 } 6064 reference=SvRV(ST(0)); 6065 6066 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6067 if (image == (Image *) NULL) 6068 { 6069 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6070 PackageName); 6071 goto PerlException; 6072 } 6073 6074 region.x=0; 6075 region.y=0; 6076 region.width=image->columns; 6077 region.height=1; 6078 if (items == 1) 6079 (void) ParseAbsoluteGeometry(SvPV(ST(1),na),®ion); 6080 for (i=2; i < items; i+=2) 6081 { 6082 attribute=(char *) SvPV(ST(i-1),na); 6083 switch (*attribute) 6084 { 6085 case 'g': 6086 case 'G': 6087 { 6088 if (LocaleCompare(attribute,"geometry") == 0) 6089 { 6090 (void) ParseAbsoluteGeometry(SvPV(ST(i),na),®ion); 6091 break; 6092 } 6093 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6094 attribute); 6095 break; 6096 } 6097 case 'H': 6098 case 'h': 6099 { 6100 if (LocaleCompare(attribute,"height") == 0) 6101 { 6102 region.height=SvIV(ST(i)); 6103 continue; 6104 } 6105 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 6106 attribute); 6107 break; 6108 } 6109 case 'X': 6110 case 'x': 6111 { 6112 if (LocaleCompare(attribute,"x") == 0) 6113 { 6114 region.x=SvIV(ST(i)); 6115 continue; 6116 } 6117 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 6118 attribute); 6119 break; 6120 } 6121 case 'Y': 6122 case 'y': 6123 { 6124 if (LocaleCompare(attribute,"y") == 0) 6125 { 6126 region.y=SvIV(ST(i)); 6127 continue; 6128 } 6129 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 6130 attribute); 6131 break; 6132 } 6133 case 'W': 6134 case 'w': 6135 { 6136 if (LocaleCompare(attribute,"width") == 0) 6137 { 6138 region.width=SvIV(ST(i)); 6139 continue; 6140 } 6141 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 6142 attribute); 6143 break; 6144 } 6145 } 6146 } 6147 blob=(const void *) GetVirtualPixels(image,region.x,region.y,region.width, 6148 region.height,exception); 6149 if (blob != (void *) NULL) 6150 goto PerlEnd; 6151 6152 PerlException: 6153 InheritPerlException(exception,perl_exception); 6154 exception=DestroyExceptionInfo(exception); 6155 SvREFCNT_dec(perl_exception); /* throw away all errors */ 6156 6157 PerlEnd: 6158 RETVAL = (void *) blob; 6159 } 6160 OUTPUT: 6161 RETVAL 6162 6163 # 6165 ############################################################################### 6166 # # 6167 # # 6168 # # 6169 # G e t A u t h e n t i c M e t a c o n t e n t # 6170 # # 6171 # # 6172 # # 6173 ############################################################################### 6174 # 6175 # 6176 void * 6177 GetAuthenticMetacontent(ref,...) 6178 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6179 ALIAS: 6180 getauthenticmetacontent = 1 6181 GetMetacontent = 2 6182 getmetacontent = 3 6183 CODE: 6184 { 6185 ExceptionInfo 6186 *exception; 6187 6188 Image 6189 *image; 6190 6191 struct PackageInfo 6192 *info; 6193 6194 SV 6195 *perl_exception, 6196 *reference; 6197 6198 void 6199 *blob = NULL; 6200 6201 PERL_UNUSED_VAR(ref); 6202 PERL_UNUSED_VAR(ix); 6203 exception=AcquireExceptionInfo(); 6204 perl_exception=newSVpv("",0); 6205 if (sv_isobject(ST(0)) == 0) 6206 { 6207 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 6208 PackageName); 6209 goto PerlException; 6210 } 6211 reference=SvRV(ST(0)); 6212 6213 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6214 if (image == (Image *) NULL) 6215 { 6216 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6217 PackageName); 6218 goto PerlException; 6219 } 6220 6221 blob=(void *) GetAuthenticMetacontent(image); 6222 if (blob != (void *) NULL) 6223 goto PerlEnd; 6224 6225 PerlException: 6226 InheritPerlException(exception,perl_exception); 6227 exception=DestroyExceptionInfo(exception); 6228 SvREFCNT_dec(perl_exception); /* throw away all errors */ 6229 6230 PerlEnd: 6231 RETVAL = blob; 6232 } 6233 OUTPUT: 6234 RETVAL 6235 6236 # 6238 ############################################################################### 6239 # # 6240 # # 6241 # # 6242 # G e t V i r t u a l M e t a c o n t e n t # 6243 # # 6244 # # 6245 # # 6246 ############################################################################### 6247 # 6248 # 6249 void * 6250 GetVirtualMetacontent(ref,...) 6251 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6252 ALIAS: 6253 getvirtualmetacontent = 1 6254 CODE: 6255 { 6256 ExceptionInfo 6257 *exception; 6258 6259 Image 6260 *image; 6261 6262 struct PackageInfo 6263 *info; 6264 6265 SV 6266 *perl_exception, 6267 *reference; 6268 6269 void 6270 *blob = NULL; 6271 6272 PERL_UNUSED_VAR(ref); 6273 PERL_UNUSED_VAR(ix); 6274 exception=AcquireExceptionInfo(); 6275 perl_exception=newSVpv("",0); 6276 if (sv_isobject(ST(0)) == 0) 6277 { 6278 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 6279 PackageName); 6280 goto PerlException; 6281 } 6282 reference=SvRV(ST(0)); 6283 6284 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6285 if (image == (Image *) NULL) 6286 { 6287 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6288 PackageName); 6289 goto PerlException; 6290 } 6291 6292 blob=(void *) GetVirtualMetacontent(image); 6293 if (blob != (void *) NULL) 6294 goto PerlEnd; 6295 6296 PerlException: 6297 InheritPerlException(exception,perl_exception); 6298 exception=DestroyExceptionInfo(exception); 6299 SvREFCNT_dec(perl_exception); /* throw away all errors */ 6300 6301 PerlEnd: 6302 RETVAL = blob; 6303 } 6304 OUTPUT: 6305 RETVAL 6306 6307 # 6309 ############################################################################### 6310 # # 6311 # # 6312 # # 6313 # H i s t o g r a m # 6314 # # 6315 # # 6316 # # 6317 ############################################################################### 6318 # 6319 # 6320 void 6321 Histogram(ref,...) 6322 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6323 ALIAS: 6324 HistogramImage = 1 6325 histogram = 2 6326 histogramimage = 3 6327 PPCODE: 6328 { 6329 AV 6330 *av; 6331 6332 char 6333 message[MagickPathExtent]; 6334 6335 PixelInfo 6336 *histogram; 6337 6338 ExceptionInfo 6339 *exception; 6340 6341 Image 6342 *image; 6343 6344 register ssize_t 6345 i; 6346 6347 ssize_t 6348 count; 6349 6350 struct PackageInfo 6351 *info; 6352 6353 SV 6354 *perl_exception, 6355 *reference; 6356 6357 size_t 6358 number_colors; 6359 6360 PERL_UNUSED_VAR(ref); 6361 PERL_UNUSED_VAR(ix); 6362 exception=AcquireExceptionInfo(); 6363 perl_exception=newSVpv("",0); 6364 av=NULL; 6365 if (sv_isobject(ST(0)) == 0) 6366 { 6367 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 6368 PackageName); 6369 goto PerlException; 6370 } 6371 reference=SvRV(ST(0)); 6372 av=newAV(); 6373 SvREFCNT_dec(av); 6374 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6375 if (image == (Image *) NULL) 6376 { 6377 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6378 PackageName); 6379 goto PerlException; 6380 } 6381 count=0; 6382 for ( ; image; image=image->next) 6383 { 6384 histogram=GetImageHistogram(image,&number_colors,exception); 6385 if (histogram == (PixelInfo *) NULL) 6386 continue; 6387 count+=(ssize_t) number_colors; 6388 EXTEND(sp,6*count); 6389 for (i=0; i < (ssize_t) number_colors; i++) 6390 { 6391 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", 6392 histogram[i].red); 6393 PUSHs(sv_2mortal(newSVpv(message,0))); 6394 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", 6395 histogram[i].green); 6396 PUSHs(sv_2mortal(newSVpv(message,0))); 6397 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", 6398 histogram[i].blue); 6399 PUSHs(sv_2mortal(newSVpv(message,0))); 6400 if (image->colorspace == CMYKColorspace) 6401 { 6402 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", 6403 histogram[i].black); 6404 PUSHs(sv_2mortal(newSVpv(message,0))); 6405 } 6406 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", 6407 histogram[i].alpha); 6408 PUSHs(sv_2mortal(newSVpv(message,0))); 6409 (void) FormatLocaleString(message,MagickPathExtent,"%.20g",(double) 6410 histogram[i].count); 6411 PUSHs(sv_2mortal(newSVpv(message,0))); 6412 } 6413 histogram=(PixelInfo *) RelinquishMagickMemory(histogram); 6414 } 6415 6416 PerlException: 6417 InheritPerlException(exception,perl_exception); 6418 exception=DestroyExceptionInfo(exception); 6419 SvREFCNT_dec(perl_exception); 6420 } 6421 6422 # 6424 ############################################################################### 6425 # # 6426 # # 6427 # # 6428 # G e t P i x e l # 6429 # # 6430 # # 6431 # # 6432 ############################################################################### 6433 # 6434 # 6435 void 6436 GetPixel(ref,...) 6437 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6438 ALIAS: 6439 getpixel = 1 6440 getPixel = 2 6441 PPCODE: 6442 { 6443 AV 6444 *av; 6445 6446 char 6447 *attribute; 6448 6449 ExceptionInfo 6450 *exception; 6451 6452 Image 6453 *image; 6454 6455 MagickBooleanType 6456 normalize; 6457 6458 RectangleInfo 6459 region; 6460 6461 register const Quantum 6462 *p; 6463 6464 register ssize_t 6465 i; 6466 6467 ssize_t 6468 option; 6469 6470 struct PackageInfo 6471 *info; 6472 6473 SV 6474 *perl_exception, 6475 *reference; /* reference is the SV* of ref=SvIV(reference) */ 6476 6477 PERL_UNUSED_VAR(ref); 6478 PERL_UNUSED_VAR(ix); 6479 exception=AcquireExceptionInfo(); 6480 perl_exception=newSVpv("",0); 6481 reference=SvRV(ST(0)); 6482 av=(AV *) reference; 6483 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 6484 exception); 6485 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6486 if (image == (Image *) NULL) 6487 { 6488 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6489 PackageName); 6490 goto PerlException; 6491 } 6492 normalize=MagickTrue; 6493 region.x=0; 6494 region.y=0; 6495 region.width=image->columns; 6496 region.height=1; 6497 if (items == 1) 6498 (void) ParseAbsoluteGeometry(SvPV(ST(1),na),®ion); 6499 for (i=2; i < items; i+=2) 6500 { 6501 attribute=(char *) SvPV(ST(i-1),na); 6502 switch (*attribute) 6503 { 6504 case 'C': 6505 case 'c': 6506 { 6507 if (LocaleCompare(attribute,"channel") == 0) 6508 { 6509 ssize_t 6510 option; 6511 6512 option=ParseChannelOption(SvPV(ST(i),na)); 6513 if (option < 0) 6514 { 6515 ThrowPerlException(exception,OptionError,"UnrecognizedType", 6516 SvPV(ST(i),na)); 6517 return; 6518 } 6519 (void) SetPixelChannelMask(image,(ChannelType) option); 6520 break; 6521 } 6522 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6523 attribute); 6524 break; 6525 } 6526 case 'g': 6527 case 'G': 6528 { 6529 if (LocaleCompare(attribute,"geometry") == 0) 6530 { 6531 (void) ParseAbsoluteGeometry(SvPV(ST(i),na),®ion); 6532 break; 6533 } 6534 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6535 attribute); 6536 break; 6537 } 6538 case 'N': 6539 case 'n': 6540 { 6541 if (LocaleCompare(attribute,"normalize") == 0) 6542 { 6543 option=ParseCommandOption(MagickBooleanOptions,MagickFalse, 6544 SvPV(ST(i),na)); 6545 if (option < 0) 6546 { 6547 ThrowPerlException(exception,OptionError,"UnrecognizedType", 6548 SvPV(ST(i),na)); 6549 break; 6550 } 6551 normalize=option != 0 ? MagickTrue : MagickFalse; 6552 break; 6553 } 6554 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6555 attribute); 6556 break; 6557 } 6558 case 'x': 6559 case 'X': 6560 { 6561 if (LocaleCompare(attribute,"x") == 0) 6562 { 6563 region.x=SvIV(ST(i)); 6564 break; 6565 } 6566 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6567 attribute); 6568 break; 6569 } 6570 case 'y': 6571 case 'Y': 6572 { 6573 if (LocaleCompare(attribute,"y") == 0) 6574 { 6575 region.y=SvIV(ST(i)); 6576 break; 6577 } 6578 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6579 attribute); 6580 break; 6581 } 6582 default: 6583 { 6584 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6585 attribute); 6586 break; 6587 } 6588 } 6589 } 6590 p=GetVirtualPixels(image,region.x,region.y,1,1,exception); 6591 if (p == (const Quantum *) NULL) 6592 PUSHs(&sv_undef); 6593 else 6594 { 6595 double 6596 scale; 6597 6598 scale=1.0; 6599 if (normalize != MagickFalse) 6600 scale=1.0/QuantumRange; 6601 if ((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) 6602 PUSHs(sv_2mortal(newSVnv(scale*GetPixelRed(image,p)))); 6603 if ((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) 6604 PUSHs(sv_2mortal(newSVnv(scale*GetPixelGreen(image,p)))); 6605 if ((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) 6606 PUSHs(sv_2mortal(newSVnv(scale*GetPixelBlue(image,p)))); 6607 if (((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) && 6608 (image->colorspace == CMYKColorspace)) 6609 PUSHs(sv_2mortal(newSVnv(scale*GetPixelBlack(image,p)))); 6610 if ((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) 6611 PUSHs(sv_2mortal(newSVnv(scale*GetPixelAlpha(image,p)))); 6612 } 6613 6614 PerlException: 6615 InheritPerlException(exception,perl_exception); 6616 exception=DestroyExceptionInfo(exception); 6617 SvREFCNT_dec(perl_exception); 6618 } 6619 6620 # 6622 ############################################################################### 6623 # # 6624 # # 6625 # # 6626 # G e t P i x e l s # 6627 # # 6628 # # 6629 # # 6630 ############################################################################### 6631 # 6632 # 6633 void 6634 GetPixels(ref,...) 6635 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6636 ALIAS: 6637 getpixels = 1 6638 getPixels = 2 6639 PPCODE: 6640 { 6641 AV 6642 *av; 6643 6644 char 6645 *attribute; 6646 6647 const char 6648 *map; 6649 6650 ExceptionInfo 6651 *exception; 6652 6653 Image 6654 *image; 6655 6656 MagickBooleanType 6657 normalize, 6658 status; 6659 6660 RectangleInfo 6661 region; 6662 6663 register ssize_t 6664 i; 6665 6666 ssize_t 6667 option; 6668 6669 struct PackageInfo 6670 *info; 6671 6672 SV 6673 *perl_exception, 6674 *reference; /* reference is the SV* of ref=SvIV(reference) */ 6675 6676 PERL_UNUSED_VAR(ref); 6677 PERL_UNUSED_VAR(ix); 6678 exception=AcquireExceptionInfo(); 6679 perl_exception=newSVpv("",0); 6680 reference=SvRV(ST(0)); 6681 av=(AV *) reference; 6682 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 6683 exception); 6684 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6685 if (image == (Image *) NULL) 6686 { 6687 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6688 PackageName); 6689 goto PerlException; 6690 } 6691 map="RGB"; 6692 if (image->alpha_trait != UndefinedPixelTrait) 6693 map="RGBA"; 6694 if (image->colorspace == CMYKColorspace) 6695 { 6696 map="CMYK"; 6697 if (image->alpha_trait != UndefinedPixelTrait) 6698 map="CMYKA"; 6699 } 6700 normalize=MagickFalse; 6701 region.x=0; 6702 region.y=0; 6703 region.width=image->columns; 6704 region.height=1; 6705 if (items == 1) 6706 (void) ParseAbsoluteGeometry(SvPV(ST(1),na),®ion); 6707 for (i=2; i < items; i+=2) 6708 { 6709 attribute=(char *) SvPV(ST(i-1),na); 6710 switch (*attribute) 6711 { 6712 case 'g': 6713 case 'G': 6714 { 6715 if (LocaleCompare(attribute,"geometry") == 0) 6716 { 6717 (void) ParseAbsoluteGeometry(SvPV(ST(i),na),®ion); 6718 break; 6719 } 6720 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6721 attribute); 6722 break; 6723 } 6724 case 'H': 6725 case 'h': 6726 { 6727 if (LocaleCompare(attribute,"height") == 0) 6728 { 6729 region.height=SvIV(ST(i)); 6730 break; 6731 } 6732 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6733 attribute); 6734 break; 6735 } 6736 case 'M': 6737 case 'm': 6738 { 6739 if (LocaleCompare(attribute,"map") == 0) 6740 { 6741 map=SvPV(ST(i),na); 6742 break; 6743 } 6744 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6745 attribute); 6746 break; 6747 } 6748 case 'N': 6749 case 'n': 6750 { 6751 if (LocaleCompare(attribute,"normalize") == 0) 6752 { 6753 option=ParseCommandOption(MagickBooleanOptions,MagickFalse, 6754 SvPV(ST(i),na)); 6755 if (option < 0) 6756 { 6757 ThrowPerlException(exception,OptionError,"UnrecognizedType", 6758 SvPV(ST(i),na)); 6759 break; 6760 } 6761 normalize=option != 0 ? MagickTrue : MagickFalse; 6762 break; 6763 } 6764 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6765 attribute); 6766 break; 6767 } 6768 case 'W': 6769 case 'w': 6770 { 6771 if (LocaleCompare(attribute,"width") == 0) 6772 { 6773 region.width=SvIV(ST(i)); 6774 break; 6775 } 6776 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6777 attribute); 6778 break; 6779 } 6780 case 'x': 6781 case 'X': 6782 { 6783 if (LocaleCompare(attribute,"x") == 0) 6784 { 6785 region.x=SvIV(ST(i)); 6786 break; 6787 } 6788 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6789 attribute); 6790 break; 6791 } 6792 case 'y': 6793 case 'Y': 6794 { 6795 if (LocaleCompare(attribute,"y") == 0) 6796 { 6797 region.y=SvIV(ST(i)); 6798 break; 6799 } 6800 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6801 attribute); 6802 break; 6803 } 6804 default: 6805 { 6806 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 6807 attribute); 6808 break; 6809 } 6810 } 6811 } 6812 if (normalize != MagickFalse) 6813 { 6814 float 6815 *pixels; 6816 6817 pixels=(float *) AcquireQuantumMemory(strlen(map)*region.width, 6818 region.height*sizeof(*pixels)); 6819 if (pixels == (float *) NULL) 6820 { 6821 ThrowPerlException(exception,ResourceLimitError, 6822 "MemoryAllocationFailed",PackageName); 6823 goto PerlException; 6824 } 6825 status=ExportImagePixels(image,region.x,region.y,region.width, 6826 region.height,map,FloatPixel,pixels,exception); 6827 if (status == MagickFalse) 6828 PUSHs(&sv_undef); 6829 else 6830 { 6831 EXTEND(sp,strlen(map)*region.width*region.height); 6832 for (i=0; i < (ssize_t) (strlen(map)*region.width*region.height); i++) 6833 PUSHs(sv_2mortal(newSVnv(pixels[i]))); 6834 } 6835 pixels=(float *) RelinquishMagickMemory(pixels); 6836 } 6837 else 6838 { 6839 Quantum 6840 *pixels; 6841 6842 pixels=(Quantum *) AcquireQuantumMemory(strlen(map)*region.width, 6843 region.height*sizeof(*pixels)); 6844 if (pixels == (Quantum *) NULL) 6845 { 6846 ThrowPerlException(exception,ResourceLimitError, 6847 "MemoryAllocationFailed",PackageName); 6848 goto PerlException; 6849 } 6850 status=ExportImagePixels(image,region.x,region.y,region.width, 6851 region.height,map,QuantumPixel,pixels,exception); 6852 if (status == MagickFalse) 6853 PUSHs(&sv_undef); 6854 else 6855 { 6856 EXTEND(sp,strlen(map)*region.width*region.height); 6857 for (i=0; i < (ssize_t) (strlen(map)*region.width*region.height); i++) 6858 PUSHs(sv_2mortal(newSViv(pixels[i]))); 6859 } 6860 pixels=(Quantum *) RelinquishMagickMemory(pixels); 6861 } 6862 6863 PerlException: 6864 InheritPerlException(exception,perl_exception); 6865 exception=DestroyExceptionInfo(exception); 6866 SvREFCNT_dec(perl_exception); 6867 } 6868 6869 # 6871 ############################################################################### 6872 # # 6873 # # 6874 # # 6875 # I m a g e T o B l o b # 6876 # # 6877 # # 6878 # # 6879 ############################################################################### 6880 # 6881 # 6882 void 6883 ImageToBlob(ref,...) 6884 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6885 ALIAS: 6886 ImageToBlob = 1 6887 imagetoblob = 2 6888 toblob = 3 6889 blob = 4 6890 PPCODE: 6891 { 6892 char 6893 filename[MagickPathExtent]; 6894 6895 ExceptionInfo 6896 *exception; 6897 6898 Image 6899 *image, 6900 *next; 6901 6902 register ssize_t 6903 i; 6904 6905 struct PackageInfo 6906 *info, 6907 *package_info; 6908 6909 size_t 6910 length; 6911 6912 ssize_t 6913 scene; 6914 6915 SV 6916 *perl_exception, 6917 *reference; 6918 6919 void 6920 *blob; 6921 6922 PERL_UNUSED_VAR(ref); 6923 PERL_UNUSED_VAR(ix); 6924 exception=AcquireExceptionInfo(); 6925 perl_exception=newSVpv("",0); 6926 package_info=(struct PackageInfo *) NULL; 6927 if (sv_isobject(ST(0)) == 0) 6928 { 6929 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 6930 PackageName); 6931 goto PerlException; 6932 } 6933 reference=SvRV(ST(0)); 6934 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 6935 if (image == (Image *) NULL) 6936 { 6937 ThrowPerlException(exception,OptionError,"NoImagesDefined", 6938 PackageName); 6939 goto PerlException; 6940 } 6941 package_info=ClonePackageInfo(info,exception); 6942 for (i=2; i < items; i+=2) 6943 SetAttribute(aTHX_ package_info,image,SvPV(ST(i-1),na),ST(i),exception); 6944 (void) CopyMagickString(filename,package_info->image_info->filename, 6945 MagickPathExtent); 6946 scene=0; 6947 for (next=image; next; next=next->next) 6948 { 6949 (void) CopyMagickString(next->filename,filename,MagickPathExtent); 6950 next->scene=scene++; 6951 } 6952 SetImageInfo(package_info->image_info,(unsigned int) 6953 GetImageListLength(image),exception); 6954 EXTEND(sp,(ssize_t) GetImageListLength(image)); 6955 for ( ; image; image=image->next) 6956 { 6957 length=0; 6958 blob=ImagesToBlob(package_info->image_info,image,&length,exception); 6959 if (blob != (char *) NULL) 6960 { 6961 PUSHs(sv_2mortal(newSVpv((const char *) blob,length))); 6962 blob=(unsigned char *) RelinquishMagickMemory(blob); 6963 } 6964 if (package_info->image_info->adjoin) 6965 break; 6966 } 6967 6968 PerlException: 6969 if (package_info != (struct PackageInfo *) NULL) 6970 DestroyPackageInfo(package_info); 6971 InheritPerlException(exception,perl_exception); 6972 exception=DestroyExceptionInfo(exception); 6973 SvREFCNT_dec(perl_exception); /* throw away all errors */ 6974 } 6975 6976 # 6978 ############################################################################### 6979 # # 6980 # # 6981 # # 6982 # L a y e r s # 6983 # # 6984 # # 6985 # # 6986 ############################################################################### 6987 # 6988 # 6989 void 6990 Layers(ref,...) 6991 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 6992 ALIAS: 6993 Layers = 1 6994 layers = 2 6995 OptimizeImageLayers = 3 6996 optimizelayers = 4 6997 optimizeimagelayers = 5 6998 PPCODE: 6999 { 7000 AV 7001 *av; 7002 7003 char 7004 *attribute; 7005 7006 CompositeOperator 7007 compose; 7008 7009 ExceptionInfo 7010 *exception; 7011 7012 HV 7013 *hv; 7014 7015 Image 7016 *image, 7017 *layers; 7018 7019 LayerMethod 7020 method; 7021 7022 register ssize_t 7023 i; 7024 7025 ssize_t 7026 option, 7027 sp; 7028 7029 struct PackageInfo 7030 *info; 7031 7032 SV 7033 *av_reference, 7034 *perl_exception, 7035 *reference, 7036 *rv, 7037 *sv; 7038 7039 PERL_UNUSED_VAR(ref); 7040 PERL_UNUSED_VAR(ix); 7041 exception=AcquireExceptionInfo(); 7042 perl_exception=newSVpv("",0); 7043 sv=NULL; 7044 if (sv_isobject(ST(0)) == 0) 7045 { 7046 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 7047 PackageName); 7048 goto PerlException; 7049 } 7050 reference=SvRV(ST(0)); 7051 hv=SvSTASH(reference); 7052 av=newAV(); 7053 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 7054 SvREFCNT_dec(av); 7055 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 7056 if (image == (Image *) NULL) 7057 { 7058 ThrowPerlException(exception,OptionError,"NoImagesDefined", 7059 PackageName); 7060 goto PerlException; 7061 } 7062 compose=image->compose; 7063 method=OptimizeLayer; 7064 for (i=2; i < items; i+=2) 7065 { 7066 attribute=(char *) SvPV(ST(i-1),na); 7067 switch (*attribute) 7068 { 7069 case 'C': 7070 case 'c': 7071 { 7072 if (LocaleCompare(attribute,"compose") == 0) 7073 { 7074 sp=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 7075 MagickComposeOptions,MagickFalse,SvPV(ST(i),na)); 7076 if (sp < 0) 7077 { 7078 ThrowPerlException(exception,OptionError,"UnrecognizedType", 7079 SvPV(ST(i),na)); 7080 break; 7081 } 7082 compose=(CompositeOperator) sp; 7083 break; 7084 } 7085 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 7086 attribute); 7087 break; 7088 } 7089 case 'M': 7090 case 'm': 7091 { 7092 if (LocaleCompare(attribute,"method") == 0) 7093 { 7094 option=ParseCommandOption(MagickLayerOptions,MagickFalse, 7095 SvPV(ST(i),na)); 7096 if (option < 0) 7097 { 7098 ThrowPerlException(exception,OptionError,"UnrecognizedType", 7099 SvPV(ST(i),na)); 7100 break; 7101 } 7102 method=(LayerMethod) option; 7103 break; 7104 } 7105 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 7106 attribute); 7107 break; 7108 } 7109 default: 7110 { 7111 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 7112 attribute); 7113 break; 7114 } 7115 } 7116 } 7117 layers=(Image *) NULL; 7118 switch (method) 7119 { 7120 case CompareAnyLayer: 7121 case CompareClearLayer: 7122 case CompareOverlayLayer: 7123 default: 7124 { 7125 layers=CompareImagesLayers(image,method,exception); 7126 break; 7127 } 7128 case MergeLayer: 7129 case FlattenLayer: 7130 case MosaicLayer: 7131 { 7132 layers=MergeImageLayers(image,method,exception); 7133 break; 7134 } 7135 case DisposeLayer: 7136 { 7137 layers=DisposeImages(image,exception); 7138 break; 7139 } 7140 case OptimizeImageLayer: 7141 { 7142 layers=OptimizeImageLayers(image,exception); 7143 break; 7144 } 7145 case OptimizePlusLayer: 7146 { 7147 layers=OptimizePlusImageLayers(image,exception); 7148 break; 7149 } 7150 case OptimizeTransLayer: 7151 { 7152 OptimizeImageTransparency(image,exception); 7153 break; 7154 } 7155 case RemoveDupsLayer: 7156 { 7157 RemoveDuplicateLayers(&image,exception); 7158 break; 7159 } 7160 case RemoveZeroLayer: 7161 { 7162 RemoveZeroDelayLayers(&image,exception); 7163 break; 7164 } 7165 case OptimizeLayer: 7166 { 7167 QuantizeInfo 7168 *quantize_info; 7169 7170 /* 7171 General Purpose, GIF Animation Optimizer. 7172 */ 7173 layers=CoalesceImages(image,exception); 7174 if (layers == (Image *) NULL) 7175 break; 7176 image=layers; 7177 layers=OptimizeImageLayers(image,exception); 7178 if (layers == (Image *) NULL) 7179 break; 7180 image=DestroyImageList(image); 7181 image=layers; 7182 layers=(Image *) NULL; 7183 OptimizeImageTransparency(image,exception); 7184 quantize_info=AcquireQuantizeInfo(info->image_info); 7185 (void) RemapImages(quantize_info,image,(Image *) NULL,exception); 7186 quantize_info=DestroyQuantizeInfo(quantize_info); 7187 break; 7188 } 7189 case CompositeLayer: 7190 { 7191 Image 7192 *source; 7193 7194 RectangleInfo 7195 geometry; 7196 7197 /* 7198 Split image sequence at the first 'NULL:' image. 7199 */ 7200 source=image; 7201 while (source != (Image *) NULL) 7202 { 7203 source=GetNextImageInList(source); 7204 if ((source != (Image *) NULL) && 7205 (LocaleCompare(source->magick,"NULL") == 0)) 7206 break; 7207 } 7208 if (source != (Image *) NULL) 7209 { 7210 if ((GetPreviousImageInList(source) == (Image *) NULL) || 7211 (GetNextImageInList(source) == (Image *) NULL)) 7212 source=(Image *) NULL; 7213 else 7214 { 7215 /* 7216 Separate the two lists, junk the null: image. 7217 */ 7218 source=SplitImageList(source->previous); 7219 DeleteImageFromList(&source); 7220 } 7221 } 7222 if (source == (Image *) NULL) 7223 { 7224 (void) ThrowMagickException(exception,GetMagickModule(), 7225 OptionError,"MissingNullSeparator","layers Composite"); 7226 break; 7227 } 7228 /* 7229 Adjust offset with gravity and virtual canvas. 7230 */ 7231 SetGeometry(image,&geometry); 7232 (void) ParseAbsoluteGeometry(image->geometry,&geometry); 7233 geometry.width=source->page.width != 0 ? source->page.width : 7234 source->columns; 7235 geometry.height=source->page.height != 0 ? source->page.height : 7236 source->rows; 7237 GravityAdjustGeometry(image->page.width != 0 ? image->page.width : 7238 image->columns,image->page.height != 0 ? image->page.height : 7239 image->rows,image->gravity,&geometry); 7240 CompositeLayers(image,compose,source,geometry.x,geometry.y,exception); 7241 source=DestroyImageList(source); 7242 break; 7243 } 7244 } 7245 if (layers != (Image *) NULL) 7246 image=layers; 7247 else 7248 image=CloneImage(image,0,0,MagickTrue,exception); 7249 if (image == (Image *) NULL) 7250 goto PerlException; 7251 for ( ; image; image=image->next) 7252 { 7253 AddImageToRegistry(sv,image); 7254 rv=newRV(sv); 7255 av_push(av,sv_bless(rv,hv)); 7256 SvREFCNT_dec(sv); 7257 } 7258 exception=DestroyExceptionInfo(exception); 7259 ST(0)=av_reference; 7260 SvREFCNT_dec(perl_exception); 7261 XSRETURN(1); 7262 7263 PerlException: 7264 InheritPerlException(exception,perl_exception); 7265 exception=DestroyExceptionInfo(exception); 7266 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 7267 SvPOK_on(perl_exception); 7268 ST(0)=sv_2mortal(perl_exception); 7269 XSRETURN(1); 7270 } 7271 7272 # 7274 ############################################################################### 7275 # # 7276 # # 7277 # # 7278 # M a g i c k T o M i m e # 7279 # # 7280 # # 7281 # # 7282 ############################################################################### 7283 # 7284 # 7285 SV * 7286 MagickToMime(ref,name) 7287 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 7288 char *name 7289 ALIAS: 7290 magicktomime = 1 7291 CODE: 7292 { 7293 char 7294 *mime; 7295 7296 PERL_UNUSED_VAR(ref); 7297 PERL_UNUSED_VAR(ix); 7298 mime=MagickToMime(name); 7299 RETVAL=newSVpv(mime,0); 7300 mime=(char *) RelinquishMagickMemory(mime); 7301 } 7302 OUTPUT: 7303 RETVAL 7304 7305 # 7307 ############################################################################### 7308 # # 7309 # # 7310 # # 7311 # M o g r i f y # 7312 # # 7313 # # 7314 # # 7315 ############################################################################### 7316 # 7317 # 7318 void 7319 Mogrify(ref,...) 7320 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 7321 ALIAS: 7322 Comment = 1 7323 CommentImage = 2 7324 Label = 3 7325 LabelImage = 4 7326 AddNoise = 5 7327 AddNoiseImage = 6 7328 Colorize = 7 7329 ColorizeImage = 8 7330 Border = 9 7331 BorderImage = 10 7332 Blur = 11 7333 BlurImage = 12 7334 Chop = 13 7335 ChopImage = 14 7336 Crop = 15 7337 CropImage = 16 7338 Despeckle = 17 7339 DespeckleImage = 18 7340 Edge = 19 7341 EdgeImage = 20 7342 Emboss = 21 7343 EmbossImage = 22 7344 Enhance = 23 7345 EnhanceImage = 24 7346 Flip = 25 7347 FlipImage = 26 7348 Flop = 27 7349 FlopImage = 28 7350 Frame = 29 7351 FrameImage = 30 7352 Implode = 31 7353 ImplodeImage = 32 7354 Magnify = 33 7355 MagnifyImage = 34 7356 MedianFilter = 35 7357 MedianConvolveImage = 36 7358 Minify = 37 7359 MinifyImage = 38 7360 OilPaint = 39 7361 OilPaintImage = 40 7362 ReduceNoise = 41 7363 ReduceNoiseImage = 42 7364 Roll = 43 7365 RollImage = 44 7366 Rotate = 45 7367 RotateImage = 46 7368 Sample = 47 7369 SampleImage = 48 7370 Scale = 49 7371 ScaleImage = 50 7372 Shade = 51 7373 ShadeImage = 52 7374 Sharpen = 53 7375 SharpenImage = 54 7376 Shear = 55 7377 ShearImage = 56 7378 Spread = 57 7379 SpreadImage = 58 7380 Swirl = 59 7381 SwirlImage = 60 7382 Resize = 61 7383 ResizeImage = 62 7384 Zoom = 63 7385 ZoomImage = 64 7386 Annotate = 65 7387 AnnotateImage = 66 7388 ColorFloodfill = 67 7389 ColorFloodfillImage= 68 7390 Composite = 69 7391 CompositeImage = 70 7392 Contrast = 71 7393 ContrastImage = 72 7394 CycleColormap = 73 7395 CycleColormapImage = 74 7396 Draw = 75 7397 DrawImage = 76 7398 Equalize = 77 7399 EqualizeImage = 78 7400 Gamma = 79 7401 GammaImage = 80 7402 Map = 81 7403 MapImage = 82 7404 MatteFloodfill = 83 7405 MatteFloodfillImage= 84 7406 Modulate = 85 7407 ModulateImage = 86 7408 Negate = 87 7409 NegateImage = 88 7410 Normalize = 89 7411 NormalizeImage = 90 7412 NumberColors = 91 7413 NumberColorsImage = 92 7414 Opaque = 93 7415 OpaqueImage = 94 7416 Quantize = 95 7417 QuantizeImage = 96 7418 Raise = 97 7419 RaiseImage = 98 7420 Segment = 99 7421 SegmentImage = 100 7422 Signature = 101 7423 SignatureImage = 102 7424 Solarize = 103 7425 SolarizeImage = 104 7426 Sync = 105 7427 SyncImage = 106 7428 Texture = 107 7429 TextureImage = 108 7430 Evaluate = 109 7431 EvaluateImage = 110 7432 Transparent = 111 7433 TransparentImage = 112 7434 Threshold = 113 7435 ThresholdImage = 114 7436 Charcoal = 115 7437 CharcoalImage = 116 7438 Trim = 117 7439 TrimImage = 118 7440 Wave = 119 7441 WaveImage = 120 7442 Separate = 121 7443 SeparateImage = 122 7444 Stereo = 125 7445 StereoImage = 126 7446 Stegano = 127 7447 SteganoImage = 128 7448 Deconstruct = 129 7449 DeconstructImage = 130 7450 GaussianBlur = 131 7451 GaussianBlurImage = 132 7452 Convolve = 133 7453 ConvolveImage = 134 7454 Profile = 135 7455 ProfileImage = 136 7456 UnsharpMask = 137 7457 UnsharpMaskImage = 138 7458 MotionBlur = 139 7459 MotionBlurImage = 140 7460 OrderedDither = 141 7461 OrderedDitherImage = 142 7462 Shave = 143 7463 ShaveImage = 144 7464 Level = 145 7465 LevelImage = 146 7466 Clip = 147 7467 ClipImage = 148 7468 AffineTransform = 149 7469 AffineTransformImage = 150 7470 Difference = 151 7471 DifferenceImage = 152 7472 AdaptiveThreshold = 153 7473 AdaptiveThresholdImage = 154 7474 Resample = 155 7475 ResampleImage = 156 7476 Describe = 157 7477 DescribeImage = 158 7478 BlackThreshold = 159 7479 BlackThresholdImage= 160 7480 WhiteThreshold = 161 7481 WhiteThresholdImage= 162 7482 RotationalBlur = 163 7483 RotationalBlurImage= 164 7484 Thumbnail = 165 7485 ThumbnailImage = 166 7486 Strip = 167 7487 StripImage = 168 7488 Tint = 169 7489 TintImage = 170 7490 Channel = 171 7491 ChannelImage = 172 7492 Splice = 173 7493 SpliceImage = 174 7494 Posterize = 175 7495 PosterizeImage = 176 7496 Shadow = 177 7497 ShadowImage = 178 7498 Identify = 179 7499 IdentifyImage = 180 7500 SepiaTone = 181 7501 SepiaToneImage = 182 7502 SigmoidalContrast = 183 7503 SigmoidalContrastImage = 184 7504 Extent = 185 7505 ExtentImage = 186 7506 Vignette = 187 7507 VignetteImage = 188 7508 ContrastStretch = 189 7509 ContrastStretchImage = 190 7510 Sans0 = 191 7511 Sans0Image = 192 7512 Sans1 = 193 7513 Sans1Image = 194 7514 AdaptiveSharpen = 195 7515 AdaptiveSharpenImage = 196 7516 Transpose = 197 7517 TransposeImage = 198 7518 Transverse = 199 7519 TransverseImage = 200 7520 AutoOrient = 201 7521 AutoOrientImage = 202 7522 AdaptiveBlur = 203 7523 AdaptiveBlurImage = 204 7524 Sketch = 205 7525 SketchImage = 206 7526 UniqueColors = 207 7527 UniqueColorsImage = 208 7528 AdaptiveResize = 209 7529 AdaptiveResizeImage= 210 7530 ClipMask = 211 7531 ClipMaskImage = 212 7532 LinearStretch = 213 7533 LinearStretchImage = 214 7534 ColorMatrix = 215 7535 ColorMatrixImage = 216 7536 Mask = 217 7537 MaskImage = 218 7538 Polaroid = 219 7539 PolaroidImage = 220 7540 FloodfillPaint = 221 7541 FloodfillPaintImage= 222 7542 Distort = 223 7543 DistortImage = 224 7544 Clut = 225 7545 ClutImage = 226 7546 LiquidRescale = 227 7547 LiquidRescaleImage = 228 7548 Encipher = 229 7549 EncipherImage = 230 7550 Decipher = 231 7551 DecipherImage = 232 7552 Deskew = 233 7553 DeskewImage = 234 7554 Remap = 235 7555 RemapImage = 236 7556 SparseColor = 237 7557 SparseColorImage = 238 7558 Function = 239 7559 FunctionImage = 240 7560 SelectiveBlur = 241 7561 SelectiveBlurImage = 242 7562 HaldClut = 243 7563 HaldClutImage = 244 7564 BlueShift = 245 7565 BlueShiftImage = 246 7566 ForwardFourierTransform = 247 7567 ForwardFourierTransformImage = 248 7568 InverseFourierTransform = 249 7569 InverseFourierTransformImage = 250 7570 ColorDecisionList = 251 7571 ColorDecisionListImage = 252 7572 AutoGamma = 253 7573 AutoGammaImage = 254 7574 AutoLevel = 255 7575 AutoLevelImage = 256 7576 LevelColors = 257 7577 LevelImageColors = 258 7578 Clamp = 259 7579 ClampImage = 260 7580 BrightnessContrast = 261 7581 BrightnessContrastImage = 262 7582 Morphology = 263 7583 MorphologyImage = 264 7584 Mode = 265 7585 ModeImage = 266 7586 Statistic = 267 7587 StatisticImage = 268 7588 Perceptible = 269 7589 PerceptibleImage = 270 7590 Poly = 271 7591 PolyImage = 272 7592 Grayscale = 273 7593 GrayscaleImage = 274 7594 CannyEdge = 275 7595 CannyEdgeImage = 276 7596 HoughLine = 277 7597 HoughLineImage = 278 7598 MeanShift = 279 7599 MeanShiftImage = 280 7600 Kuwahara = 281 7601 KuwaharaImage = 282 7602 ConnectedComponent = 283 7603 ConnectedComponentImage = 284 7604 CopyPixels = 285 7605 CopyImagePixels = 286 7606 Color = 287 7607 ColorImage = 288 7608 WaveletDenoise = 289 7609 WaveletDenoiseImage= 290 7610 MogrifyRegion = 666 7611 PPCODE: 7612 { 7613 AffineMatrix 7614 affine, 7615 current; 7616 7617 char 7618 attribute_flag[MaxArguments], 7619 message[MagickPathExtent]; 7620 7621 ChannelType 7622 channel, 7623 channel_mask; 7624 7625 CompositeOperator 7626 compose; 7627 7628 const char 7629 *attribute, 7630 *value; 7631 7632 double 7633 angle; 7634 7635 ExceptionInfo 7636 *exception; 7637 7638 GeometryInfo 7639 geometry_info; 7640 7641 Image 7642 *image, 7643 *next, 7644 *region_image; 7645 7646 MagickBooleanType 7647 status; 7648 7649 MagickStatusType 7650 flags; 7651 7652 PixelInfo 7653 fill_color; 7654 7655 RectangleInfo 7656 geometry, 7657 region_info; 7658 7659 register ssize_t 7660 i; 7661 7662 ssize_t 7663 base, 7664 j, 7665 number_images; 7666 7667 struct Methods 7668 *rp; 7669 7670 struct PackageInfo 7671 *info; 7672 7673 SV 7674 *perl_exception, 7675 **pv, 7676 *reference, 7677 **reference_vector; 7678 7679 struct ArgumentList 7680 argument_list[MaxArguments]; 7681 7682 PERL_UNUSED_VAR(ref); 7683 PERL_UNUSED_VAR(ix); 7684 exception=AcquireExceptionInfo(); 7685 perl_exception=newSVpv("",0); 7686 reference_vector=NULL; 7687 region_image=NULL; 7688 number_images=0; 7689 base=2; 7690 if (sv_isobject(ST(0)) == 0) 7691 { 7692 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 7693 PackageName); 7694 goto PerlException; 7695 } 7696 reference=SvRV(ST(0)); 7697 region_info.width=0; 7698 region_info.height=0; 7699 region_info.x=0; 7700 region_info.y=0; 7701 region_image=(Image *) NULL; 7702 image=SetupList(aTHX_ reference,&info,&reference_vector,exception); 7703 if (ix && (ix != 666)) 7704 { 7705 /* 7706 Called as Method(...) 7707 */ 7708 ix=(ix+1)/2; 7709 rp=(&Methods[ix-1]); 7710 attribute=rp->name; 7711 } 7712 else 7713 { 7714 /* 7715 Called as Mogrify("Method",...) 7716 */ 7717 attribute=(char *) SvPV(ST(1),na); 7718 if (ix) 7719 { 7720 flags=ParseGravityGeometry(image,attribute,®ion_info,exception); 7721 attribute=(char *) SvPV(ST(2),na); 7722 base++; 7723 } 7724 for (rp=Methods; ; rp++) 7725 { 7726 if (rp >= EndOf(Methods)) 7727 { 7728 ThrowPerlException(exception,OptionError, 7729 "UnrecognizedPerlMagickMethod",attribute); 7730 goto PerlException; 7731 } 7732 if (strEQcase(attribute,rp->name)) 7733 break; 7734 } 7735 ix=rp-Methods+1; 7736 base++; 7737 } 7738 if (image == (Image *) NULL) 7739 { 7740 ThrowPerlException(exception,OptionError,"NoImagesDefined",attribute); 7741 goto PerlException; 7742 } 7743 Zero(&argument_list,NumberOf(argument_list),struct ArgumentList); 7744 Zero(&attribute_flag,NumberOf(attribute_flag),char); 7745 for (i=base; (i < items) || ((i == items) && (base == items)); i+=2) 7746 { 7747 Arguments 7748 *pp, 7749 *qq; 7750 7751 ssize_t 7752 ssize_test; 7753 7754 struct ArgumentList 7755 *al; 7756 7757 SV 7758 *sv; 7759 7760 sv=NULL; 7761 ssize_test=0; 7762 pp=(Arguments *) NULL; 7763 qq=rp->arguments; 7764 if (i == items) 7765 { 7766 pp=rp->arguments, 7767 sv=ST(i-1); 7768 } 7769 else 7770 for (sv=ST(i), attribute=(char *) SvPV(ST(i-1),na); ; qq++) 7771 { 7772 if ((qq >= EndOf(rp->arguments)) || (qq->method == NULL)) 7773 break; 7774 if (strEQcase(attribute,qq->method) > ssize_test) 7775 { 7776 pp=qq; 7777 ssize_test=strEQcase(attribute,qq->method); 7778 } 7779 } 7780 if (pp == (Arguments *) NULL) 7781 { 7782 ThrowPerlException(exception,OptionError,"UnrecognizedOption", 7783 attribute); 7784 goto continue_outer_loop; 7785 } 7786 al=(&argument_list[pp-rp->arguments]); 7787 switch (pp->type) 7788 { 7789 case ArrayReference: 7790 { 7791 if (SvTYPE(sv) != SVt_RV) 7792 { 7793 (void) FormatLocaleString(message,MagickPathExtent, 7794 "invalid %.60s value",pp->method); 7795 ThrowPerlException(exception,OptionError,message,SvPV(sv,na)); 7796 goto continue_outer_loop; 7797 } 7798 al->array_reference=SvRV(sv); 7799 break; 7800 } 7801 case RealReference: 7802 { 7803 al->real_reference=SvNV(sv); 7804 break; 7805 } 7806 case FileReference: 7807 { 7808 al->file_reference=(FILE *) PerlIO_findFILE(IoIFP(sv_2io(sv))); 7809 break; 7810 } 7811 case ImageReference: 7812 { 7813 if (!sv_isobject(sv) || 7814 !(al->image_reference=SetupList(aTHX_ SvRV(sv), 7815 (struct PackageInfo **) NULL,(SV ***) NULL,exception))) 7816 { 7817 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 7818 PackageName); 7819 goto PerlException; 7820 } 7821 break; 7822 } 7823 case IntegerReference: 7824 { 7825 al->integer_reference=SvIV(sv); 7826 break; 7827 } 7828 case StringReference: 7829 { 7830 al->string_reference=(char *) SvPV(sv,al->length); 7831 if (sv_isobject(sv)) 7832 al->image_reference=SetupList(aTHX_ SvRV(sv), 7833 (struct PackageInfo **) NULL,(SV ***) NULL,exception); 7834 break; 7835 } 7836 default: 7837 { 7838 /* 7839 Is a string; look up name. 7840 */ 7841 if ((al->length > 1) && (*(char *) SvPV(sv,al->length) == '@')) 7842 { 7843 al->string_reference=(char *) SvPV(sv,al->length); 7844 al->integer_reference=(-1); 7845 break; 7846 } 7847 al->integer_reference=ParseCommandOption((CommandOption) pp->type, 7848 MagickFalse,SvPV(sv,na)); 7849 if (pp->type == MagickChannelOptions) 7850 al->integer_reference=ParseChannelOption(SvPV(sv,na)); 7851 if ((al->integer_reference < 0) && ((al->integer_reference=SvIV(sv)) <= 0)) 7852 { 7853 (void) FormatLocaleString(message,MagickPathExtent, 7854 "invalid %.60s value",pp->method); 7855 ThrowPerlException(exception,OptionError,message,SvPV(sv,na)); 7856 goto continue_outer_loop; 7857 } 7858 break; 7859 } 7860 } 7861 attribute_flag[pp-rp->arguments]++; 7862 continue_outer_loop: ; 7863 } 7864 (void) ResetMagickMemory((char *) &fill_color,0,sizeof(fill_color)); 7865 pv=reference_vector; 7866 SetGeometryInfo(&geometry_info); 7867 channel=DefaultChannels; 7868 for (next=image; next; next=next->next) 7869 { 7870 image=next; 7871 SetGeometry(image,&geometry); 7872 if ((region_info.width*region_info.height) != 0) 7873 { 7874 region_image=image; 7875 image=CropImage(image,®ion_info,exception); 7876 } 7877 switch (ix) 7878 { 7879 default: 7880 { 7881 (void) FormatLocaleString(message,MagickPathExtent,"%.20g",(double) ix); 7882 ThrowPerlException(exception,OptionError, 7883 "UnrecognizedPerlMagickMethod",message); 7884 goto PerlException; 7885 } 7886 case 1: /* Comment */ 7887 { 7888 if (attribute_flag[0] == 0) 7889 argument_list[0].string_reference=(char *) NULL; 7890 (void) SetImageProperty(image,"comment",InterpretImageProperties( 7891 info ? info->image_info : (ImageInfo *) NULL,image, 7892 argument_list[0].string_reference,exception),exception); 7893 break; 7894 } 7895 case 2: /* Label */ 7896 { 7897 if (attribute_flag[0] == 0) 7898 argument_list[0].string_reference=(char *) NULL; 7899 (void) SetImageProperty(image,"label",InterpretImageProperties( 7900 info ? info->image_info : (ImageInfo *) NULL,image, 7901 argument_list[0].string_reference,exception),exception); 7902 break; 7903 } 7904 case 3: /* AddNoise */ 7905 { 7906 double 7907 attenuate; 7908 7909 if (attribute_flag[0] == 0) 7910 argument_list[0].integer_reference=UniformNoise; 7911 attenuate=1.0; 7912 if (attribute_flag[1] != 0) 7913 attenuate=argument_list[1].real_reference; 7914 if (attribute_flag[2] != 0) 7915 channel=(ChannelType) argument_list[2].integer_reference; 7916 channel_mask=SetImageChannelMask(image,channel); 7917 image=AddNoiseImage(image,(NoiseType) 7918 argument_list[0].integer_reference,attenuate,exception); 7919 if (image != (Image *) NULL) 7920 (void) SetImageChannelMask(image,channel_mask); 7921 break; 7922 } 7923 case 4: /* Colorize */ 7924 { 7925 PixelInfo 7926 target; 7927 7928 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod, 7929 0,0,&target,exception); 7930 if (attribute_flag[0] != 0) 7931 (void) QueryColorCompliance(argument_list[0].string_reference, 7932 AllCompliance,&target,exception); 7933 if (attribute_flag[1] == 0) 7934 argument_list[1].string_reference="100%"; 7935 image=ColorizeImage(image,argument_list[1].string_reference,&target, 7936 exception); 7937 break; 7938 } 7939 case 5: /* Border */ 7940 { 7941 CompositeOperator 7942 compose; 7943 7944 geometry.width=0; 7945 geometry.height=0; 7946 if (attribute_flag[0] != 0) 7947 flags=ParsePageGeometry(image,argument_list[0].string_reference, 7948 &geometry,exception); 7949 if (attribute_flag[1] != 0) 7950 geometry.width=argument_list[1].integer_reference; 7951 if (attribute_flag[2] != 0) 7952 geometry.height=argument_list[2].integer_reference; 7953 if (attribute_flag[3] != 0) 7954 QueryColorCompliance(argument_list[3].string_reference, 7955 AllCompliance,&image->border_color,exception); 7956 if (attribute_flag[4] != 0) 7957 QueryColorCompliance(argument_list[4].string_reference, 7958 AllCompliance,&image->border_color,exception); 7959 if (attribute_flag[5] != 0) 7960 QueryColorCompliance(argument_list[5].string_reference, 7961 AllCompliance,&image->border_color,exception); 7962 compose=image->compose; 7963 if (attribute_flag[6] != 0) 7964 compose=(CompositeOperator) argument_list[6].integer_reference; 7965 image=BorderImage(image,&geometry,compose,exception); 7966 break; 7967 } 7968 case 6: /* Blur */ 7969 { 7970 if (attribute_flag[0] != 0) 7971 { 7972 flags=ParseGeometry(argument_list[0].string_reference, 7973 &geometry_info); 7974 if ((flags & SigmaValue) == 0) 7975 geometry_info.sigma=1.0; 7976 } 7977 if (attribute_flag[1] != 0) 7978 geometry_info.rho=argument_list[1].real_reference; 7979 if (attribute_flag[2] != 0) 7980 geometry_info.sigma=argument_list[2].real_reference; 7981 if (attribute_flag[3] != 0) 7982 channel=(ChannelType) argument_list[3].integer_reference; 7983 channel_mask=SetImageChannelMask(image,channel); 7984 image=BlurImage(image,geometry_info.rho,geometry_info.sigma, 7985 exception); 7986 if (image != (Image *) NULL) 7987 (void) SetImageChannelMask(image,channel_mask); 7988 break; 7989 } 7990 case 7: /* Chop */ 7991 { 7992 if (attribute_flag[5] != 0) 7993 image->gravity=(GravityType) argument_list[5].integer_reference; 7994 if (attribute_flag[0] != 0) 7995 flags=ParseGravityGeometry(image,argument_list[0].string_reference, 7996 &geometry,exception); 7997 if (attribute_flag[1] != 0) 7998 geometry.width=argument_list[1].integer_reference; 7999 if (attribute_flag[2] != 0) 8000 geometry.height=argument_list[2].integer_reference; 8001 if (attribute_flag[3] != 0) 8002 geometry.x=argument_list[3].integer_reference; 8003 if (attribute_flag[4] != 0) 8004 geometry.y=argument_list[4].integer_reference; 8005 image=ChopImage(image,&geometry,exception); 8006 break; 8007 } 8008 case 8: /* Crop */ 8009 { 8010 if (attribute_flag[6] != 0) 8011 image->gravity=(GravityType) argument_list[6].integer_reference; 8012 if (attribute_flag[0] != 0) 8013 flags=ParseGravityGeometry(image,argument_list[0].string_reference, 8014 &geometry,exception); 8015 if (attribute_flag[1] != 0) 8016 geometry.width=argument_list[1].integer_reference; 8017 if (attribute_flag[2] != 0) 8018 geometry.height=argument_list[2].integer_reference; 8019 if (attribute_flag[3] != 0) 8020 geometry.x=argument_list[3].integer_reference; 8021 if (attribute_flag[4] != 0) 8022 geometry.y=argument_list[4].integer_reference; 8023 if (attribute_flag[5] != 0) 8024 image->fuzz=StringToDoubleInterval( 8025 argument_list[5].string_reference,(double) QuantumRange+1.0); 8026 image=CropImage(image,&geometry,exception); 8027 break; 8028 } 8029 case 9: /* Despeckle */ 8030 { 8031 image=DespeckleImage(image,exception); 8032 break; 8033 } 8034 case 10: /* Edge */ 8035 { 8036 if (attribute_flag[0] != 0) 8037 geometry_info.rho=argument_list[0].real_reference; 8038 image=EdgeImage(image,geometry_info.rho,exception); 8039 break; 8040 } 8041 case 11: /* Emboss */ 8042 { 8043 if (attribute_flag[0] != 0) 8044 { 8045 flags=ParseGeometry(argument_list[0].string_reference, 8046 &geometry_info); 8047 if ((flags & SigmaValue) == 0) 8048 geometry_info.sigma=1.0; 8049 } 8050 if (attribute_flag[1] != 0) 8051 geometry_info.rho=argument_list[1].real_reference; 8052 if (attribute_flag[2] != 0) 8053 geometry_info.sigma=argument_list[2].real_reference; 8054 image=EmbossImage(image,geometry_info.rho,geometry_info.sigma, 8055 exception); 8056 break; 8057 } 8058 case 12: /* Enhance */ 8059 { 8060 image=EnhanceImage(image,exception); 8061 break; 8062 } 8063 case 13: /* Flip */ 8064 { 8065 image=FlipImage(image,exception); 8066 break; 8067 } 8068 case 14: /* Flop */ 8069 { 8070 image=FlopImage(image,exception); 8071 break; 8072 } 8073 case 15: /* Frame */ 8074 { 8075 CompositeOperator 8076 compose; 8077 8078 FrameInfo 8079 frame_info; 8080 8081 if (attribute_flag[0] != 0) 8082 { 8083 flags=ParsePageGeometry(image,argument_list[0].string_reference, 8084 &geometry,exception); 8085 frame_info.width=geometry.width; 8086 frame_info.height=geometry.height; 8087 frame_info.outer_bevel=geometry.x; 8088 frame_info.inner_bevel=geometry.y; 8089 } 8090 if (attribute_flag[1] != 0) 8091 frame_info.width=argument_list[1].integer_reference; 8092 if (attribute_flag[2] != 0) 8093 frame_info.height=argument_list[2].integer_reference; 8094 if (attribute_flag[3] != 0) 8095 frame_info.inner_bevel=argument_list[3].integer_reference; 8096 if (attribute_flag[4] != 0) 8097 frame_info.outer_bevel=argument_list[4].integer_reference; 8098 if (attribute_flag[5] != 0) 8099 QueryColorCompliance(argument_list[5].string_reference, 8100 AllCompliance,&fill_color,exception); 8101 if (attribute_flag[6] != 0) 8102 QueryColorCompliance(argument_list[6].string_reference, 8103 AllCompliance,&fill_color,exception); 8104 frame_info.x=(ssize_t) frame_info.width; 8105 frame_info.y=(ssize_t) frame_info.height; 8106 frame_info.width=image->columns+2*frame_info.x; 8107 frame_info.height=image->rows+2*frame_info.y; 8108 if ((attribute_flag[5] != 0) || (attribute_flag[6] != 0)) 8109 image->alpha_color=fill_color; 8110 compose=image->compose; 8111 if (attribute_flag[7] != 0) 8112 compose=(CompositeOperator) argument_list[7].integer_reference; 8113 image=FrameImage(image,&frame_info,compose,exception); 8114 break; 8115 } 8116 case 16: /* Implode */ 8117 { 8118 PixelInterpolateMethod 8119 method; 8120 8121 if (attribute_flag[0] == 0) 8122 argument_list[0].real_reference=0.5; 8123 method=UndefinedInterpolatePixel; 8124 if (attribute_flag[1] != 0) 8125 method=(PixelInterpolateMethod) argument_list[1].integer_reference; 8126 image=ImplodeImage(image,argument_list[0].real_reference, 8127 method,exception); 8128 break; 8129 } 8130 case 17: /* Magnify */ 8131 { 8132 image=MagnifyImage(image,exception); 8133 break; 8134 } 8135 case 18: /* MedianFilter */ 8136 { 8137 if (attribute_flag[0] != 0) 8138 { 8139 flags=ParseGeometry(argument_list[0].string_reference, 8140 &geometry_info); 8141 if ((flags & SigmaValue) == 0) 8142 geometry_info.sigma=geometry_info.rho; 8143 } 8144 if (attribute_flag[1] != 0) 8145 geometry_info.rho=argument_list[1].real_reference; 8146 if (attribute_flag[2] != 0) 8147 geometry_info.sigma=argument_list[2].real_reference; 8148 if (attribute_flag[3] != 0) 8149 channel=(ChannelType) argument_list[3].integer_reference; 8150 channel_mask=SetImageChannelMask(image,channel); 8151 image=StatisticImage(image,MedianStatistic,(size_t) geometry_info.rho, 8152 (size_t) geometry_info.sigma,exception); 8153 if (image != (Image *) NULL) 8154 (void) SetImageChannelMask(image,channel_mask); 8155 break; 8156 } 8157 case 19: /* Minify */ 8158 { 8159 image=MinifyImage(image,exception); 8160 break; 8161 } 8162 case 20: /* OilPaint */ 8163 { 8164 if (attribute_flag[0] == 0) 8165 argument_list[0].real_reference=0.0; 8166 if (attribute_flag[1] == 0) 8167 argument_list[1].real_reference=1.0; 8168 image=OilPaintImage(image,argument_list[0].real_reference, 8169 argument_list[1].real_reference,exception); 8170 break; 8171 } 8172 case 21: /* ReduceNoise */ 8173 { 8174 if (attribute_flag[0] != 0) 8175 { 8176 flags=ParseGeometry(argument_list[0].string_reference, 8177 &geometry_info); 8178 if ((flags & SigmaValue) == 0) 8179 geometry_info.sigma=1.0; 8180 } 8181 if (attribute_flag[1] != 0) 8182 geometry_info.rho=argument_list[1].real_reference; 8183 if (attribute_flag[2] != 0) 8184 geometry_info.sigma=argument_list[2].real_reference; 8185 if (attribute_flag[3] != 0) 8186 channel=(ChannelType) argument_list[3].integer_reference; 8187 channel_mask=SetImageChannelMask(image,channel); 8188 image=StatisticImage(image,NonpeakStatistic,(size_t) 8189 geometry_info.rho,(size_t) geometry_info.sigma,exception); 8190 if (image != (Image *) NULL) 8191 (void) SetImageChannelMask(image,channel_mask); 8192 break; 8193 } 8194 case 22: /* Roll */ 8195 { 8196 if (attribute_flag[0] != 0) 8197 flags=ParsePageGeometry(image,argument_list[0].string_reference, 8198 &geometry,exception); 8199 if (attribute_flag[1] != 0) 8200 geometry.x=argument_list[1].integer_reference; 8201 if (attribute_flag[2] != 0) 8202 geometry.y=argument_list[2].integer_reference; 8203 image=RollImage(image,geometry.x,geometry.y,exception); 8204 break; 8205 } 8206 case 23: /* Rotate */ 8207 { 8208 if (attribute_flag[0] == 0) 8209 argument_list[0].real_reference=90.0; 8210 if (attribute_flag[1] != 0) 8211 { 8212 QueryColorCompliance(argument_list[1].string_reference, 8213 AllCompliance,&image->background_color,exception); 8214 if ((image->background_color.alpha_trait != UndefinedPixelTrait) && 8215 (image->alpha_trait == UndefinedPixelTrait)) 8216 (void) SetImageAlpha(image,OpaqueAlpha,exception); 8217 } 8218 image=RotateImage(image,argument_list[0].real_reference,exception); 8219 break; 8220 } 8221 case 24: /* Sample */ 8222 { 8223 if (attribute_flag[0] != 0) 8224 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 8225 &geometry,exception); 8226 if (attribute_flag[1] != 0) 8227 geometry.width=argument_list[1].integer_reference; 8228 if (attribute_flag[2] != 0) 8229 geometry.height=argument_list[2].integer_reference; 8230 image=SampleImage(image,geometry.width,geometry.height,exception); 8231 break; 8232 } 8233 case 25: /* Scale */ 8234 { 8235 if (attribute_flag[0] != 0) 8236 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 8237 &geometry,exception); 8238 if (attribute_flag[1] != 0) 8239 geometry.width=argument_list[1].integer_reference; 8240 if (attribute_flag[2] != 0) 8241 geometry.height=argument_list[2].integer_reference; 8242 image=ScaleImage(image,geometry.width,geometry.height,exception); 8243 break; 8244 } 8245 case 26: /* Shade */ 8246 { 8247 if (attribute_flag[0] != 0) 8248 { 8249 flags=ParseGeometry(argument_list[0].string_reference, 8250 &geometry_info); 8251 if ((flags & SigmaValue) == 0) 8252 geometry_info.sigma=0.0; 8253 } 8254 if (attribute_flag[1] != 0) 8255 geometry_info.rho=argument_list[1].real_reference; 8256 if (attribute_flag[2] != 0) 8257 geometry_info.sigma=argument_list[2].real_reference; 8258 image=ShadeImage(image, 8259 argument_list[3].integer_reference != 0 ? MagickTrue : MagickFalse, 8260 geometry_info.rho,geometry_info.sigma,exception); 8261 break; 8262 } 8263 case 27: /* Sharpen */ 8264 { 8265 if (attribute_flag[0] != 0) 8266 { 8267 flags=ParseGeometry(argument_list[0].string_reference, 8268 &geometry_info); 8269 if ((flags & SigmaValue) == 0) 8270 geometry_info.sigma=1.0; 8271 } 8272 if (attribute_flag[1] != 0) 8273 geometry_info.rho=argument_list[1].real_reference; 8274 if (attribute_flag[2] != 0) 8275 geometry_info.sigma=argument_list[2].real_reference; 8276 if (attribute_flag[3] != 0) 8277 channel=(ChannelType) argument_list[3].integer_reference; 8278 channel_mask=SetImageChannelMask(image,channel); 8279 image=SharpenImage(image,geometry_info.rho,geometry_info.sigma, 8280 exception); 8281 if (image != (Image *) NULL) 8282 (void) SetImageChannelMask(image,channel_mask); 8283 break; 8284 } 8285 case 28: /* Shear */ 8286 { 8287 if (attribute_flag[0] != 0) 8288 { 8289 flags=ParseGeometry(argument_list[0].string_reference, 8290 &geometry_info); 8291 if ((flags & SigmaValue) == 0) 8292 geometry_info.sigma=geometry_info.rho; 8293 } 8294 if (attribute_flag[1] != 0) 8295 geometry_info.rho=argument_list[1].real_reference; 8296 if (attribute_flag[2] != 0) 8297 geometry_info.sigma=argument_list[2].real_reference; 8298 if (attribute_flag[3] != 0) 8299 QueryColorCompliance(argument_list[3].string_reference, 8300 AllCompliance,&image->background_color,exception); 8301 if (attribute_flag[4] != 0) 8302 QueryColorCompliance(argument_list[4].string_reference, 8303 AllCompliance,&image->background_color,exception); 8304 image=ShearImage(image,geometry_info.rho,geometry_info.sigma, 8305 exception); 8306 break; 8307 } 8308 case 29: /* Spread */ 8309 { 8310 PixelInterpolateMethod 8311 method; 8312 8313 if (attribute_flag[0] == 0) 8314 argument_list[0].real_reference=1.0; 8315 method=UndefinedInterpolatePixel; 8316 if (attribute_flag[1] != 0) 8317 method=(PixelInterpolateMethod) argument_list[1].integer_reference; 8318 image=SpreadImage(image,method,argument_list[0].real_reference, 8319 exception); 8320 break; 8321 } 8322 case 30: /* Swirl */ 8323 { 8324 PixelInterpolateMethod 8325 method; 8326 8327 if (attribute_flag[0] == 0) 8328 argument_list[0].real_reference=50.0; 8329 method=UndefinedInterpolatePixel; 8330 if (attribute_flag[1] != 0) 8331 method=(PixelInterpolateMethod) argument_list[1].integer_reference; 8332 image=SwirlImage(image,argument_list[0].real_reference, 8333 method,exception); 8334 break; 8335 } 8336 case 31: /* Resize */ 8337 case 32: /* Zoom */ 8338 { 8339 if (attribute_flag[0] != 0) 8340 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 8341 &geometry,exception); 8342 if (attribute_flag[1] != 0) 8343 geometry.width=argument_list[1].integer_reference; 8344 if (attribute_flag[2] != 0) 8345 geometry.height=argument_list[2].integer_reference; 8346 if (attribute_flag[3] == 0) 8347 argument_list[3].integer_reference=(ssize_t) UndefinedFilter; 8348 if (attribute_flag[4] != 0) 8349 SetImageArtifact(image,"filter:support", 8350 argument_list[4].string_reference); 8351 image=ResizeImage(image,geometry.width,geometry.height, 8352 (FilterType) argument_list[3].integer_reference, 8353 exception); 8354 break; 8355 } 8356 case 33: /* Annotate */ 8357 { 8358 DrawInfo 8359 *draw_info; 8360 8361 draw_info=CloneDrawInfo(info ? info->image_info : (ImageInfo *) NULL, 8362 (DrawInfo *) NULL); 8363 if (attribute_flag[0] != 0) 8364 { 8365 char 8366 *text; 8367 8368 text=InterpretImageProperties(info ? info->image_info : 8369 (ImageInfo *) NULL,image,argument_list[0].string_reference, 8370 exception); 8371 (void) CloneString(&draw_info->text,text); 8372 text=DestroyString(text); 8373 } 8374 if (attribute_flag[1] != 0) 8375 (void) CloneString(&draw_info->font, 8376 argument_list[1].string_reference); 8377 if (attribute_flag[2] != 0) 8378 draw_info->pointsize=argument_list[2].real_reference; 8379 if (attribute_flag[3] != 0) 8380 (void) CloneString(&draw_info->density, 8381 argument_list[3].string_reference); 8382 if (attribute_flag[4] != 0) 8383 (void) QueryColorCompliance(argument_list[4].string_reference, 8384 AllCompliance,&draw_info->undercolor,exception); 8385 if (attribute_flag[5] != 0) 8386 { 8387 (void) QueryColorCompliance(argument_list[5].string_reference, 8388 AllCompliance,&draw_info->stroke,exception); 8389 if (argument_list[5].image_reference != (Image *) NULL) 8390 draw_info->stroke_pattern=CloneImage( 8391 argument_list[5].image_reference,0,0,MagickTrue,exception); 8392 } 8393 if (attribute_flag[6] != 0) 8394 { 8395 (void) QueryColorCompliance(argument_list[6].string_reference, 8396 AllCompliance,&draw_info->fill,exception); 8397 if (argument_list[6].image_reference != (Image *) NULL) 8398 draw_info->fill_pattern=CloneImage( 8399 argument_list[6].image_reference,0,0,MagickTrue,exception); 8400 } 8401 if (attribute_flag[7] != 0) 8402 { 8403 (void) CloneString(&draw_info->geometry, 8404 argument_list[7].string_reference); 8405 flags=ParsePageGeometry(image,argument_list[7].string_reference, 8406 &geometry,exception); 8407 if (((flags & SigmaValue) == 0) && ((flags & XiValue) != 0)) 8408 geometry_info.sigma=geometry_info.xi; 8409 } 8410 if (attribute_flag[8] != 0) 8411 (void) QueryColorCompliance(argument_list[8].string_reference, 8412 AllCompliance,&draw_info->fill,exception); 8413 if (attribute_flag[11] != 0) 8414 draw_info->gravity=(GravityType) 8415 argument_list[11].integer_reference; 8416 if (attribute_flag[25] != 0) 8417 { 8418 AV 8419 *av; 8420 8421 av=(AV *) argument_list[25].array_reference; 8422 if ((av_len(av) != 3) && (av_len(av) != 5)) 8423 { 8424 ThrowPerlException(exception,OptionError, 8425 "affine matrix must have 4 or 6 elements",PackageName); 8426 goto PerlException; 8427 } 8428 draw_info->affine.sx=(double) SvNV(*(av_fetch(av,0,0))); 8429 draw_info->affine.rx=(double) SvNV(*(av_fetch(av,1,0))); 8430 draw_info->affine.ry=(double) SvNV(*(av_fetch(av,2,0))); 8431 draw_info->affine.sy=(double) SvNV(*(av_fetch(av,3,0))); 8432 if (fabs(draw_info->affine.sx*draw_info->affine.sy- 8433 draw_info->affine.rx*draw_info->affine.ry) < MagickEpsilon) 8434 { 8435 ThrowPerlException(exception,OptionError, 8436 "affine matrix is singular",PackageName); 8437 goto PerlException; 8438 } 8439 if (av_len(av) == 5) 8440 { 8441 draw_info->affine.tx=(double) SvNV(*(av_fetch(av,4,0))); 8442 draw_info->affine.ty=(double) SvNV(*(av_fetch(av,5,0))); 8443 } 8444 } 8445 for (j=12; j < 17; j++) 8446 { 8447 if (attribute_flag[j] == 0) 8448 continue; 8449 value=argument_list[j].string_reference; 8450 angle=argument_list[j].real_reference; 8451 current=draw_info->affine; 8452 GetAffineMatrix(&affine); 8453 switch (j) 8454 { 8455 case 12: 8456 { 8457 /* 8458 Translate. 8459 */ 8460 flags=ParseGeometry(value,&geometry_info); 8461 affine.tx=geometry_info.xi; 8462 affine.ty=geometry_info.psi; 8463 if ((flags & PsiValue) == 0) 8464 affine.ty=affine.tx; 8465 break; 8466 } 8467 case 13: 8468 { 8469 /* 8470 Scale. 8471 */ 8472 flags=ParseGeometry(value,&geometry_info); 8473 affine.sx=geometry_info.rho; 8474 affine.sy=geometry_info.sigma; 8475 if ((flags & SigmaValue) == 0) 8476 affine.sy=affine.sx; 8477 break; 8478 } 8479 case 14: 8480 { 8481 /* 8482 Rotate. 8483 */ 8484 if (angle == 0.0) 8485 break; 8486 affine.sx=cos(DegreesToRadians(fmod(angle,360.0))); 8487 affine.rx=sin(DegreesToRadians(fmod(angle,360.0))); 8488 affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0)))); 8489 affine.sy=cos(DegreesToRadians(fmod(angle,360.0))); 8490 break; 8491 } 8492 case 15: 8493 { 8494 /* 8495 SkewX. 8496 */ 8497 affine.ry=tan(DegreesToRadians(fmod(angle,360.0))); 8498 break; 8499 } 8500 case 16: 8501 { 8502 /* 8503 SkewY. 8504 */ 8505 affine.rx=tan(DegreesToRadians(fmod(angle,360.0))); 8506 break; 8507 } 8508 } 8509 draw_info->affine.sx=current.sx*affine.sx+current.ry*affine.rx; 8510 draw_info->affine.rx=current.rx*affine.sx+current.sy*affine.rx; 8511 draw_info->affine.ry=current.sx*affine.ry+current.ry*affine.sy; 8512 draw_info->affine.sy=current.rx*affine.ry+current.sy*affine.sy; 8513 draw_info->affine.tx=current.sx*affine.tx+current.ry*affine.ty+ 8514 current.tx; 8515 draw_info->affine.ty=current.rx*affine.tx+current.sy*affine.ty+ 8516 current.ty; 8517 } 8518 if (attribute_flag[9] == 0) 8519 argument_list[9].real_reference=0.0; 8520 if (attribute_flag[10] == 0) 8521 argument_list[10].real_reference=0.0; 8522 if ((attribute_flag[9] != 0) || (attribute_flag[10] != 0)) 8523 { 8524 char 8525 geometry[MagickPathExtent]; 8526 8527 (void) FormatLocaleString(geometry,MagickPathExtent,"%+f%+f", 8528 (double) argument_list[9].real_reference+draw_info->affine.tx, 8529 (double) argument_list[10].real_reference+draw_info->affine.ty); 8530 (void) CloneString(&draw_info->geometry,geometry); 8531 } 8532 if (attribute_flag[17] != 0) 8533 draw_info->stroke_width=argument_list[17].real_reference; 8534 if (attribute_flag[18] != 0) 8535 { 8536 draw_info->text_antialias=argument_list[18].integer_reference != 0 ? 8537 MagickTrue : MagickFalse; 8538 draw_info->stroke_antialias=draw_info->text_antialias; 8539 } 8540 if (attribute_flag[19] != 0) 8541 (void) CloneString(&draw_info->family, 8542 argument_list[19].string_reference); 8543 if (attribute_flag[20] != 0) 8544 draw_info->style=(StyleType) argument_list[20].integer_reference; 8545 if (attribute_flag[21] != 0) 8546 draw_info->stretch=(StretchType) argument_list[21].integer_reference; 8547 if (attribute_flag[22] != 0) 8548 draw_info->weight=argument_list[22].integer_reference; 8549 if (attribute_flag[23] != 0) 8550 draw_info->align=(AlignType) argument_list[23].integer_reference; 8551 if (attribute_flag[24] != 0) 8552 (void) CloneString(&draw_info->encoding, 8553 argument_list[24].string_reference); 8554 if (attribute_flag[25] != 0) 8555 draw_info->fill_pattern=CloneImage( 8556 argument_list[25].image_reference,0,0,MagickTrue,exception); 8557 if (attribute_flag[26] != 0) 8558 draw_info->fill_pattern=CloneImage( 8559 argument_list[26].image_reference,0,0,MagickTrue,exception); 8560 if (attribute_flag[27] != 0) 8561 draw_info->stroke_pattern=CloneImage( 8562 argument_list[27].image_reference,0,0,MagickTrue,exception); 8563 if (attribute_flag[29] != 0) 8564 draw_info->kerning=argument_list[29].real_reference; 8565 if (attribute_flag[30] != 0) 8566 draw_info->interline_spacing=argument_list[30].real_reference; 8567 if (attribute_flag[31] != 0) 8568 draw_info->interword_spacing=argument_list[31].real_reference; 8569 if (attribute_flag[32] != 0) 8570 draw_info->direction=(DirectionType) 8571 argument_list[32].integer_reference; 8572 (void) AnnotateImage(image,draw_info,exception); 8573 draw_info=DestroyDrawInfo(draw_info); 8574 break; 8575 } 8576 case 34: /* ColorFloodfill */ 8577 { 8578 DrawInfo 8579 *draw_info; 8580 8581 MagickBooleanType 8582 invert; 8583 8584 PixelInfo 8585 target; 8586 8587 draw_info=CloneDrawInfo(info ? info->image_info : 8588 (ImageInfo *) NULL,(DrawInfo *) NULL); 8589 if (attribute_flag[0] != 0) 8590 flags=ParsePageGeometry(image,argument_list[0].string_reference, 8591 &geometry,exception); 8592 if (attribute_flag[1] != 0) 8593 geometry.x=argument_list[1].integer_reference; 8594 if (attribute_flag[2] != 0) 8595 geometry.y=argument_list[2].integer_reference; 8596 if (attribute_flag[3] != 0) 8597 (void) QueryColorCompliance(argument_list[3].string_reference, 8598 AllCompliance,&draw_info->fill,exception); 8599 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod, 8600 geometry.x,geometry.y,&target,exception); 8601 invert=MagickFalse; 8602 if (attribute_flag[4] != 0) 8603 { 8604 QueryColorCompliance(argument_list[4].string_reference, 8605 AllCompliance,&target,exception); 8606 invert=MagickTrue; 8607 } 8608 if (attribute_flag[5] != 0) 8609 image->fuzz=StringToDoubleInterval( 8610 argument_list[5].string_reference,(double) QuantumRange+1.0); 8611 if (attribute_flag[6] != 0) 8612 invert=(MagickBooleanType) argument_list[6].integer_reference; 8613 (void) FloodfillPaintImage(image,draw_info,&target,geometry.x, 8614 geometry.y,invert,exception); 8615 draw_info=DestroyDrawInfo(draw_info); 8616 break; 8617 } 8618 case 35: /* Composite */ 8619 { 8620 char 8621 composite_geometry[MagickPathExtent]; 8622 8623 Image 8624 *composite_image, 8625 *rotate_image; 8626 8627 MagickBooleanType 8628 clip_to_self; 8629 8630 compose=OverCompositeOp; 8631 if (attribute_flag[0] != 0) 8632 composite_image=argument_list[0].image_reference; 8633 else 8634 { 8635 ThrowPerlException(exception,OptionError, 8636 "CompositeImageRequired",PackageName); 8637 goto PerlException; 8638 } 8639 /* 8640 Parameter Handling used for BOTH normal and tiled composition. 8641 */ 8642 if (attribute_flag[1] != 0) /* compose */ 8643 compose=(CompositeOperator) argument_list[1].integer_reference; 8644 if (attribute_flag[6] != 0) /* opacity */ 8645 { 8646 if (compose != DissolveCompositeOp) 8647 (void) SetImageAlpha(composite_image,(Quantum) 8648 StringToDoubleInterval(argument_list[6].string_reference, 8649 (double) QuantumRange+1.0),exception); 8650 else 8651 { 8652 CacheView 8653 *composite_view; 8654 8655 double 8656 opacity; 8657 8658 MagickBooleanType 8659 sync; 8660 8661 register ssize_t 8662 x; 8663 8664 register Quantum 8665 *q; 8666 8667 ssize_t 8668 y; 8669 8670 /* 8671 Handle dissolve composite operator (patch by 8672 Kevin A. McGrail). 8673 */ 8674 (void) CloneString(&image->geometry, 8675 argument_list[6].string_reference); 8676 opacity=(Quantum) StringToDoubleInterval( 8677 argument_list[6].string_reference,(double) QuantumRange+ 8678 1.0); 8679 if (composite_image->alpha_trait != UndefinedPixelTrait) 8680 (void) SetImageAlpha(composite_image,OpaqueAlpha,exception); 8681 composite_view=AcquireAuthenticCacheView(composite_image,exception); 8682 for (y=0; y < (ssize_t) composite_image->rows ; y++) 8683 { 8684 q=GetCacheViewAuthenticPixels(composite_view,0,y,(ssize_t) 8685 composite_image->columns,1,exception); 8686 for (x=0; x < (ssize_t) composite_image->columns; x++) 8687 { 8688 if (GetPixelAlpha(image,q) == OpaqueAlpha) 8689 SetPixelAlpha(composite_image,ClampToQuantum(opacity), 8690 q); 8691 q+=GetPixelChannels(composite_image); 8692 } 8693 sync=SyncCacheViewAuthenticPixels(composite_view,exception); 8694 if (sync == MagickFalse) 8695 break; 8696 } 8697 composite_view=DestroyCacheView(composite_view); 8698 } 8699 } 8700 if (attribute_flag[9] != 0) /* "color=>" */ 8701 QueryColorCompliance(argument_list[9].string_reference, 8702 AllCompliance,&composite_image->background_color,exception); 8703 if (attribute_flag[12] != 0) /* "interpolate=>" */ 8704 image->interpolate=(PixelInterpolateMethod) 8705 argument_list[12].integer_reference; 8706 if (attribute_flag[13] != 0) /* "args=>" */ 8707 (void) SetImageArtifact(composite_image,"compose:args", 8708 argument_list[13].string_reference); 8709 if (attribute_flag[14] != 0) /* "blend=>" depreciated */ 8710 (void) SetImageArtifact(composite_image,"compose:args", 8711 argument_list[14].string_reference); 8712 clip_to_self=MagickTrue; 8713 if (attribute_flag[15] != 0) 8714 clip_to_self=(MagickBooleanType) 8715 argument_list[15].integer_reference; 8716 /* 8717 Tiling Composition (with orthogonal rotate). 8718 */ 8719 rotate_image=(Image *) NULL; 8720 if (attribute_flag[8] != 0) /* "rotate=>" */ 8721 { 8722 /* 8723 Rotate image. 8724 */ 8725 rotate_image=RotateImage(composite_image, 8726 argument_list[8].real_reference,exception); 8727 if (rotate_image == (Image *) NULL) 8728 break; 8729 } 8730 if ((attribute_flag[7] != 0) && 8731 (argument_list[7].integer_reference != 0)) /* tile */ 8732 { 8733 ssize_t 8734 x, 8735 y; 8736 8737 /* 8738 Tile the composite image. 8739 */ 8740 if (attribute_flag[8] != 0) /* "tile=>" */ 8741 (void) SetImageArtifact(rotate_image,"compose:outside-overlay", 8742 "false"); 8743 else 8744 (void) SetImageArtifact(composite_image, 8745 "compose:outside-overlay","false"); 8746 for (y=0; y < (ssize_t) image->rows; y+=(ssize_t) composite_image->rows) 8747 for (x=0; x < (ssize_t) image->columns; x+=(ssize_t) composite_image->columns) 8748 { 8749 if (attribute_flag[8] != 0) /* rotate */ 8750 (void) CompositeImage(image,rotate_image,compose, 8751 MagickTrue,x,y,exception); 8752 else 8753 (void) CompositeImage(image,composite_image,compose, 8754 MagickTrue,x,y,exception); 8755 } 8756 if (attribute_flag[8] != 0) /* rotate */ 8757 rotate_image=DestroyImage(rotate_image); 8758 break; 8759 } 8760 /* 8761 Parameter Handling used used ONLY for normal composition. 8762 */ 8763 if (attribute_flag[5] != 0) /* gravity */ 8764 image->gravity=(GravityType) argument_list[5].integer_reference; 8765 if (attribute_flag[2] != 0) /* geometry offset */ 8766 { 8767 SetGeometry(image,&geometry); 8768 (void) ParseAbsoluteGeometry(argument_list[2].string_reference, 8769 &geometry); 8770 GravityAdjustGeometry(image->columns,image->rows,image->gravity, 8771 &geometry); 8772 } 8773 if (attribute_flag[3] != 0) /* x offset */ 8774 geometry.x=argument_list[3].integer_reference; 8775 if (attribute_flag[4] != 0) /* y offset */ 8776 geometry.y=argument_list[4].integer_reference; 8777 if (attribute_flag[10] != 0) /* mask */ 8778 { 8779 if ((image->compose == DisplaceCompositeOp) || 8780 (image->compose == DistortCompositeOp)) 8781 { 8782 /* 8783 Merge Y displacement into X displacement image. 8784 */ 8785 composite_image=CloneImage(composite_image,0,0,MagickTrue, 8786 exception); 8787 (void) CompositeImage(composite_image, 8788 argument_list[10].image_reference,CopyGreenCompositeOp, 8789 MagickTrue,0,0,exception); 8790 } 8791 else 8792 { 8793 Image 8794 *mask_image; 8795 8796 /* 8797 Set a blending mask for the composition. 8798 */ 8799 mask_image=CloneImage(argument_list[10].image_reference,0,0, 8800 MagickTrue,exception); 8801 (void) SetImageMask(composite_image,ReadPixelMask,mask_image, 8802 exception); 8803 mask_image=DestroyImage(mask_image); 8804 } 8805 } 8806 if (attribute_flag[11] != 0) /* channel */ 8807 channel=(ChannelType) argument_list[11].integer_reference; 8808 /* 8809 Composite two images (normal composition). 8810 */ 8811 (void) FormatLocaleString(composite_geometry,MagickPathExtent, 8812 "%.20gx%.20g%+.20g%+.20g",(double) composite_image->columns, 8813 (double) composite_image->rows,(double) geometry.x,(double) 8814 geometry.y); 8815 flags=ParseGravityGeometry(image,composite_geometry,&geometry, 8816 exception); 8817 channel_mask=SetImageChannelMask(image,channel); 8818 if (attribute_flag[8] == 0) /* no rotate */ 8819 CompositeImage(image,composite_image,compose,clip_to_self, 8820 geometry.x,geometry.y,exception); 8821 else 8822 { 8823 /* 8824 Position adjust rotated image then composite. 8825 */ 8826 geometry.x-=(ssize_t) (rotate_image->columns- 8827 composite_image->columns)/2; 8828 geometry.y-=(ssize_t) (rotate_image->rows- 8829 composite_image->rows)/2; 8830 CompositeImage(image,rotate_image,compose,clip_to_self,geometry.x, 8831 geometry.y,exception); 8832 rotate_image=DestroyImage(rotate_image); 8833 } 8834 if (attribute_flag[10] != 0) /* mask */ 8835 { 8836 if ((image->compose == DisplaceCompositeOp) || 8837 (image->compose == DistortCompositeOp)) 8838 composite_image=DestroyImage(composite_image); 8839 else 8840 (void) SetImageMask(image,ReadPixelMask,(Image *) NULL, 8841 exception); 8842 } 8843 (void) SetImageChannelMask(image,channel_mask); 8844 break; 8845 } 8846 case 36: /* Contrast */ 8847 { 8848 if (attribute_flag[0] == 0) 8849 argument_list[0].integer_reference=0; 8850 (void) ContrastImage(image,argument_list[0].integer_reference != 0 ? 8851 MagickTrue : MagickFalse,exception); 8852 break; 8853 } 8854 case 37: /* CycleColormap */ 8855 { 8856 if (attribute_flag[0] == 0) 8857 argument_list[0].integer_reference=6; 8858 (void) CycleColormapImage(image,argument_list[0].integer_reference, 8859 exception); 8860 break; 8861 } 8862 case 38: /* Draw */ 8863 { 8864 DrawInfo 8865 *draw_info; 8866 8867 draw_info=CloneDrawInfo(info ? info->image_info : (ImageInfo *) NULL, 8868 (DrawInfo *) NULL); 8869 (void) CloneString(&draw_info->primitive,"point"); 8870 if (attribute_flag[0] != 0) 8871 { 8872 if (argument_list[0].integer_reference < 0) 8873 (void) CloneString(&draw_info->primitive, 8874 argument_list[0].string_reference); 8875 else 8876 (void) CloneString(&draw_info->primitive,CommandOptionToMnemonic( 8877 MagickPrimitiveOptions,argument_list[0].integer_reference)); 8878 } 8879 if (attribute_flag[1] != 0) 8880 { 8881 if (LocaleCompare(draw_info->primitive,"path") == 0) 8882 { 8883 (void) ConcatenateString(&draw_info->primitive," '"); 8884 ConcatenateString(&draw_info->primitive, 8885 argument_list[1].string_reference); 8886 (void) ConcatenateString(&draw_info->primitive,"'"); 8887 } 8888 else 8889 { 8890 (void) ConcatenateString(&draw_info->primitive," "); 8891 ConcatenateString(&draw_info->primitive, 8892 argument_list[1].string_reference); 8893 } 8894 } 8895 if (attribute_flag[2] != 0) 8896 { 8897 (void) ConcatenateString(&draw_info->primitive," "); 8898 (void) ConcatenateString(&draw_info->primitive, 8899 CommandOptionToMnemonic(MagickMethodOptions, 8900 argument_list[2].integer_reference)); 8901 } 8902 if (attribute_flag[3] != 0) 8903 { 8904 (void) QueryColorCompliance(argument_list[3].string_reference, 8905 AllCompliance,&draw_info->stroke,exception); 8906 if (argument_list[3].image_reference != (Image *) NULL) 8907 draw_info->stroke_pattern=CloneImage( 8908 argument_list[3].image_reference,0,0,MagickTrue,exception); 8909 } 8910 if (attribute_flag[4] != 0) 8911 { 8912 (void) QueryColorCompliance(argument_list[4].string_reference, 8913 AllCompliance,&draw_info->fill,exception); 8914 if (argument_list[4].image_reference != (Image *) NULL) 8915 draw_info->fill_pattern=CloneImage( 8916 argument_list[4].image_reference,0,0,MagickTrue,exception); 8917 } 8918 if (attribute_flag[5] != 0) 8919 draw_info->stroke_width=argument_list[5].real_reference; 8920 if (attribute_flag[6] != 0) 8921 (void) CloneString(&draw_info->font, 8922 argument_list[6].string_reference); 8923 if (attribute_flag[7] != 0) 8924 (void) QueryColorCompliance(argument_list[7].string_reference, 8925 AllCompliance,&draw_info->border_color,exception); 8926 if (attribute_flag[8] != 0) 8927 draw_info->affine.tx=argument_list[8].real_reference; 8928 if (attribute_flag[9] != 0) 8929 draw_info->affine.ty=argument_list[9].real_reference; 8930 if (attribute_flag[20] != 0) 8931 { 8932 AV 8933 *av; 8934 8935 av=(AV *) argument_list[20].array_reference; 8936 if ((av_len(av) != 3) && (av_len(av) != 5)) 8937 { 8938 ThrowPerlException(exception,OptionError, 8939 "affine matrix must have 4 or 6 elements",PackageName); 8940 goto PerlException; 8941 } 8942 draw_info->affine.sx=(double) SvNV(*(av_fetch(av,0,0))); 8943 draw_info->affine.rx=(double) SvNV(*(av_fetch(av,1,0))); 8944 draw_info->affine.ry=(double) SvNV(*(av_fetch(av,2,0))); 8945 draw_info->affine.sy=(double) SvNV(*(av_fetch(av,3,0))); 8946 if (fabs(draw_info->affine.sx*draw_info->affine.sy- 8947 draw_info->affine.rx*draw_info->affine.ry) < MagickEpsilon) 8948 { 8949 ThrowPerlException(exception,OptionError, 8950 "affine matrix is singular",PackageName); 8951 goto PerlException; 8952 } 8953 if (av_len(av) == 5) 8954 { 8955 draw_info->affine.tx=(double) SvNV(*(av_fetch(av,4,0))); 8956 draw_info->affine.ty=(double) SvNV(*(av_fetch(av,5,0))); 8957 } 8958 } 8959 for (j=10; j < 15; j++) 8960 { 8961 if (attribute_flag[j] == 0) 8962 continue; 8963 value=argument_list[j].string_reference; 8964 angle=argument_list[j].real_reference; 8965 current=draw_info->affine; 8966 GetAffineMatrix(&affine); 8967 switch (j) 8968 { 8969 case 10: 8970 { 8971 /* 8972 Translate. 8973 */ 8974 flags=ParseGeometry(value,&geometry_info); 8975 affine.tx=geometry_info.xi; 8976 affine.ty=geometry_info.psi; 8977 if ((flags & PsiValue) == 0) 8978 affine.ty=affine.tx; 8979 break; 8980 } 8981 case 11: 8982 { 8983 /* 8984 Scale. 8985 */ 8986 flags=ParseGeometry(value,&geometry_info); 8987 affine.sx=geometry_info.rho; 8988 affine.sy=geometry_info.sigma; 8989 if ((flags & SigmaValue) == 0) 8990 affine.sy=affine.sx; 8991 break; 8992 } 8993 case 12: 8994 { 8995 /* 8996 Rotate. 8997 */ 8998 if (angle == 0.0) 8999 break; 9000 affine.sx=cos(DegreesToRadians(fmod(angle,360.0))); 9001 affine.rx=sin(DegreesToRadians(fmod(angle,360.0))); 9002 affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0)))); 9003 affine.sy=cos(DegreesToRadians(fmod(angle,360.0))); 9004 break; 9005 } 9006 case 13: 9007 { 9008 /* 9009 SkewX. 9010 */ 9011 affine.ry=tan(DegreesToRadians(fmod(angle,360.0))); 9012 break; 9013 } 9014 case 14: 9015 { 9016 /* 9017 SkewY. 9018 */ 9019 affine.rx=tan(DegreesToRadians(fmod(angle,360.0))); 9020 break; 9021 } 9022 } 9023 draw_info->affine.sx=current.sx*affine.sx+current.ry*affine.rx; 9024 draw_info->affine.rx=current.rx*affine.sx+current.sy*affine.rx; 9025 draw_info->affine.ry=current.sx*affine.ry+current.ry*affine.sy; 9026 draw_info->affine.sy=current.rx*affine.ry+current.sy*affine.sy; 9027 draw_info->affine.tx= 9028 current.sx*affine.tx+current.ry*affine.ty+current.tx; 9029 draw_info->affine.ty= 9030 current.rx*affine.tx+current.sy*affine.ty+current.ty; 9031 } 9032 if (attribute_flag[15] != 0) 9033 draw_info->fill_pattern=CloneImage( 9034 argument_list[15].image_reference,0,0,MagickTrue,exception); 9035 if (attribute_flag[16] != 0) 9036 draw_info->pointsize=argument_list[16].real_reference; 9037 if (attribute_flag[17] != 0) 9038 { 9039 draw_info->stroke_antialias=argument_list[17].integer_reference != 0 9040 ? MagickTrue : MagickFalse; 9041 draw_info->text_antialias=draw_info->stroke_antialias; 9042 } 9043 if (attribute_flag[18] != 0) 9044 (void) CloneString(&draw_info->density, 9045 argument_list[18].string_reference); 9046 if (attribute_flag[19] != 0) 9047 draw_info->stroke_width=argument_list[19].real_reference; 9048 if (attribute_flag[21] != 0) 9049 draw_info->dash_offset=argument_list[21].real_reference; 9050 if (attribute_flag[22] != 0) 9051 { 9052 AV 9053 *av; 9054 9055 av=(AV *) argument_list[22].array_reference; 9056 draw_info->dash_pattern=(double *) AcquireQuantumMemory( 9057 av_len(av)+2UL,sizeof(*draw_info->dash_pattern)); 9058 if (draw_info->dash_pattern != (double *) NULL) 9059 { 9060 for (i=0; i <= av_len(av); i++) 9061 draw_info->dash_pattern[i]=(double) 9062 SvNV(*(av_fetch(av,i,0))); 9063 draw_info->dash_pattern[i]=0.0; 9064 } 9065 } 9066 if (attribute_flag[23] != 0) 9067 image->interpolate=(PixelInterpolateMethod) 9068 argument_list[23].integer_reference; 9069 if ((attribute_flag[24] != 0) && 9070 (draw_info->fill_pattern != (Image *) NULL)) 9071 flags=ParsePageGeometry(draw_info->fill_pattern, 9072 argument_list[24].string_reference, 9073 &draw_info->fill_pattern->tile_offset,exception); 9074 if (attribute_flag[25] != 0) 9075 { 9076 (void) ConcatenateString(&draw_info->primitive," '"); 9077 (void) ConcatenateString(&draw_info->primitive, 9078 argument_list[25].string_reference); 9079 (void) ConcatenateString(&draw_info->primitive,"'"); 9080 } 9081 if (attribute_flag[26] != 0) 9082 draw_info->fill_pattern=CloneImage( 9083 argument_list[26].image_reference,0,0,MagickTrue,exception); 9084 if (attribute_flag[27] != 0) 9085 draw_info->stroke_pattern=CloneImage( 9086 argument_list[27].image_reference,0,0,MagickTrue,exception); 9087 if (attribute_flag[28] != 0) 9088 (void) CloneString(&draw_info->primitive, 9089 argument_list[28].string_reference); 9090 if (attribute_flag[29] != 0) 9091 draw_info->kerning=argument_list[29].real_reference; 9092 if (attribute_flag[30] != 0) 9093 draw_info->interline_spacing=argument_list[30].real_reference; 9094 if (attribute_flag[31] != 0) 9095 draw_info->interword_spacing=argument_list[31].real_reference; 9096 if (attribute_flag[32] != 0) 9097 draw_info->direction=(DirectionType) 9098 argument_list[32].integer_reference; 9099 DrawImage(image,draw_info,exception); 9100 draw_info=DestroyDrawInfo(draw_info); 9101 break; 9102 } 9103 case 39: /* Equalize */ 9104 { 9105 if (attribute_flag[0] != 0) 9106 channel=(ChannelType) argument_list[0].integer_reference; 9107 channel_mask=SetImageChannelMask(image,channel); 9108 EqualizeImage(image,exception); 9109 (void) SetImageChannelMask(image,channel_mask); 9110 break; 9111 } 9112 case 40: /* Gamma */ 9113 { 9114 if (attribute_flag[1] != 0) 9115 channel=(ChannelType) argument_list[1].integer_reference; 9116 if (attribute_flag[2] == 0) 9117 argument_list[2].real_reference=1.0; 9118 if (attribute_flag[3] == 0) 9119 argument_list[3].real_reference=1.0; 9120 if (attribute_flag[4] == 0) 9121 argument_list[4].real_reference=1.0; 9122 if (attribute_flag[0] == 0) 9123 { 9124 (void) FormatLocaleString(message,MagickPathExtent, 9125 "%.15g,%.15g,%.15g",(double) argument_list[2].real_reference, 9126 (double) argument_list[3].real_reference, 9127 (double) argument_list[4].real_reference); 9128 argument_list[0].string_reference=message; 9129 } 9130 (void) GammaImage(image,StringToDouble( 9131 argument_list[0].string_reference,(char **) NULL),exception); 9132 break; 9133 } 9134 case 41: /* Map */ 9135 { 9136 QuantizeInfo 9137 *quantize_info; 9138 9139 if (attribute_flag[0] == 0) 9140 { 9141 ThrowPerlException(exception,OptionError,"MapImageRequired", 9142 PackageName); 9143 goto PerlException; 9144 } 9145 quantize_info=AcquireQuantizeInfo(info->image_info); 9146 if (attribute_flag[1] != 0) 9147 quantize_info->dither_method=(DitherMethod) 9148 argument_list[1].integer_reference; 9149 (void) RemapImages(quantize_info,image, 9150 argument_list[0].image_reference,exception); 9151 quantize_info=DestroyQuantizeInfo(quantize_info); 9152 break; 9153 } 9154 case 42: /* MatteFloodfill */ 9155 { 9156 DrawInfo 9157 *draw_info; 9158 9159 MagickBooleanType 9160 invert; 9161 9162 PixelInfo 9163 target; 9164 9165 draw_info=CloneDrawInfo(info ? info->image_info : (ImageInfo *) NULL, 9166 (DrawInfo *) NULL); 9167 if (attribute_flag[0] != 0) 9168 flags=ParsePageGeometry(image,argument_list[0].string_reference, 9169 &geometry,exception); 9170 if (attribute_flag[1] != 0) 9171 geometry.x=argument_list[1].integer_reference; 9172 if (attribute_flag[2] != 0) 9173 geometry.y=argument_list[2].integer_reference; 9174 if (image->alpha_trait == UndefinedPixelTrait) 9175 (void) SetImageAlpha(image,OpaqueAlpha,exception); 9176 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod, 9177 geometry.x,geometry.y,&target,exception); 9178 if (attribute_flag[4] != 0) 9179 QueryColorCompliance(argument_list[4].string_reference, 9180 AllCompliance,&target,exception); 9181 if (attribute_flag[3] != 0) 9182 target.alpha=StringToDoubleInterval( 9183 argument_list[3].string_reference,(double) (double) QuantumRange+ 9184 1.0); 9185 if (attribute_flag[5] != 0) 9186 image->fuzz=StringToDoubleInterval( 9187 argument_list[5].string_reference,(double) QuantumRange+1.0); 9188 invert=MagickFalse; 9189 if (attribute_flag[6] != 0) 9190 invert=(MagickBooleanType) argument_list[6].integer_reference; 9191 channel_mask=SetImageChannelMask(image,AlphaChannel); 9192 (void) FloodfillPaintImage(image,draw_info,&target,geometry.x, 9193 geometry.y,invert,exception); 9194 (void) SetImageChannelMask(image,channel_mask); 9195 draw_info=DestroyDrawInfo(draw_info); 9196 break; 9197 } 9198 case 43: /* Modulate */ 9199 { 9200 char 9201 modulate[MagickPathExtent]; 9202 9203 geometry_info.rho=100.0; 9204 geometry_info.sigma=100.0; 9205 geometry_info.xi=100.0; 9206 if (attribute_flag[0] != 0) 9207 (void)ParseGeometry(argument_list[0].string_reference, 9208 &geometry_info); 9209 if (attribute_flag[1] != 0) 9210 geometry_info.xi=argument_list[1].real_reference; 9211 if (attribute_flag[2] != 0) 9212 geometry_info.sigma=argument_list[2].real_reference; 9213 if (attribute_flag[3] != 0) 9214 { 9215 geometry_info.sigma=argument_list[3].real_reference; 9216 SetImageArtifact(image,"modulate:colorspace","HWB"); 9217 } 9218 if (attribute_flag[4] != 0) 9219 { 9220 geometry_info.rho=argument_list[4].real_reference; 9221 SetImageArtifact(image,"modulate:colorspace","HSB"); 9222 } 9223 if (attribute_flag[5] != 0) 9224 { 9225 geometry_info.sigma=argument_list[5].real_reference; 9226 SetImageArtifact(image,"modulate:colorspace","HSL"); 9227 } 9228 if (attribute_flag[6] != 0) 9229 { 9230 geometry_info.rho=argument_list[6].real_reference; 9231 SetImageArtifact(image,"modulate:colorspace","HWB"); 9232 } 9233 (void) FormatLocaleString(modulate,MagickPathExtent,"%.15g,%.15g,%.15g", 9234 geometry_info.rho,geometry_info.sigma,geometry_info.xi); 9235 (void) ModulateImage(image,modulate,exception); 9236 break; 9237 } 9238 case 44: /* Negate */ 9239 { 9240 if (attribute_flag[0] == 0) 9241 argument_list[0].integer_reference=0; 9242 if (attribute_flag[1] != 0) 9243 channel=(ChannelType) argument_list[1].integer_reference; 9244 channel_mask=SetImageChannelMask(image,channel); 9245 (void) NegateImage(image,argument_list[0].integer_reference != 0 ? 9246 MagickTrue : MagickFalse,exception); 9247 (void) SetImageChannelMask(image,channel_mask); 9248 break; 9249 } 9250 case 45: /* Normalize */ 9251 { 9252 if (attribute_flag[0] != 0) 9253 channel=(ChannelType) argument_list[0].integer_reference; 9254 channel_mask=SetImageChannelMask(image,channel); 9255 NormalizeImage(image,exception); 9256 (void) SetImageChannelMask(image,channel_mask); 9257 break; 9258 } 9259 case 46: /* NumberColors */ 9260 break; 9261 case 47: /* Opaque */ 9262 { 9263 MagickBooleanType 9264 invert; 9265 9266 PixelInfo 9267 fill_color, 9268 target; 9269 9270 (void) QueryColorCompliance("none",AllCompliance,&target, 9271 exception); 9272 (void) QueryColorCompliance("none",AllCompliance,&fill_color, 9273 exception); 9274 if (attribute_flag[0] != 0) 9275 (void) QueryColorCompliance(argument_list[0].string_reference, 9276 AllCompliance,&target,exception); 9277 if (attribute_flag[1] != 0) 9278 (void) QueryColorCompliance(argument_list[1].string_reference, 9279 AllCompliance,&fill_color,exception); 9280 if (attribute_flag[2] != 0) 9281 image->fuzz=StringToDoubleInterval( 9282 argument_list[2].string_reference,(double) QuantumRange+1.0); 9283 if (attribute_flag[3] != 0) 9284 channel=(ChannelType) argument_list[3].integer_reference; 9285 invert=MagickFalse; 9286 if (attribute_flag[4] != 0) 9287 invert=(MagickBooleanType) argument_list[4].integer_reference; 9288 channel_mask=SetImageChannelMask(image,channel); 9289 (void) OpaquePaintImage(image,&target,&fill_color,invert,exception); 9290 (void) SetImageChannelMask(image,channel_mask); 9291 break; 9292 } 9293 case 48: /* Quantize */ 9294 { 9295 QuantizeInfo 9296 *quantize_info; 9297 9298 quantize_info=AcquireQuantizeInfo(info->image_info); 9299 if (attribute_flag[0] != 0) 9300 quantize_info->number_colors=(size_t) 9301 argument_list[0].integer_reference; 9302 if (attribute_flag[1] != 0) 9303 quantize_info->tree_depth=(size_t) 9304 argument_list[1].integer_reference; 9305 if (attribute_flag[2] != 0) 9306 quantize_info->colorspace=(ColorspaceType) 9307 argument_list[2].integer_reference; 9308 if (attribute_flag[3] != 0) 9309 quantize_info->dither_method=(DitherMethod) 9310 argument_list[3].integer_reference; 9311 if (attribute_flag[4] != 0) 9312 quantize_info->measure_error= 9313 argument_list[4].integer_reference != 0 ? MagickTrue : MagickFalse; 9314 if (attribute_flag[6] != 0) 9315 (void) QueryColorCompliance(argument_list[6].string_reference, 9316 AllCompliance,&image->transparent_color,exception); 9317 if (attribute_flag[7] != 0) 9318 quantize_info->dither_method=(DitherMethod) 9319 argument_list[7].integer_reference; 9320 if (attribute_flag[5] && argument_list[5].integer_reference) 9321 (void) QuantizeImages(quantize_info,image,exception); 9322 else 9323 if ((image->storage_class == DirectClass) || 9324 (image->colors > quantize_info->number_colors) || 9325 (quantize_info->colorspace == GRAYColorspace)) 9326 (void) QuantizeImage(quantize_info,image,exception); 9327 else 9328 CompressImageColormap(image,exception); 9329 quantize_info=DestroyQuantizeInfo(quantize_info); 9330 break; 9331 } 9332 case 49: /* Raise */ 9333 { 9334 if (attribute_flag[0] != 0) 9335 flags=ParsePageGeometry(image,argument_list[0].string_reference, 9336 &geometry,exception); 9337 if (attribute_flag[1] != 0) 9338 geometry.width=argument_list[1].integer_reference; 9339 if (attribute_flag[2] != 0) 9340 geometry.height=argument_list[2].integer_reference; 9341 if (attribute_flag[3] == 0) 9342 argument_list[3].integer_reference=1; 9343 (void) RaiseImage(image,&geometry, 9344 argument_list[3].integer_reference != 0 ? MagickTrue : MagickFalse, 9345 exception); 9346 break; 9347 } 9348 case 50: /* Segment */ 9349 { 9350 ColorspaceType 9351 colorspace; 9352 9353 double 9354 cluster_threshold, 9355 smoothing_threshold; 9356 9357 MagickBooleanType 9358 verbose; 9359 9360 cluster_threshold=1.0; 9361 smoothing_threshold=1.5; 9362 colorspace=sRGBColorspace; 9363 verbose=MagickFalse; 9364 if (attribute_flag[0] != 0) 9365 { 9366 flags=ParseGeometry(argument_list[0].string_reference, 9367 &geometry_info); 9368 cluster_threshold=geometry_info.rho; 9369 if (flags & SigmaValue) 9370 smoothing_threshold=geometry_info.sigma; 9371 } 9372 if (attribute_flag[1] != 0) 9373 cluster_threshold=argument_list[1].real_reference; 9374 if (attribute_flag[2] != 0) 9375 smoothing_threshold=argument_list[2].real_reference; 9376 if (attribute_flag[3] != 0) 9377 colorspace=(ColorspaceType) argument_list[3].integer_reference; 9378 if (attribute_flag[4] != 0) 9379 verbose=argument_list[4].integer_reference != 0 ? 9380 MagickTrue : MagickFalse; 9381 (void) SegmentImage(image,colorspace,verbose,cluster_threshold, 9382 smoothing_threshold,exception); 9383 break; 9384 } 9385 case 51: /* Signature */ 9386 { 9387 (void) SignatureImage(image,exception); 9388 break; 9389 } 9390 case 52: /* Solarize */ 9391 { 9392 geometry_info.rho=QuantumRange/2.0; 9393 if (attribute_flag[0] != 0) 9394 flags=ParseGeometry(argument_list[0].string_reference, 9395 &geometry_info); 9396 if (attribute_flag[1] != 0) 9397 geometry_info.rho=StringToDoubleInterval( 9398 argument_list[1].string_reference,(double) QuantumRange+1.0); 9399 (void) SolarizeImage(image,geometry_info.rho,exception); 9400 break; 9401 } 9402 case 53: /* Sync */ 9403 { 9404 (void) SyncImage(image,exception); 9405 break; 9406 } 9407 case 54: /* Texture */ 9408 { 9409 if (attribute_flag[0] == 0) 9410 break; 9411 TextureImage(image,argument_list[0].image_reference,exception); 9412 break; 9413 } 9414 case 55: /* Evalute */ 9415 { 9416 MagickEvaluateOperator 9417 op; 9418 9419 op=SetEvaluateOperator; 9420 if (attribute_flag[0] == MagickFalse) 9421 argument_list[0].real_reference=0.0; 9422 if (attribute_flag[1] != MagickFalse) 9423 op=(MagickEvaluateOperator) argument_list[1].integer_reference; 9424 if (attribute_flag[2] != MagickFalse) 9425 channel=(ChannelType) argument_list[2].integer_reference; 9426 channel_mask=SetImageChannelMask(image,channel); 9427 (void) EvaluateImage(image,op,argument_list[0].real_reference, 9428 exception); 9429 (void) SetImageChannelMask(image,channel_mask); 9430 break; 9431 } 9432 case 56: /* Transparent */ 9433 { 9434 double 9435 opacity; 9436 9437 MagickBooleanType 9438 invert; 9439 9440 PixelInfo 9441 target; 9442 9443 (void) QueryColorCompliance("none",AllCompliance,&target, 9444 exception); 9445 if (attribute_flag[0] != 0) 9446 (void) QueryColorCompliance(argument_list[0].string_reference, 9447 AllCompliance,&target,exception); 9448 opacity=TransparentAlpha; 9449 if (attribute_flag[1] != 0) 9450 opacity=StringToDoubleInterval(argument_list[1].string_reference, 9451 (double) QuantumRange+1.0); 9452 if (attribute_flag[2] != 0) 9453 image->fuzz=StringToDoubleInterval( 9454 argument_list[2].string_reference,(double) QuantumRange+1.0); 9455 if (attribute_flag[3] == 0) 9456 argument_list[3].integer_reference=0; 9457 invert=MagickFalse; 9458 if (attribute_flag[3] != 0) 9459 invert=(MagickBooleanType) argument_list[3].integer_reference; 9460 (void) TransparentPaintImage(image,&target,ClampToQuantum(opacity), 9461 invert,exception); 9462 break; 9463 } 9464 case 57: /* Threshold */ 9465 { 9466 double 9467 threshold; 9468 9469 if (attribute_flag[0] == 0) 9470 argument_list[0].string_reference="50%"; 9471 if (attribute_flag[1] != 0) 9472 channel=(ChannelType) argument_list[1].integer_reference; 9473 threshold=StringToDoubleInterval(argument_list[0].string_reference, 9474 (double) QuantumRange+1.0); 9475 channel_mask=SetImageChannelMask(image,channel); 9476 (void) BilevelImage(image,threshold,exception); 9477 (void) SetImageChannelMask(image,channel_mask); 9478 break; 9479 } 9480 case 58: /* Charcoal */ 9481 { 9482 if (attribute_flag[0] != 0) 9483 { 9484 flags=ParseGeometry(argument_list[0].string_reference, 9485 &geometry_info); 9486 if ((flags & SigmaValue) == 0) 9487 geometry_info.sigma=1.0; 9488 } 9489 if (attribute_flag[1] != 0) 9490 geometry_info.rho=argument_list[1].real_reference; 9491 if (attribute_flag[2] != 0) 9492 geometry_info.sigma=argument_list[2].real_reference; 9493 image=CharcoalImage(image,geometry_info.rho,geometry_info.sigma, 9494 exception); 9495 break; 9496 } 9497 case 59: /* Trim */ 9498 { 9499 if (attribute_flag[0] != 0) 9500 image->fuzz=StringToDoubleInterval( 9501 argument_list[0].string_reference,(double) QuantumRange+1.0); 9502 image=TrimImage(image,exception); 9503 break; 9504 } 9505 case 60: /* Wave */ 9506 { 9507 PixelInterpolateMethod 9508 method; 9509 9510 if (attribute_flag[0] != 0) 9511 { 9512 flags=ParseGeometry(argument_list[0].string_reference, 9513 &geometry_info); 9514 if ((flags & SigmaValue) == 0) 9515 geometry_info.sigma=1.0; 9516 } 9517 if (attribute_flag[1] != 0) 9518 geometry_info.rho=argument_list[1].real_reference; 9519 if (attribute_flag[2] != 0) 9520 geometry_info.sigma=argument_list[2].real_reference; 9521 method=UndefinedInterpolatePixel; 9522 if (attribute_flag[3] != 0) 9523 method=(PixelInterpolateMethod) argument_list[3].integer_reference; 9524 image=WaveImage(image,geometry_info.rho,geometry_info.sigma, 9525 method,exception); 9526 break; 9527 } 9528 case 61: /* Separate */ 9529 { 9530 if (attribute_flag[0] != 0) 9531 channel=(ChannelType) argument_list[0].integer_reference; 9532 image=SeparateImage(image,channel,exception); 9533 break; 9534 } 9535 case 63: /* Stereo */ 9536 { 9537 if (attribute_flag[0] == 0) 9538 { 9539 ThrowPerlException(exception,OptionError,"StereoImageRequired", 9540 PackageName); 9541 goto PerlException; 9542 } 9543 if (attribute_flag[1] != 0) 9544 geometry.x=argument_list[1].integer_reference; 9545 if (attribute_flag[2] != 0) 9546 geometry.y=argument_list[2].integer_reference; 9547 image=StereoAnaglyphImage(image,argument_list[0].image_reference, 9548 geometry.x,geometry.y,exception); 9549 break; 9550 } 9551 case 64: /* Stegano */ 9552 { 9553 if (attribute_flag[0] == 0) 9554 { 9555 ThrowPerlException(exception,OptionError,"SteganoImageRequired", 9556 PackageName); 9557 goto PerlException; 9558 } 9559 if (attribute_flag[1] == 0) 9560 argument_list[1].integer_reference=0; 9561 image->offset=argument_list[1].integer_reference; 9562 image=SteganoImage(image,argument_list[0].image_reference,exception); 9563 break; 9564 } 9565 case 65: /* Deconstruct */ 9566 { 9567 image=CompareImagesLayers(image,CompareAnyLayer,exception); 9568 break; 9569 } 9570 case 66: /* GaussianBlur */ 9571 { 9572 if (attribute_flag[0] != 0) 9573 { 9574 flags=ParseGeometry(argument_list[0].string_reference, 9575 &geometry_info); 9576 if ((flags & SigmaValue) == 0) 9577 geometry_info.sigma=1.0; 9578 } 9579 if (attribute_flag[1] != 0) 9580 geometry_info.rho=argument_list[1].real_reference; 9581 if (attribute_flag[2] != 0) 9582 geometry_info.sigma=argument_list[2].real_reference; 9583 if (attribute_flag[3] != 0) 9584 channel=(ChannelType) argument_list[3].integer_reference; 9585 channel_mask=SetImageChannelMask(image,channel); 9586 image=GaussianBlurImage(image,geometry_info.rho,geometry_info.sigma, 9587 exception); 9588 if (image != (Image *) NULL) 9589 (void) SetImageChannelMask(image,channel_mask); 9590 break; 9591 } 9592 case 67: /* Convolve */ 9593 { 9594 KernelInfo 9595 *kernel; 9596 9597 kernel=(KernelInfo *) NULL; 9598 if ((attribute_flag[0] == 0) && (attribute_flag[3] == 0)) 9599 break; 9600 if (attribute_flag[0] != 0) 9601 { 9602 AV 9603 *av; 9604 9605 size_t 9606 order; 9607 9608 kernel=AcquireKernelInfo((const char *) NULL,exception); 9609 if (kernel == (KernelInfo *) NULL) 9610 break; 9611 av=(AV *) argument_list[0].array_reference; 9612 order=(size_t) sqrt(av_len(av)+1); 9613 kernel->width=order; 9614 kernel->height=order; 9615 kernel->values=(MagickRealType *) AcquireAlignedMemory(order, 9616 order*sizeof(*kernel->values)); 9617 if (kernel->values == (MagickRealType *) NULL) 9618 { 9619 kernel=DestroyKernelInfo(kernel); 9620 ThrowPerlException(exception,ResourceLimitFatalError, 9621 "MemoryAllocationFailed",PackageName); 9622 goto PerlException; 9623 } 9624 for (j=0; (j < (ssize_t) (order*order)) && (j < (av_len(av)+1)); j++) 9625 kernel->values[j]=(MagickRealType) SvNV(*(av_fetch(av,j,0))); 9626 for ( ; j < (ssize_t) (order*order); j++) 9627 kernel->values[j]=0.0; 9628 } 9629 if (attribute_flag[1] != 0) 9630 channel=(ChannelType) argument_list[1].integer_reference; 9631 if (attribute_flag[2] != 0) 9632 SetImageArtifact(image,"filter:blur", 9633 argument_list[2].string_reference); 9634 if (attribute_flag[3] != 0) 9635 { 9636 kernel=AcquireKernelInfo(argument_list[3].string_reference, 9637 exception); 9638 if (kernel == (KernelInfo *) NULL) 9639 break; 9640 } 9641 channel_mask=SetImageChannelMask(image,channel); 9642 image=ConvolveImage(image,kernel,exception); 9643 if (image != (Image *) NULL) 9644 (void) SetImageChannelMask(image,channel_mask); 9645 kernel=DestroyKernelInfo(kernel); 9646 break; 9647 } 9648 case 68: /* Profile */ 9649 { 9650 const char 9651 *name; 9652 9653 Image 9654 *profile_image; 9655 9656 ImageInfo 9657 *profile_info; 9658 9659 StringInfo 9660 *profile; 9661 9662 name="*"; 9663 if (attribute_flag[0] != 0) 9664 name=argument_list[0].string_reference; 9665 if (attribute_flag[2] != 0) 9666 image->rendering_intent=(RenderingIntent) 9667 argument_list[2].integer_reference; 9668 if (attribute_flag[3] != 0) 9669 image->black_point_compensation= 9670 argument_list[3].integer_reference != 0 ? MagickTrue : MagickFalse; 9671 if (attribute_flag[1] != 0) 9672 { 9673 if (argument_list[1].length == 0) 9674 { 9675 /* 9676 Remove a profile from the image. 9677 */ 9678 (void) ProfileImage(image,name,(const unsigned char *) NULL,0, 9679 exception); 9680 break; 9681 } 9682 /* 9683 Associate user supplied profile with the image. 9684 */ 9685 profile=AcquireStringInfo(argument_list[1].length); 9686 SetStringInfoDatum(profile,(const unsigned char *) 9687 argument_list[1].string_reference); 9688 (void) ProfileImage(image,name,GetStringInfoDatum(profile), 9689 (size_t) GetStringInfoLength(profile),exception); 9690 profile=DestroyStringInfo(profile); 9691 break; 9692 } 9693 /* 9694 Associate a profile with the image. 9695 */ 9696 profile_info=CloneImageInfo(info ? info->image_info : 9697 (ImageInfo *) NULL); 9698 profile_image=ReadImages(profile_info,name,exception); 9699 if (profile_image == (Image *) NULL) 9700 break; 9701 ResetImageProfileIterator(profile_image); 9702 name=GetNextImageProfile(profile_image); 9703 while (name != (const char *) NULL) 9704 { 9705 const StringInfo 9706 *profile; 9707 9708 profile=GetImageProfile(profile_image,name); 9709 if (profile != (const StringInfo *) NULL) 9710 (void) ProfileImage(image,name,GetStringInfoDatum(profile), 9711 (size_t) GetStringInfoLength(profile),exception); 9712 name=GetNextImageProfile(profile_image); 9713 } 9714 profile_image=DestroyImage(profile_image); 9715 profile_info=DestroyImageInfo(profile_info); 9716 break; 9717 } 9718 case 69: /* UnsharpMask */ 9719 { 9720 if (attribute_flag[0] != 0) 9721 { 9722 flags=ParseGeometry(argument_list[0].string_reference, 9723 &geometry_info); 9724 if ((flags & SigmaValue) == 0) 9725 geometry_info.sigma=1.0; 9726 if ((flags & XiValue) == 0) 9727 geometry_info.xi=1.0; 9728 if ((flags & PsiValue) == 0) 9729 geometry_info.psi=0.5; 9730 } 9731 if (attribute_flag[1] != 0) 9732 geometry_info.rho=argument_list[1].real_reference; 9733 if (attribute_flag[2] != 0) 9734 geometry_info.sigma=argument_list[2].real_reference; 9735 if (attribute_flag[3] != 0) 9736 geometry_info.xi=argument_list[3].real_reference; 9737 if (attribute_flag[4] != 0) 9738 geometry_info.psi=argument_list[4].real_reference; 9739 if (attribute_flag[5] != 0) 9740 channel=(ChannelType) argument_list[5].integer_reference; 9741 channel_mask=SetImageChannelMask(image,channel); 9742 image=UnsharpMaskImage(image,geometry_info.rho,geometry_info.sigma, 9743 geometry_info.xi,geometry_info.psi,exception); 9744 if (image != (Image *) NULL) 9745 (void) SetImageChannelMask(image,channel_mask); 9746 break; 9747 } 9748 case 70: /* MotionBlur */ 9749 { 9750 if (attribute_flag[0] != 0) 9751 { 9752 flags=ParseGeometry(argument_list[0].string_reference, 9753 &geometry_info); 9754 if ((flags & SigmaValue) == 0) 9755 geometry_info.sigma=1.0; 9756 if ((flags & XiValue) == 0) 9757 geometry_info.xi=1.0; 9758 } 9759 if (attribute_flag[1] != 0) 9760 geometry_info.rho=argument_list[1].real_reference; 9761 if (attribute_flag[2] != 0) 9762 geometry_info.sigma=argument_list[2].real_reference; 9763 if (attribute_flag[3] != 0) 9764 geometry_info.xi=argument_list[3].real_reference; 9765 if (attribute_flag[4] != 0) 9766 channel=(ChannelType) argument_list[4].integer_reference; 9767 channel_mask=SetImageChannelMask(image,channel); 9768 image=MotionBlurImage(image,geometry_info.rho,geometry_info.sigma, 9769 geometry_info.xi,exception); 9770 if (image != (Image *) NULL) 9771 (void) SetImageChannelMask(image,channel_mask); 9772 break; 9773 } 9774 case 71: /* OrderedDither */ 9775 { 9776 if (attribute_flag[0] == 0) 9777 argument_list[0].string_reference="o8x8"; 9778 if (attribute_flag[1] != 0) 9779 channel=(ChannelType) argument_list[1].integer_reference; 9780 channel_mask=SetImageChannelMask(image,channel); 9781 (void) OrderedDitherImage(image,argument_list[0].string_reference, 9782 exception); 9783 (void) SetImageChannelMask(image,channel_mask); 9784 break; 9785 } 9786 case 72: /* Shave */ 9787 { 9788 if (attribute_flag[0] != 0) 9789 flags=ParsePageGeometry(image,argument_list[0].string_reference, 9790 &geometry,exception); 9791 if (attribute_flag[1] != 0) 9792 geometry.width=argument_list[1].integer_reference; 9793 if (attribute_flag[2] != 0) 9794 geometry.height=argument_list[2].integer_reference; 9795 image=ShaveImage(image,&geometry,exception); 9796 break; 9797 } 9798 case 73: /* Level */ 9799 { 9800 double 9801 black_point, 9802 gamma, 9803 white_point; 9804 9805 black_point=0.0; 9806 white_point=(double) image->columns*image->rows; 9807 gamma=1.0; 9808 if (attribute_flag[0] != 0) 9809 { 9810 flags=ParseGeometry(argument_list[0].string_reference, 9811 &geometry_info); 9812 black_point=geometry_info.rho; 9813 if ((flags & SigmaValue) != 0) 9814 white_point=geometry_info.sigma; 9815 if ((flags & XiValue) != 0) 9816 gamma=geometry_info.xi; 9817 if ((flags & PercentValue) != 0) 9818 { 9819 black_point*=(double) (QuantumRange/100.0); 9820 white_point*=(double) (QuantumRange/100.0); 9821 } 9822 if ((flags & SigmaValue) == 0) 9823 white_point=(double) QuantumRange-black_point; 9824 } 9825 if (attribute_flag[1] != 0) 9826 black_point=argument_list[1].real_reference; 9827 if (attribute_flag[2] != 0) 9828 white_point=argument_list[2].real_reference; 9829 if (attribute_flag[3] != 0) 9830 gamma=argument_list[3].real_reference; 9831 if (attribute_flag[4] != 0) 9832 channel=(ChannelType) argument_list[4].integer_reference; 9833 if (attribute_flag[5] != 0) 9834 { 9835 argument_list[0].real_reference=argument_list[5].real_reference; 9836 attribute_flag[0]=attribute_flag[5]; 9837 } 9838 channel_mask=SetImageChannelMask(image,channel); 9839 (void) LevelImage(image,black_point,white_point,gamma,exception); 9840 (void) SetImageChannelMask(image,channel_mask); 9841 break; 9842 } 9843 case 74: /* Clip */ 9844 { 9845 if (attribute_flag[0] == 0) 9846 argument_list[0].string_reference="#1"; 9847 if (attribute_flag[1] == 0) 9848 argument_list[1].integer_reference=MagickTrue; 9849 (void) ClipImagePath(image,argument_list[0].string_reference, 9850 argument_list[1].integer_reference != 0 ? MagickTrue : MagickFalse, 9851 exception); 9852 break; 9853 } 9854 case 75: /* AffineTransform */ 9855 { 9856 DrawInfo 9857 *draw_info; 9858 9859 draw_info=CloneDrawInfo(info ? info->image_info : (ImageInfo *) NULL, 9860 (DrawInfo *) NULL); 9861 if (attribute_flag[0] != 0) 9862 { 9863 AV 9864 *av; 9865 9866 av=(AV *) argument_list[0].array_reference; 9867 if ((av_len(av) != 3) && (av_len(av) != 5)) 9868 { 9869 ThrowPerlException(exception,OptionError, 9870 "affine matrix must have 4 or 6 elements",PackageName); 9871 goto PerlException; 9872 } 9873 draw_info->affine.sx=(double) SvNV(*(av_fetch(av,0,0))); 9874 draw_info->affine.rx=(double) SvNV(*(av_fetch(av,1,0))); 9875 draw_info->affine.ry=(double) SvNV(*(av_fetch(av,2,0))); 9876 draw_info->affine.sy=(double) SvNV(*(av_fetch(av,3,0))); 9877 if (fabs(draw_info->affine.sx*draw_info->affine.sy- 9878 draw_info->affine.rx*draw_info->affine.ry) < MagickEpsilon) 9879 { 9880 ThrowPerlException(exception,OptionError, 9881 "affine matrix is singular",PackageName); 9882 goto PerlException; 9883 } 9884 if (av_len(av) == 5) 9885 { 9886 draw_info->affine.tx=(double) SvNV(*(av_fetch(av,4,0))); 9887 draw_info->affine.ty=(double) SvNV(*(av_fetch(av,5,0))); 9888 } 9889 } 9890 for (j=1; j < 6; j++) 9891 { 9892 if (attribute_flag[j] == 0) 9893 continue; 9894 value=argument_list[j].string_reference; 9895 angle=argument_list[j].real_reference; 9896 current=draw_info->affine; 9897 GetAffineMatrix(&affine); 9898 switch (j) 9899 { 9900 case 1: 9901 { 9902 /* 9903 Translate. 9904 */ 9905 flags=ParseGeometry(value,&geometry_info); 9906 affine.tx=geometry_info.xi; 9907 affine.ty=geometry_info.psi; 9908 if ((flags & PsiValue) == 0) 9909 affine.ty=affine.tx; 9910 break; 9911 } 9912 case 2: 9913 { 9914 /* 9915 Scale. 9916 */ 9917 flags=ParseGeometry(value,&geometry_info); 9918 affine.sx=geometry_info.rho; 9919 affine.sy=geometry_info.sigma; 9920 if ((flags & SigmaValue) == 0) 9921 affine.sy=affine.sx; 9922 break; 9923 } 9924 case 3: 9925 { 9926 /* 9927 Rotate. 9928 */ 9929 if (angle == 0.0) 9930 break; 9931 affine.sx=cos(DegreesToRadians(fmod(angle,360.0))); 9932 affine.rx=sin(DegreesToRadians(fmod(angle,360.0))); 9933 affine.ry=(-sin(DegreesToRadians(fmod(angle,360.0)))); 9934 affine.sy=cos(DegreesToRadians(fmod(angle,360.0))); 9935 break; 9936 } 9937 case 4: 9938 { 9939 /* 9940 SkewX. 9941 */ 9942 affine.ry=tan(DegreesToRadians(fmod(angle,360.0))); 9943 break; 9944 } 9945 case 5: 9946 { 9947 /* 9948 SkewY. 9949 */ 9950 affine.rx=tan(DegreesToRadians(fmod(angle,360.0))); 9951 break; 9952 } 9953 } 9954 draw_info->affine.sx=current.sx*affine.sx+current.ry*affine.rx; 9955 draw_info->affine.rx=current.rx*affine.sx+current.sy*affine.rx; 9956 draw_info->affine.ry=current.sx*affine.ry+current.ry*affine.sy; 9957 draw_info->affine.sy=current.rx*affine.ry+current.sy*affine.sy; 9958 draw_info->affine.tx= 9959 current.sx*affine.tx+current.ry*affine.ty+current.tx; 9960 draw_info->affine.ty= 9961 current.rx*affine.tx+current.sy*affine.ty+current.ty; 9962 } 9963 if (attribute_flag[6] != 0) 9964 image->interpolate=(PixelInterpolateMethod) 9965 argument_list[6].integer_reference; 9966 if (attribute_flag[7] != 0) 9967 QueryColorCompliance(argument_list[7].string_reference, 9968 AllCompliance,&image->background_color,exception); 9969 image=AffineTransformImage(image,&draw_info->affine,exception); 9970 draw_info=DestroyDrawInfo(draw_info); 9971 break; 9972 } 9973 case 76: /* Difference */ 9974 { 9975 if (attribute_flag[0] == 0) 9976 { 9977 ThrowPerlException(exception,OptionError, 9978 "ReferenceImageRequired",PackageName); 9979 goto PerlException; 9980 } 9981 if (attribute_flag[1] != 0) 9982 image->fuzz=StringToDoubleInterval( 9983 argument_list[1].string_reference,(double) QuantumRange+1.0); 9984 (void) SetImageColorMetric(image,argument_list[0].image_reference, 9985 exception); 9986 break; 9987 } 9988 case 77: /* AdaptiveThreshold */ 9989 { 9990 if (attribute_flag[0] != 0) 9991 { 9992 flags=ParseGeometry(argument_list[0].string_reference, 9993 &geometry_info); 9994 if ((flags & PercentValue) != 0) 9995 geometry_info.xi=QuantumRange*geometry_info.xi/100.0; 9996 } 9997 if (attribute_flag[1] != 0) 9998 geometry_info.rho=argument_list[1].integer_reference; 9999 if (attribute_flag[2] != 0) 10000 geometry_info.sigma=argument_list[2].integer_reference; 10001 if (attribute_flag[3] != 0) 10002 geometry_info.xi=argument_list[3].integer_reference;; 10003 image=AdaptiveThresholdImage(image,(size_t) geometry_info.rho, 10004 (size_t) geometry_info.sigma,(double) geometry_info.xi,exception); 10005 break; 10006 } 10007 case 78: /* Resample */ 10008 { 10009 size_t 10010 height, 10011 width; 10012 10013 if (attribute_flag[0] != 0) 10014 { 10015 flags=ParseGeometry(argument_list[0].string_reference, 10016 &geometry_info); 10017 if ((flags & SigmaValue) == 0) 10018 geometry_info.sigma=geometry_info.rho; 10019 } 10020 if (attribute_flag[1] != 0) 10021 geometry_info.rho=argument_list[1].real_reference; 10022 if (attribute_flag[2] != 0) 10023 geometry_info.sigma=argument_list[2].real_reference; 10024 if (attribute_flag[3] == 0) 10025 argument_list[3].integer_reference=(ssize_t) UndefinedFilter; 10026 if (attribute_flag[4] == 0) 10027 SetImageArtifact(image,"filter:support", 10028 argument_list[4].string_reference); 10029 width=(size_t) (geometry_info.rho*image->columns/ 10030 (image->resolution.x == 0.0 ? 72.0 : image->resolution.x)+0.5); 10031 height=(size_t) (geometry_info.sigma*image->rows/ 10032 (image->resolution.y == 0.0 ? 72.0 : image->resolution.y)+0.5); 10033 image=ResizeImage(image,width,height,(FilterType) 10034 argument_list[3].integer_reference,exception); 10035 if (image != (Image *) NULL) 10036 { 10037 image->resolution.x=geometry_info.rho; 10038 image->resolution.y=geometry_info.sigma; 10039 } 10040 break; 10041 } 10042 case 79: /* Describe */ 10043 { 10044 if (attribute_flag[0] == 0) 10045 argument_list[0].file_reference=(FILE *) NULL; 10046 if (attribute_flag[1] != 0) 10047 (void) SetImageArtifact(image,"identify:features", 10048 argument_list[1].string_reference); 10049 (void) IdentifyImage(image,argument_list[0].file_reference, 10050 MagickTrue,exception); 10051 break; 10052 } 10053 case 80: /* BlackThreshold */ 10054 { 10055 if (attribute_flag[0] == 0) 10056 argument_list[0].string_reference="50%"; 10057 if (attribute_flag[2] != 0) 10058 channel=(ChannelType) argument_list[2].integer_reference; 10059 channel_mask=SetImageChannelMask(image,channel); 10060 BlackThresholdImage(image,argument_list[0].string_reference, 10061 exception); 10062 (void) SetImageChannelMask(image,channel_mask); 10063 break; 10064 } 10065 case 81: /* WhiteThreshold */ 10066 { 10067 if (attribute_flag[0] == 0) 10068 argument_list[0].string_reference="50%"; 10069 if (attribute_flag[2] != 0) 10070 channel=(ChannelType) argument_list[2].integer_reference; 10071 channel_mask=SetImageChannelMask(image,channel); 10072 WhiteThresholdImage(image,argument_list[0].string_reference, 10073 exception); 10074 (void) SetImageChannelMask(image,channel_mask); 10075 break; 10076 } 10077 case 82: /* RotationalBlur */ 10078 { 10079 if (attribute_flag[0] != 0) 10080 { 10081 flags=ParseGeometry(argument_list[0].string_reference, 10082 &geometry_info); 10083 } 10084 if (attribute_flag[1] != 0) 10085 geometry_info.rho=argument_list[1].real_reference; 10086 if (attribute_flag[2] != 0) 10087 channel=(ChannelType) argument_list[2].integer_reference; 10088 channel_mask=SetImageChannelMask(image,channel); 10089 image=RotationalBlurImage(image,geometry_info.rho,exception); 10090 if (image != (Image *) NULL) 10091 (void) SetImageChannelMask(image,channel_mask); 10092 break; 10093 } 10094 case 83: /* Thumbnail */ 10095 { 10096 if (attribute_flag[0] != 0) 10097 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 10098 &geometry,exception); 10099 if (attribute_flag[1] != 0) 10100 geometry.width=argument_list[1].integer_reference; 10101 if (attribute_flag[2] != 0) 10102 geometry.height=argument_list[2].integer_reference; 10103 image=ThumbnailImage(image,geometry.width,geometry.height,exception); 10104 break; 10105 } 10106 case 84: /* Strip */ 10107 { 10108 (void) StripImage(image,exception); 10109 break; 10110 } 10111 case 85: /* Tint */ 10112 { 10113 PixelInfo 10114 tint; 10115 10116 GetPixelInfo(image,&tint); 10117 if (attribute_flag[0] != 0) 10118 (void) QueryColorCompliance(argument_list[0].string_reference, 10119 AllCompliance,&tint,exception); 10120 if (attribute_flag[1] == 0) 10121 argument_list[1].string_reference="100"; 10122 image=TintImage(image,argument_list[1].string_reference,&tint, 10123 exception); 10124 break; 10125 } 10126 case 86: /* Channel */ 10127 { 10128 if (attribute_flag[0] != 0) 10129 channel=(ChannelType) argument_list[0].integer_reference; 10130 image=SeparateImage(image,channel,exception); 10131 break; 10132 } 10133 case 87: /* Splice */ 10134 { 10135 if (attribute_flag[7] != 0) 10136 image->gravity=(GravityType) argument_list[7].integer_reference; 10137 if (attribute_flag[0] != 0) 10138 flags=ParseGravityGeometry(image,argument_list[0].string_reference, 10139 &geometry,exception); 10140 if (attribute_flag[1] != 0) 10141 geometry.width=argument_list[1].integer_reference; 10142 if (attribute_flag[2] != 0) 10143 geometry.height=argument_list[2].integer_reference; 10144 if (attribute_flag[3] != 0) 10145 geometry.x=argument_list[3].integer_reference; 10146 if (attribute_flag[4] != 0) 10147 geometry.y=argument_list[4].integer_reference; 10148 if (attribute_flag[5] != 0) 10149 image->fuzz=StringToDoubleInterval( 10150 argument_list[5].string_reference,(double) QuantumRange+1.0); 10151 if (attribute_flag[6] != 0) 10152 (void) QueryColorCompliance(argument_list[6].string_reference, 10153 AllCompliance,&image->background_color,exception); 10154 image=SpliceImage(image,&geometry,exception); 10155 break; 10156 } 10157 case 88: /* Posterize */ 10158 { 10159 if (attribute_flag[0] == 0) 10160 argument_list[0].integer_reference=3; 10161 if (attribute_flag[1] == 0) 10162 argument_list[1].integer_reference=0; 10163 (void) PosterizeImage(image,argument_list[0].integer_reference, 10164 argument_list[1].integer_reference ? RiemersmaDitherMethod : 10165 NoDitherMethod,exception); 10166 break; 10167 } 10168 case 89: /* Shadow */ 10169 { 10170 if (attribute_flag[0] != 0) 10171 { 10172 flags=ParseGeometry(argument_list[0].string_reference, 10173 &geometry_info); 10174 if ((flags & SigmaValue) == 0) 10175 geometry_info.sigma=1.0; 10176 if ((flags & XiValue) == 0) 10177 geometry_info.xi=4.0; 10178 if ((flags & PsiValue) == 0) 10179 geometry_info.psi=4.0; 10180 } 10181 if (attribute_flag[1] != 0) 10182 geometry_info.rho=argument_list[1].real_reference; 10183 if (attribute_flag[2] != 0) 10184 geometry_info.sigma=argument_list[2].real_reference; 10185 if (attribute_flag[3] != 0) 10186 geometry_info.xi=argument_list[3].integer_reference; 10187 if (attribute_flag[4] != 0) 10188 geometry_info.psi=argument_list[4].integer_reference; 10189 image=ShadowImage(image,geometry_info.rho,geometry_info.sigma, 10190 (ssize_t) ceil(geometry_info.xi-0.5),(ssize_t) 10191 ceil(geometry_info.psi-0.5),exception); 10192 break; 10193 } 10194 case 90: /* Identify */ 10195 { 10196 if (attribute_flag[0] == 0) 10197 argument_list[0].file_reference=(FILE *) NULL; 10198 if (attribute_flag[1] != 0) 10199 (void) SetImageArtifact(image,"identify:features", 10200 argument_list[1].string_reference); 10201 if ((attribute_flag[2] != 0) && 10202 (argument_list[2].integer_reference != 0)) 10203 (void) SetImageArtifact(image,"identify:unique","true"); 10204 (void) IdentifyImage(image,argument_list[0].file_reference, 10205 MagickTrue,exception); 10206 break; 10207 } 10208 case 91: /* SepiaTone */ 10209 { 10210 if (attribute_flag[0] == 0) 10211 argument_list[0].real_reference=80.0*QuantumRange/100.0; 10212 image=SepiaToneImage(image,argument_list[0].real_reference, 10213 exception); 10214 break; 10215 } 10216 case 92: /* SigmoidalContrast */ 10217 { 10218 MagickBooleanType 10219 sharpen; 10220 10221 if (attribute_flag[0] != 0) 10222 { 10223 flags=ParseGeometry(argument_list[0].string_reference, 10224 &geometry_info); 10225 if ((flags & SigmaValue) == 0) 10226 geometry_info.sigma=QuantumRange/2.0; 10227 if ((flags & PercentValue) != 0) 10228 geometry_info.sigma=QuantumRange*geometry_info.sigma/100.0; 10229 } 10230 if (attribute_flag[1] != 0) 10231 geometry_info.rho=argument_list[1].real_reference; 10232 if (attribute_flag[2] != 0) 10233 geometry_info.sigma=argument_list[2].real_reference; 10234 if (attribute_flag[3] != 0) 10235 channel=(ChannelType) argument_list[3].integer_reference; 10236 sharpen=MagickTrue; 10237 if (attribute_flag[4] != 0) 10238 sharpen=argument_list[4].integer_reference != 0 ? MagickTrue : 10239 MagickFalse; 10240 channel_mask=SetImageChannelMask(image,channel); 10241 (void) SigmoidalContrastImage(image,sharpen,geometry_info.rho, 10242 geometry_info.sigma,exception); 10243 (void) SetImageChannelMask(image,channel_mask); 10244 break; 10245 } 10246 case 93: /* Extent */ 10247 { 10248 if (attribute_flag[7] != 0) 10249 image->gravity=(GravityType) argument_list[7].integer_reference; 10250 if (attribute_flag[0] != 0) 10251 { 10252 int 10253 flags; 10254 10255 flags=ParseGravityGeometry(image, 10256 argument_list[0].string_reference,&geometry,exception); 10257 (void) flags; 10258 if (geometry.width == 0) 10259 geometry.width=image->columns; 10260 if (geometry.height == 0) 10261 geometry.height=image->rows; 10262 } 10263 if (attribute_flag[1] != 0) 10264 geometry.width=argument_list[1].integer_reference; 10265 if (attribute_flag[2] != 0) 10266 geometry.height=argument_list[2].integer_reference; 10267 if (attribute_flag[3] != 0) 10268 geometry.x=argument_list[3].integer_reference; 10269 if (attribute_flag[4] != 0) 10270 geometry.y=argument_list[4].integer_reference; 10271 if (attribute_flag[5] != 0) 10272 image->fuzz=StringToDoubleInterval( 10273 argument_list[5].string_reference,(double) QuantumRange+1.0); 10274 if (attribute_flag[6] != 0) 10275 (void) QueryColorCompliance(argument_list[6].string_reference, 10276 AllCompliance,&image->background_color,exception); 10277 image=ExtentImage(image,&geometry,exception); 10278 break; 10279 } 10280 case 94: /* Vignette */ 10281 { 10282 if (attribute_flag[0] != 0) 10283 { 10284 flags=ParseGeometry(argument_list[0].string_reference, 10285 &geometry_info); 10286 if ((flags & SigmaValue) == 0) 10287 geometry_info.sigma=1.0; 10288 if ((flags & XiValue) == 0) 10289 geometry_info.xi=0.1*image->columns; 10290 if ((flags & PsiValue) == 0) 10291 geometry_info.psi=0.1*image->rows; 10292 } 10293 if (attribute_flag[1] != 0) 10294 geometry_info.rho=argument_list[1].real_reference; 10295 if (attribute_flag[2] != 0) 10296 geometry_info.sigma=argument_list[2].real_reference; 10297 if (attribute_flag[3] != 0) 10298 geometry_info.xi=argument_list[3].integer_reference; 10299 if (attribute_flag[4] != 0) 10300 geometry_info.psi=argument_list[4].integer_reference; 10301 if (attribute_flag[5] != 0) 10302 (void) QueryColorCompliance(argument_list[5].string_reference, 10303 AllCompliance,&image->background_color,exception); 10304 image=VignetteImage(image,geometry_info.rho,geometry_info.sigma, 10305 (ssize_t) ceil(geometry_info.xi-0.5),(ssize_t) 10306 ceil(geometry_info.psi-0.5),exception); 10307 break; 10308 } 10309 case 95: /* ContrastStretch */ 10310 { 10311 double 10312 black_point, 10313 white_point; 10314 10315 black_point=0.0; 10316 white_point=(double) image->columns*image->rows; 10317 if (attribute_flag[0] != 0) 10318 { 10319 flags=ParseGeometry(argument_list[0].string_reference, 10320 &geometry_info); 10321 black_point=geometry_info.rho; 10322 white_point=(flags & SigmaValue) != 0 ? geometry_info.sigma : 10323 black_point; 10324 if ((flags & PercentValue) != 0) 10325 { 10326 black_point*=(double) image->columns*image->rows/100.0; 10327 white_point*=(double) image->columns*image->rows/100.0; 10328 } 10329 white_point=(double) image->columns*image->rows- 10330 white_point; 10331 } 10332 if (attribute_flag[1] != 0) 10333 black_point=argument_list[1].real_reference; 10334 if (attribute_flag[2] != 0) 10335 white_point=argument_list[2].real_reference; 10336 if (attribute_flag[4] != 0) 10337 channel=(ChannelType) argument_list[4].integer_reference; 10338 channel_mask=SetImageChannelMask(image,channel); 10339 (void) ContrastStretchImage(image,black_point,white_point,exception); 10340 (void) SetImageChannelMask(image,channel_mask); 10341 break; 10342 } 10343 case 96: /* Sans0 */ 10344 { 10345 break; 10346 } 10347 case 97: /* Sans1 */ 10348 { 10349 break; 10350 } 10351 case 98: /* AdaptiveSharpen */ 10352 { 10353 if (attribute_flag[0] != 0) 10354 { 10355 flags=ParseGeometry(argument_list[0].string_reference, 10356 &geometry_info); 10357 if ((flags & SigmaValue) == 0) 10358 geometry_info.sigma=1.0; 10359 if ((flags & XiValue) == 0) 10360 geometry_info.xi=0.0; 10361 } 10362 if (attribute_flag[1] != 0) 10363 geometry_info.rho=argument_list[1].real_reference; 10364 if (attribute_flag[2] != 0) 10365 geometry_info.sigma=argument_list[2].real_reference; 10366 if (attribute_flag[3] != 0) 10367 geometry_info.xi=argument_list[3].real_reference; 10368 if (attribute_flag[4] != 0) 10369 channel=(ChannelType) argument_list[4].integer_reference; 10370 channel_mask=SetImageChannelMask(image,channel); 10371 image=AdaptiveSharpenImage(image,geometry_info.rho, 10372 geometry_info.sigma,exception); 10373 if (image != (Image *) NULL) 10374 (void) SetImageChannelMask(image,channel_mask); 10375 break; 10376 } 10377 case 99: /* Transpose */ 10378 { 10379 image=TransposeImage(image,exception); 10380 break; 10381 } 10382 case 100: /* Tranverse */ 10383 { 10384 image=TransverseImage(image,exception); 10385 break; 10386 } 10387 case 101: /* AutoOrient */ 10388 { 10389 image=AutoOrientImage(image,image->orientation,exception); 10390 break; 10391 } 10392 case 102: /* AdaptiveBlur */ 10393 { 10394 if (attribute_flag[0] != 0) 10395 { 10396 flags=ParseGeometry(argument_list[0].string_reference, 10397 &geometry_info); 10398 if ((flags & SigmaValue) == 0) 10399 geometry_info.sigma=1.0; 10400 if ((flags & XiValue) == 0) 10401 geometry_info.xi=0.0; 10402 } 10403 if (attribute_flag[1] != 0) 10404 geometry_info.rho=argument_list[1].real_reference; 10405 if (attribute_flag[2] != 0) 10406 geometry_info.sigma=argument_list[2].real_reference; 10407 if (attribute_flag[3] != 0) 10408 channel=(ChannelType) argument_list[3].integer_reference; 10409 channel_mask=SetImageChannelMask(image,channel); 10410 image=AdaptiveBlurImage(image,geometry_info.rho,geometry_info.sigma, 10411 exception); 10412 if (image != (Image *) NULL) 10413 (void) SetImageChannelMask(image,channel_mask); 10414 break; 10415 } 10416 case 103: /* Sketch */ 10417 { 10418 if (attribute_flag[0] != 0) 10419 { 10420 flags=ParseGeometry(argument_list[0].string_reference, 10421 &geometry_info); 10422 if ((flags & SigmaValue) == 0) 10423 geometry_info.sigma=1.0; 10424 if ((flags & XiValue) == 0) 10425 geometry_info.xi=1.0; 10426 } 10427 if (attribute_flag[1] != 0) 10428 geometry_info.rho=argument_list[1].real_reference; 10429 if (attribute_flag[2] != 0) 10430 geometry_info.sigma=argument_list[2].real_reference; 10431 if (attribute_flag[3] != 0) 10432 geometry_info.xi=argument_list[3].real_reference; 10433 image=SketchImage(image,geometry_info.rho,geometry_info.sigma, 10434 geometry_info.xi,exception); 10435 break; 10436 } 10437 case 104: /* UniqueColors */ 10438 { 10439 image=UniqueImageColors(image,exception); 10440 break; 10441 } 10442 case 105: /* AdaptiveResize */ 10443 { 10444 if (attribute_flag[0] != 0) 10445 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 10446 &geometry,exception); 10447 if (attribute_flag[1] != 0) 10448 geometry.width=argument_list[1].integer_reference; 10449 if (attribute_flag[2] != 0) 10450 geometry.height=argument_list[2].integer_reference; 10451 if (attribute_flag[3] != 0) 10452 image->filter=(FilterType) argument_list[4].integer_reference; 10453 if (attribute_flag[4] != 0) 10454 SetImageArtifact(image,"filter:support", 10455 argument_list[4].string_reference); 10456 image=AdaptiveResizeImage(image,geometry.width,geometry.height, 10457 exception); 10458 break; 10459 } 10460 case 106: /* ClipMask */ 10461 { 10462 Image 10463 *mask_image; 10464 10465 if (attribute_flag[0] == 0) 10466 { 10467 ThrowPerlException(exception,OptionError,"MaskImageRequired", 10468 PackageName); 10469 goto PerlException; 10470 } 10471 mask_image=CloneImage(argument_list[0].image_reference,0,0,MagickTrue, 10472 exception); 10473 (void) SetImageMask(image,ReadPixelMask,mask_image,exception); 10474 mask_image=DestroyImage(mask_image); 10475 break; 10476 } 10477 case 107: /* LinearStretch */ 10478 { 10479 double 10480 black_point, 10481 white_point; 10482 10483 black_point=0.0; 10484 white_point=(double) image->columns*image->rows; 10485 if (attribute_flag[0] != 0) 10486 { 10487 flags=ParseGeometry(argument_list[0].string_reference, 10488 &geometry_info); 10489 if ((flags & SigmaValue) != 0) 10490 white_point=geometry_info.sigma; 10491 if ((flags & PercentValue) != 0) 10492 { 10493 black_point*=(double) image->columns*image->rows/100.0; 10494 white_point*=(double) image->columns*image->rows/100.0; 10495 } 10496 if ((flags & SigmaValue) == 0) 10497 white_point=(double) image->columns*image->rows-black_point; 10498 } 10499 if (attribute_flag[1] != 0) 10500 black_point=argument_list[1].real_reference; 10501 if (attribute_flag[2] != 0) 10502 white_point=argument_list[2].real_reference; 10503 (void) LinearStretchImage(image,black_point,white_point,exception); 10504 break; 10505 } 10506 case 108: /* ColorMatrix */ 10507 { 10508 AV 10509 *av; 10510 10511 double 10512 *color_matrix; 10513 10514 KernelInfo 10515 *kernel_info; 10516 10517 size_t 10518 order; 10519 10520 if (attribute_flag[0] == 0) 10521 break; 10522 av=(AV *) argument_list[0].array_reference; 10523 order=(size_t) sqrt(av_len(av)+1); 10524 color_matrix=(double *) AcquireQuantumMemory(order,order* 10525 sizeof(*color_matrix)); 10526 if (color_matrix == (double *) NULL) 10527 { 10528 ThrowPerlException(exception,ResourceLimitFatalError, 10529 "MemoryAllocationFailed",PackageName); 10530 goto PerlException; 10531 } 10532 for (j=0; (j < (ssize_t) (order*order)) && (j < (av_len(av)+1)); j++) 10533 color_matrix[j]=(double) SvNV(*(av_fetch(av,j,0))); 10534 for ( ; j < (ssize_t) (order*order); j++) 10535 color_matrix[j]=0.0; 10536 kernel_info=AcquireKernelInfo((const char *) NULL,exception); 10537 if (kernel_info == (KernelInfo *) NULL) 10538 break; 10539 kernel_info->width=order; 10540 kernel_info->height=order; 10541 kernel_info->values=(MagickRealType *) AcquireAlignedMemory(order, 10542 order*sizeof(*kernel_info->values)); 10543 if (kernel_info->values != (MagickRealType *) NULL) 10544 { 10545 for (i=0; i < (ssize_t) (order*order); i++) 10546 kernel_info->values[i]=(MagickRealType) color_matrix[i]; 10547 image=ColorMatrixImage(image,kernel_info,exception); 10548 } 10549 kernel_info=DestroyKernelInfo(kernel_info); 10550 color_matrix=(double *) RelinquishMagickMemory(color_matrix); 10551 break; 10552 } 10553 case 109: /* Mask */ 10554 { 10555 Image 10556 *mask_image; 10557 10558 if (attribute_flag[0] == 0) 10559 { 10560 ThrowPerlException(exception,OptionError,"MaskImageRequired", 10561 PackageName); 10562 goto PerlException; 10563 } 10564 mask_image=CloneImage(argument_list[0].image_reference,0,0, 10565 MagickTrue,exception); 10566 (void) SetImageMask(image,ReadPixelMask,mask_image,exception); 10567 mask_image=DestroyImage(mask_image); 10568 break; 10569 } 10570 case 110: /* Polaroid */ 10571 { 10572 char 10573 *caption; 10574 10575 DrawInfo 10576 *draw_info; 10577 10578 double 10579 angle; 10580 10581 PixelInterpolateMethod 10582 method; 10583 10584 draw_info=CloneDrawInfo(info ? info->image_info : (ImageInfo *) NULL, 10585 (DrawInfo *) NULL); 10586 caption=(char *) NULL; 10587 if (attribute_flag[0] != 0) 10588 caption=InterpretImageProperties(info ? info->image_info : 10589 (ImageInfo *) NULL,image,argument_list[0].string_reference, 10590 exception); 10591 angle=0.0; 10592 if (attribute_flag[1] != 0) 10593 angle=argument_list[1].real_reference; 10594 if (attribute_flag[2] != 0) 10595 (void) CloneString(&draw_info->font, 10596 argument_list[2].string_reference); 10597 if (attribute_flag[3] != 0) 10598 (void) QueryColorCompliance(argument_list[3].string_reference, 10599 AllCompliance,&draw_info->stroke,exception); 10600 if (attribute_flag[4] != 0) 10601 (void) QueryColorCompliance(argument_list[4].string_reference, 10602 AllCompliance,&draw_info->fill,exception); 10603 if (attribute_flag[5] != 0) 10604 draw_info->stroke_width=argument_list[5].real_reference; 10605 if (attribute_flag[6] != 0) 10606 draw_info->pointsize=argument_list[6].real_reference; 10607 if (attribute_flag[7] != 0) 10608 draw_info->gravity=(GravityType) argument_list[7].integer_reference; 10609 if (attribute_flag[8] != 0) 10610 (void) QueryColorCompliance(argument_list[8].string_reference, 10611 AllCompliance,&image->background_color,exception); 10612 method=UndefinedInterpolatePixel; 10613 if (attribute_flag[9] != 0) 10614 method=(PixelInterpolateMethod) argument_list[9].integer_reference; 10615 image=PolaroidImage(image,draw_info,caption,angle,method,exception); 10616 draw_info=DestroyDrawInfo(draw_info); 10617 if (caption != (char *) NULL) 10618 caption=DestroyString(caption); 10619 break; 10620 } 10621 case 111: /* FloodfillPaint */ 10622 { 10623 DrawInfo 10624 *draw_info; 10625 10626 MagickBooleanType 10627 invert; 10628 10629 PixelInfo 10630 target; 10631 10632 draw_info=CloneDrawInfo(info ? info->image_info : 10633 (ImageInfo *) NULL,(DrawInfo *) NULL); 10634 if (attribute_flag[0] != 0) 10635 flags=ParsePageGeometry(image,argument_list[0].string_reference, 10636 &geometry,exception); 10637 if (attribute_flag[1] != 0) 10638 geometry.x=argument_list[1].integer_reference; 10639 if (attribute_flag[2] != 0) 10640 geometry.y=argument_list[2].integer_reference; 10641 if (attribute_flag[3] != 0) 10642 (void) QueryColorCompliance(argument_list[3].string_reference, 10643 AllCompliance,&draw_info->fill,exception); 10644 (void) GetOneVirtualPixelInfo(image,UndefinedVirtualPixelMethod, 10645 geometry.x,geometry.y,&target,exception); 10646 if (attribute_flag[4] != 0) 10647 QueryColorCompliance(argument_list[4].string_reference, 10648 AllCompliance,&target,exception); 10649 if (attribute_flag[5] != 0) 10650 image->fuzz=StringToDoubleInterval( 10651 argument_list[5].string_reference,(double) QuantumRange+1.0); 10652 if (attribute_flag[6] != 0) 10653 channel=(ChannelType) argument_list[6].integer_reference; 10654 invert=MagickFalse; 10655 if (attribute_flag[7] != 0) 10656 invert=(MagickBooleanType) argument_list[7].integer_reference; 10657 channel_mask=SetImageChannelMask(image,channel); 10658 (void) FloodfillPaintImage(image,draw_info,&target,geometry.x, 10659 geometry.y,invert,exception); 10660 (void) SetImageChannelMask(image,channel_mask); 10661 draw_info=DestroyDrawInfo(draw_info); 10662 break; 10663 } 10664 case 112: /* Distort */ 10665 { 10666 AV 10667 *av; 10668 10669 double 10670 *coordinates; 10671 10672 DistortMethod 10673 method; 10674 10675 size_t 10676 number_coordinates; 10677 10678 VirtualPixelMethod 10679 virtual_pixel; 10680 10681 if (attribute_flag[0] == 0) 10682 break; 10683 method=UndefinedDistortion; 10684 if (attribute_flag[1] != 0) 10685 method=(DistortMethod) argument_list[1].integer_reference; 10686 av=(AV *) argument_list[0].array_reference; 10687 number_coordinates=(size_t) av_len(av)+1; 10688 coordinates=(double *) AcquireQuantumMemory(number_coordinates, 10689 sizeof(*coordinates)); 10690 if (coordinates == (double *) NULL) 10691 { 10692 ThrowPerlException(exception,ResourceLimitFatalError, 10693 "MemoryAllocationFailed",PackageName); 10694 goto PerlException; 10695 } 10696 for (j=0; j < (ssize_t) number_coordinates; j++) 10697 coordinates[j]=(double) SvNV(*(av_fetch(av,j,0))); 10698 virtual_pixel=UndefinedVirtualPixelMethod; 10699 if (attribute_flag[2] != 0) 10700 virtual_pixel=SetImageVirtualPixelMethod(image,(VirtualPixelMethod) 10701 argument_list[2].integer_reference,exception); 10702 image=DistortImage(image,method,number_coordinates,coordinates, 10703 argument_list[3].integer_reference != 0 ? MagickTrue : MagickFalse, 10704 exception); 10705 if ((attribute_flag[2] != 0) && (image != (Image *) NULL)) 10706 virtual_pixel=SetImageVirtualPixelMethod(image,virtual_pixel, 10707 exception); 10708 coordinates=(double *) RelinquishMagickMemory(coordinates); 10709 break; 10710 } 10711 case 113: /* Clut */ 10712 { 10713 PixelInterpolateMethod 10714 method; 10715 10716 if (attribute_flag[0] == 0) 10717 { 10718 ThrowPerlException(exception,OptionError,"ClutImageRequired", 10719 PackageName); 10720 goto PerlException; 10721 } 10722 method=UndefinedInterpolatePixel; 10723 if (attribute_flag[1] != 0) 10724 method=(PixelInterpolateMethod) argument_list[1].integer_reference; 10725 if (attribute_flag[2] != 0) 10726 channel=(ChannelType) argument_list[2].integer_reference; 10727 channel_mask=SetImageChannelMask(image,channel); 10728 (void) ClutImage(image,argument_list[0].image_reference,method, 10729 exception); 10730 (void) SetImageChannelMask(image,channel_mask); 10731 break; 10732 } 10733 case 114: /* LiquidRescale */ 10734 { 10735 if (attribute_flag[0] != 0) 10736 flags=ParseRegionGeometry(image,argument_list[0].string_reference, 10737 &geometry,exception); 10738 if (attribute_flag[1] != 0) 10739 geometry.width=argument_list[1].integer_reference; 10740 if (attribute_flag[2] != 0) 10741 geometry.height=argument_list[2].integer_reference; 10742 if (attribute_flag[3] == 0) 10743 argument_list[3].real_reference=1.0; 10744 if (attribute_flag[4] == 0) 10745 argument_list[4].real_reference=0.0; 10746 image=LiquidRescaleImage(image,geometry.width,geometry.height, 10747 argument_list[3].real_reference,argument_list[4].real_reference, 10748 exception); 10749 break; 10750 } 10751 case 115: /* EncipherImage */ 10752 { 10753 (void) EncipherImage(image,argument_list[0].string_reference, 10754 exception); 10755 break; 10756 } 10757 case 116: /* DecipherImage */ 10758 { 10759 (void) DecipherImage(image,argument_list[0].string_reference, 10760 exception); 10761 break; 10762 } 10763 case 117: /* Deskew */ 10764 { 10765 geometry_info.rho=QuantumRange/2.0; 10766 if (attribute_flag[0] != 0) 10767 flags=ParseGeometry(argument_list[0].string_reference, 10768 &geometry_info); 10769 if (attribute_flag[1] != 0) 10770 geometry_info.rho=StringToDoubleInterval( 10771 argument_list[1].string_reference,(double) QuantumRange+1.0); 10772 image=DeskewImage(image,geometry_info.rho,exception); 10773 break; 10774 } 10775 case 118: /* Remap */ 10776 { 10777 QuantizeInfo 10778 *quantize_info; 10779 10780 if (attribute_flag[0] == 0) 10781 { 10782 ThrowPerlException(exception,OptionError,"RemapImageRequired", 10783 PackageName); 10784 goto PerlException; 10785 } 10786 quantize_info=AcquireQuantizeInfo(info->image_info); 10787 if (attribute_flag[1] != 0) 10788 quantize_info->dither_method=(DitherMethod) 10789 argument_list[1].integer_reference; 10790 (void) RemapImages(quantize_info,image, 10791 argument_list[0].image_reference,exception); 10792 quantize_info=DestroyQuantizeInfo(quantize_info); 10793 break; 10794 } 10795 case 119: /* SparseColor */ 10796 { 10797 AV 10798 *av; 10799 10800 double 10801 *coordinates; 10802 10803 SparseColorMethod 10804 method; 10805 10806 size_t 10807 number_coordinates; 10808 10809 VirtualPixelMethod 10810 virtual_pixel; 10811 10812 if (attribute_flag[0] == 0) 10813 break; 10814 method=UndefinedColorInterpolate; 10815 if (attribute_flag[1] != 0) 10816 method=(SparseColorMethod) argument_list[1].integer_reference; 10817 av=(AV *) argument_list[0].array_reference; 10818 number_coordinates=(size_t) av_len(av)+1; 10819 coordinates=(double *) AcquireQuantumMemory(number_coordinates, 10820 sizeof(*coordinates)); 10821 if (coordinates == (double *) NULL) 10822 { 10823 ThrowPerlException(exception,ResourceLimitFatalError, 10824 "MemoryAllocationFailed",PackageName); 10825 goto PerlException; 10826 } 10827 for (j=0; j < (ssize_t) number_coordinates; j++) 10828 coordinates[j]=(double) SvNV(*(av_fetch(av,j,0))); 10829 virtual_pixel=UndefinedVirtualPixelMethod; 10830 if (attribute_flag[2] != 0) 10831 virtual_pixel=SetImageVirtualPixelMethod(image,(VirtualPixelMethod) 10832 argument_list[2].integer_reference,exception); 10833 if (attribute_flag[3] != 0) 10834 channel=(ChannelType) argument_list[3].integer_reference; 10835 channel_mask=SetImageChannelMask(image,channel); 10836 image=SparseColorImage(image,method,number_coordinates,coordinates, 10837 exception); 10838 if (image != (Image *) NULL) 10839 (void) SetImageChannelMask(image,channel_mask); 10840 if ((attribute_flag[2] != 0) && (image != (Image *) NULL)) 10841 virtual_pixel=SetImageVirtualPixelMethod(image,virtual_pixel, 10842 exception); 10843 coordinates=(double *) RelinquishMagickMemory(coordinates); 10844 break; 10845 } 10846 case 120: /* Function */ 10847 { 10848 AV 10849 *av; 10850 10851 double 10852 *parameters; 10853 10854 MagickFunction 10855 function; 10856 10857 size_t 10858 number_parameters; 10859 10860 VirtualPixelMethod 10861 virtual_pixel; 10862 10863 if (attribute_flag[0] == 0) 10864 break; 10865 function=UndefinedFunction; 10866 if (attribute_flag[1] != 0) 10867 function=(MagickFunction) argument_list[1].integer_reference; 10868 av=(AV *) argument_list[0].array_reference; 10869 number_parameters=(size_t) av_len(av)+1; 10870 parameters=(double *) AcquireQuantumMemory(number_parameters, 10871 sizeof(*parameters)); 10872 if (parameters == (double *) NULL) 10873 { 10874 ThrowPerlException(exception,ResourceLimitFatalError, 10875 "MemoryAllocationFailed",PackageName); 10876 goto PerlException; 10877 } 10878 for (j=0; j < (ssize_t) number_parameters; j++) 10879 parameters[j]=(double) SvNV(*(av_fetch(av,j,0))); 10880 virtual_pixel=UndefinedVirtualPixelMethod; 10881 if (attribute_flag[2] != 0) 10882 virtual_pixel=SetImageVirtualPixelMethod(image,(VirtualPixelMethod) 10883 argument_list[2].integer_reference,exception); 10884 (void) FunctionImage(image,function,number_parameters,parameters, 10885 exception); 10886 if ((attribute_flag[2] != 0) && (image != (Image *) NULL)) 10887 virtual_pixel=SetImageVirtualPixelMethod(image,virtual_pixel, 10888 exception); 10889 parameters=(double *) RelinquishMagickMemory(parameters); 10890 break; 10891 } 10892 case 121: /* SelectiveBlur */ 10893 { 10894 if (attribute_flag[0] != 0) 10895 { 10896 flags=ParseGeometry(argument_list[0].string_reference, 10897 &geometry_info); 10898 if ((flags & SigmaValue) == 0) 10899 geometry_info.sigma=1.0; 10900 if ((flags & PercentValue) != 0) 10901 geometry_info.xi=QuantumRange*geometry_info.xi/100.0; 10902 } 10903 if (attribute_flag[1] != 0) 10904 geometry_info.rho=argument_list[1].real_reference; 10905 if (attribute_flag[2] != 0) 10906 geometry_info.sigma=argument_list[2].real_reference; 10907 if (attribute_flag[3] != 0) 10908 geometry_info.xi=argument_list[3].integer_reference;; 10909 if (attribute_flag[5] != 0) 10910 channel=(ChannelType) argument_list[5].integer_reference; 10911 channel_mask=SetImageChannelMask(image,channel); 10912 image=SelectiveBlurImage(image,geometry_info.rho,geometry_info.sigma, 10913 geometry_info.xi,exception); 10914 if (image != (Image *) NULL) 10915 (void) SetImageChannelMask(image,channel_mask); 10916 break; 10917 } 10918 case 122: /* HaldClut */ 10919 { 10920 if (attribute_flag[0] == 0) 10921 { 10922 ThrowPerlException(exception,OptionError,"ClutImageRequired", 10923 PackageName); 10924 goto PerlException; 10925 } 10926 if (attribute_flag[1] != 0) 10927 channel=(ChannelType) argument_list[1].integer_reference; 10928 channel_mask=SetImageChannelMask(image,channel); 10929 (void) HaldClutImage(image,argument_list[0].image_reference, 10930 exception); 10931 (void) SetImageChannelMask(image,channel_mask); 10932 break; 10933 } 10934 case 123: /* BlueShift */ 10935 { 10936 if (attribute_flag[0] != 0) 10937 (void) ParseGeometry(argument_list[0].string_reference, 10938 &geometry_info); 10939 image=BlueShiftImage(image,geometry_info.rho,exception); 10940 break; 10941 } 10942 case 124: /* ForwardFourierTransformImage */ 10943 { 10944 image=ForwardFourierTransformImage(image, 10945 argument_list[0].integer_reference != 0 ? MagickTrue : MagickFalse, 10946 exception); 10947 break; 10948 } 10949 case 125: /* InverseFourierTransformImage */ 10950 { 10951 image=InverseFourierTransformImage(image,image->next, 10952 argument_list[0].integer_reference != 0 ? MagickTrue : MagickFalse, 10953 exception); 10954 break; 10955 } 10956 case 126: /* ColorDecisionList */ 10957 { 10958 if (attribute_flag[0] == 0) 10959 argument_list[0].string_reference=(char *) NULL; 10960 (void) ColorDecisionListImage(image, 10961 argument_list[0].string_reference,exception); 10962 break; 10963 } 10964 case 127: /* AutoGamma */ 10965 { 10966 if (attribute_flag[0] != 0) 10967 channel=(ChannelType) argument_list[0].integer_reference; 10968 channel_mask=SetImageChannelMask(image,channel); 10969 (void) AutoGammaImage(image,exception); 10970 (void) SetImageChannelMask(image,channel_mask); 10971 break; 10972 } 10973 case 128: /* AutoLevel */ 10974 { 10975 if (attribute_flag[0] != 0) 10976 channel=(ChannelType) argument_list[0].integer_reference; 10977 channel_mask=SetImageChannelMask(image,channel); 10978 (void) AutoLevelImage(image,exception); 10979 (void) SetImageChannelMask(image,channel_mask); 10980 break; 10981 } 10982 case 129: /* LevelColors */ 10983 { 10984 PixelInfo 10985 black_point, 10986 white_point; 10987 10988 (void) QueryColorCompliance("#000000",AllCompliance,&black_point, 10989 exception); 10990 (void) QueryColorCompliance("#ffffff",AllCompliance,&white_point, 10991 exception); 10992 if (attribute_flag[1] != 0) 10993 (void) QueryColorCompliance( 10994 argument_list[1].string_reference,AllCompliance,&black_point, 10995 exception); 10996 if (attribute_flag[2] != 0) 10997 (void) QueryColorCompliance( 10998 argument_list[2].string_reference,AllCompliance,&white_point, 10999 exception); 11000 if (attribute_flag[3] != 0) 11001 channel=(ChannelType) argument_list[3].integer_reference; 11002 channel_mask=SetImageChannelMask(image,channel); 11003 (void) LevelImageColors(image,&black_point,&white_point, 11004 argument_list[0].integer_reference != 0 ? MagickTrue : MagickFalse, 11005 exception); 11006 (void) SetImageChannelMask(image,channel_mask); 11007 break; 11008 } 11009 case 130: /* Clamp */ 11010 { 11011 if (attribute_flag[0] != 0) 11012 channel=(ChannelType) argument_list[0].integer_reference; 11013 channel_mask=SetImageChannelMask(image,channel); 11014 (void) ClampImage(image,exception); 11015 (void) SetImageChannelMask(image,channel_mask); 11016 break; 11017 } 11018 case 131: /* BrightnessContrast */ 11019 { 11020 double 11021 brightness, 11022 contrast; 11023 11024 brightness=0.0; 11025 contrast=0.0; 11026 if (attribute_flag[0] != 0) 11027 { 11028 flags=ParseGeometry(argument_list[0].string_reference, 11029 &geometry_info); 11030 brightness=geometry_info.rho; 11031 if ((flags & SigmaValue) == 0) 11032 contrast=geometry_info.sigma; 11033 } 11034 if (attribute_flag[1] != 0) 11035 brightness=argument_list[1].real_reference; 11036 if (attribute_flag[2] != 0) 11037 contrast=argument_list[2].real_reference; 11038 if (attribute_flag[4] != 0) 11039 channel=(ChannelType) argument_list[4].integer_reference; 11040 channel_mask=SetImageChannelMask(image,channel); 11041 (void) BrightnessContrastImage(image,brightness,contrast,exception); 11042 (void) SetImageChannelMask(image,channel_mask); 11043 break; 11044 } 11045 case 132: /* Morphology */ 11046 { 11047 KernelInfo 11048 *kernel; 11049 11050 MorphologyMethod 11051 method; 11052 11053 ssize_t 11054 iterations; 11055 11056 if (attribute_flag[0] == 0) 11057 break; 11058 kernel=AcquireKernelInfo(argument_list[0].string_reference,exception); 11059 if (kernel == (KernelInfo *) NULL) 11060 break; 11061 if (attribute_flag[1] != 0) 11062 channel=(ChannelType) argument_list[1].integer_reference; 11063 method=UndefinedMorphology; 11064 if (attribute_flag[2] != 0) 11065 method=argument_list[2].integer_reference; 11066 iterations=1; 11067 if (attribute_flag[3] != 0) 11068 iterations=argument_list[3].integer_reference; 11069 channel_mask=SetImageChannelMask(image,channel); 11070 image=MorphologyImage(image,method,iterations,kernel,exception); 11071 if (image != (Image *) NULL) 11072 (void) SetImageChannelMask(image,channel_mask); 11073 kernel=DestroyKernelInfo(kernel); 11074 break; 11075 } 11076 case 133: /* Mode */ 11077 { 11078 if (attribute_flag[0] != 0) 11079 { 11080 flags=ParseGeometry(argument_list[0].string_reference, 11081 &geometry_info); 11082 if ((flags & SigmaValue) == 0) 11083 geometry_info.sigma=1.0; 11084 } 11085 if (attribute_flag[1] != 0) 11086 geometry_info.rho=argument_list[1].real_reference; 11087 if (attribute_flag[2] != 0) 11088 geometry_info.sigma=argument_list[2].real_reference; 11089 if (attribute_flag[3] != 0) 11090 channel=(ChannelType) argument_list[3].integer_reference; 11091 channel_mask=SetImageChannelMask(image,channel); 11092 image=StatisticImage(image,ModeStatistic,(size_t) geometry_info.rho, 11093 (size_t) geometry_info.sigma,exception); 11094 if (image != (Image *) NULL) 11095 (void) SetImageChannelMask(image,channel_mask); 11096 break; 11097 } 11098 case 134: /* Statistic */ 11099 { 11100 StatisticType 11101 statistic; 11102 11103 statistic=UndefinedStatistic; 11104 if (attribute_flag[0] != 0) 11105 { 11106 flags=ParseGeometry(argument_list[0].string_reference, 11107 &geometry_info); 11108 if ((flags & SigmaValue) == 0) 11109 geometry_info.sigma=1.0; 11110 } 11111 if (attribute_flag[1] != 0) 11112 geometry_info.rho=argument_list[1].real_reference; 11113 if (attribute_flag[2] != 0) 11114 geometry_info.sigma=argument_list[2].real_reference; 11115 if (attribute_flag[3] != 0) 11116 channel=(ChannelType) argument_list[3].integer_reference; 11117 if (attribute_flag[4] != 0) 11118 statistic=(StatisticType) argument_list[4].integer_reference; 11119 channel_mask=SetImageChannelMask(image,channel); 11120 image=StatisticImage(image,statistic,(size_t) geometry_info.rho, 11121 (size_t) geometry_info.sigma,exception); 11122 if (image != (Image *) NULL) 11123 (void) SetImageChannelMask(image,channel_mask); 11124 break; 11125 } 11126 case 135: /* Perceptible */ 11127 { 11128 double 11129 epsilon; 11130 11131 epsilon=MagickEpsilon; 11132 if (attribute_flag[0] != 0) 11133 epsilon=argument_list[0].real_reference; 11134 if (attribute_flag[1] != 0) 11135 channel=(ChannelType) argument_list[1].integer_reference; 11136 channel_mask=SetImageChannelMask(image,channel); 11137 (void) PerceptibleImage(image,epsilon,exception); 11138 (void) SetImageChannelMask(image,channel_mask); 11139 break; 11140 } 11141 case 136: /* Poly */ 11142 { 11143 AV 11144 *av; 11145 11146 double 11147 *terms; 11148 11149 size_t 11150 number_terms; 11151 11152 if (attribute_flag[0] == 0) 11153 break; 11154 if (attribute_flag[1] != 0) 11155 channel=(ChannelType) argument_list[1].integer_reference; 11156 av=(AV *) argument_list[0].array_reference; 11157 number_terms=(size_t) av_len(av); 11158 terms=(double *) AcquireQuantumMemory(number_terms,sizeof(*terms)); 11159 if (terms == (double *) NULL) 11160 { 11161 ThrowPerlException(exception,ResourceLimitFatalError, 11162 "MemoryAllocationFailed",PackageName); 11163 goto PerlException; 11164 } 11165 for (j=0; j < av_len(av); j++) 11166 terms[j]=(double) SvNV(*(av_fetch(av,j,0))); 11167 image=PolynomialImage(image,number_terms >> 1,terms,exception); 11168 terms=(double *) RelinquishMagickMemory(terms); 11169 break; 11170 } 11171 case 137: /* Grayscale */ 11172 { 11173 PixelIntensityMethod 11174 method; 11175 11176 method=UndefinedPixelIntensityMethod; 11177 if (attribute_flag[0] != 0) 11178 method=(PixelIntensityMethod) argument_list[0].integer_reference; 11179 (void) GrayscaleImage(image,method,exception); 11180 break; 11181 } 11182 case 138: /* Canny */ 11183 { 11184 if (attribute_flag[0] != 0) 11185 { 11186 flags=ParseGeometry(argument_list[0].string_reference, 11187 &geometry_info); 11188 if ((flags & SigmaValue) == 0) 11189 geometry_info.sigma=1.0; 11190 if ((flags & XiValue) == 0) 11191 geometry_info.xi=0.10; 11192 if ((flags & PsiValue) == 0) 11193 geometry_info.psi=0.30; 11194 if ((flags & PercentValue) != 0) 11195 { 11196 geometry_info.xi/=100.0; 11197 geometry_info.psi/=100.0; 11198 } 11199 } 11200 if (attribute_flag[1] != 0) 11201 geometry_info.rho=argument_list[1].real_reference; 11202 if (attribute_flag[2] != 0) 11203 geometry_info.sigma=argument_list[2].real_reference; 11204 if (attribute_flag[3] != 0) 11205 geometry_info.xi=argument_list[3].real_reference; 11206 if (attribute_flag[4] != 0) 11207 geometry_info.psi=argument_list[4].real_reference; 11208 if (attribute_flag[5] != 0) 11209 channel=(ChannelType) argument_list[5].integer_reference; 11210 channel_mask=SetImageChannelMask(image,channel); 11211 image=CannyEdgeImage(image,geometry_info.rho,geometry_info.sigma, 11212 geometry_info.xi,geometry_info.psi,exception); 11213 if (image != (Image *) NULL) 11214 (void) SetImageChannelMask(image,channel_mask); 11215 break; 11216 } 11217 case 139: /* HoughLine */ 11218 { 11219 if (attribute_flag[0] != 0) 11220 { 11221 flags=ParseGeometry(argument_list[0].string_reference, 11222 &geometry_info); 11223 if ((flags & SigmaValue) == 0) 11224 geometry_info.sigma=geometry_info.rho; 11225 if ((flags & XiValue) == 0) 11226 geometry_info.xi=40; 11227 } 11228 if (attribute_flag[1] != 0) 11229 geometry_info.rho=(double) argument_list[1].integer_reference; 11230 if (attribute_flag[2] != 0) 11231 geometry_info.sigma=(double) argument_list[2].integer_reference; 11232 if (attribute_flag[3] != 0) 11233 geometry_info.xi=(double) argument_list[3].integer_reference; 11234 image=HoughLineImage(image,(size_t) geometry_info.rho,(size_t) 11235 geometry_info.sigma,(size_t) geometry_info.xi,exception); 11236 break; 11237 } 11238 case 140: /* MeanShift */ 11239 { 11240 if (attribute_flag[0] != 0) 11241 { 11242 flags=ParseGeometry(argument_list[0].string_reference, 11243 &geometry_info); 11244 if ((flags & SigmaValue) == 0) 11245 geometry_info.sigma=geometry_info.rho; 11246 if ((flags & XiValue) == 0) 11247 geometry_info.xi=0.10*QuantumRange; 11248 if ((flags & PercentValue) != 0) 11249 geometry_info.xi=QuantumRange*geometry_info.xi/100.0; 11250 } 11251 if (attribute_flag[1] != 0) 11252 geometry_info.rho=(double) argument_list[1].integer_reference; 11253 if (attribute_flag[2] != 0) 11254 geometry_info.sigma=(double) argument_list[2].integer_reference; 11255 if (attribute_flag[3] != 0) 11256 geometry_info.xi=(double) argument_list[3].integer_reference; 11257 image=MeanShiftImage(image,(size_t) geometry_info.rho,(size_t) 11258 geometry_info.sigma,geometry_info.xi,exception); 11259 break; 11260 } 11261 case 141: /* Kuwahara */ 11262 { 11263 if (attribute_flag[0] != 0) 11264 { 11265 flags=ParseGeometry(argument_list[0].string_reference, 11266 &geometry_info); 11267 if ((flags & SigmaValue) == 0) 11268 geometry_info.sigma=geometry_info.rho-0.5; 11269 } 11270 if (attribute_flag[1] != 0) 11271 geometry_info.rho=argument_list[1].real_reference; 11272 if (attribute_flag[2] != 0) 11273 geometry_info.sigma=argument_list[2].real_reference; 11274 if (attribute_flag[3] != 0) 11275 channel=(ChannelType) argument_list[3].integer_reference; 11276 channel_mask=SetImageChannelMask(image,channel); 11277 image=KuwaharaImage(image,geometry_info.rho,geometry_info.sigma, 11278 exception); 11279 if (image != (Image *) NULL) 11280 (void) SetImageChannelMask(image,channel_mask); 11281 break; 11282 } 11283 case 142: /* ConnectedComponent */ 11284 { 11285 size_t 11286 connectivity; 11287 11288 connectivity=4; 11289 if (attribute_flag[0] != 0) 11290 connectivity=argument_list[0].integer_reference; 11291 image=ConnectedComponentsImage(image,connectivity, 11292 (CCObjectInfo **) NULL,exception); 11293 break; 11294 } 11295 case 143: /* Copy */ 11296 { 11297 Image 11298 *source_image; 11299 11300 OffsetInfo 11301 offset; 11302 11303 RectangleInfo 11304 offset_geometry; 11305 11306 source_image=image; 11307 if (attribute_flag[0] != 0) 11308 source_image=argument_list[0].image_reference; 11309 SetGeometry(source_image,&geometry); 11310 if (attribute_flag[1] != 0) 11311 flags=ParseGravityGeometry(source_image, 11312 argument_list[1].string_reference,&geometry,exception); 11313 if (attribute_flag[2] != 0) 11314 geometry.width=argument_list[2].integer_reference; 11315 if (attribute_flag[3] != 0) 11316 geometry.height=argument_list[3].integer_reference; 11317 if (attribute_flag[4] != 0) 11318 geometry.x=argument_list[4].integer_reference; 11319 if (attribute_flag[5] != 0) 11320 geometry.y=argument_list[5].integer_reference; 11321 if (attribute_flag[6] != 0) 11322 image->gravity=(GravityType) argument_list[6].integer_reference; 11323 SetGeometry(image,&offset_geometry); 11324 if (attribute_flag[7] != 0) 11325 flags=ParseGravityGeometry(image,argument_list[7].string_reference, 11326 &offset_geometry,exception); 11327 offset.x=offset_geometry.x; 11328 offset.y=offset_geometry.y; 11329 if (attribute_flag[8] != 0) 11330 offset.x=argument_list[8].integer_reference; 11331 if (attribute_flag[9] != 0) 11332 offset.y=argument_list[9].integer_reference; 11333 (void) CopyImagePixels(image,source_image,&geometry,&offset, 11334 exception); 11335 break; 11336 } 11337 case 144: /* Color */ 11338 { 11339 PixelInfo 11340 color; 11341 11342 (void) QueryColorCompliance("none",AllCompliance,&color,exception); 11343 if (attribute_flag[0] != 0) 11344 (void) QueryColorCompliance(argument_list[0].string_reference, 11345 AllCompliance,&color,exception); 11346 (void) SetImageColor(image,&color,exception); 11347 break; 11348 } 11349 case 145: /* WaveletDenoise */ 11350 { 11351 if (attribute_flag[0] != 0) 11352 { 11353 flags=ParseGeometry(argument_list[0].string_reference, 11354 &geometry_info); 11355 if ((flags & PercentValue) != 0) 11356 { 11357 geometry_info.rho=QuantumRange*geometry_info.rho/100.0; 11358 geometry_info.sigma=QuantumRange*geometry_info.sigma/100.0; 11359 } 11360 if ((flags & SigmaValue) == 0) 11361 geometry_info.sigma=0.0; 11362 } 11363 if (attribute_flag[1] != 0) 11364 geometry_info.rho=argument_list[1].real_reference; 11365 if (attribute_flag[2] != 0) 11366 geometry_info.sigma=argument_list[2].real_reference; 11367 if (attribute_flag[3] != 0) 11368 channel=(ChannelType) argument_list[3].integer_reference; 11369 channel_mask=SetImageChannelMask(image,channel); 11370 image=WaveletDenoiseImage(image,geometry_info.rho,geometry_info.sigma, 11371 exception); 11372 if (image != (Image *) NULL) 11373 (void) SetImageChannelMask(image,channel_mask); 11374 break; 11375 } 11376 } 11377 if (next != (Image *) NULL) 11378 (void) CatchImageException(next); 11379 if (region_image != (Image *) NULL) 11380 { 11381 /* 11382 Composite region. 11383 */ 11384 status=CompositeImage(region_image,image,CopyCompositeOp,MagickTrue, 11385 region_info.x,region_info.y,exception); 11386 (void) status; 11387 (void) CatchImageException(region_image); 11388 image=DestroyImage(image); 11389 image=region_image; 11390 } 11391 if (image != (Image *) NULL) 11392 { 11393 number_images++; 11394 if (next && (next != image)) 11395 { 11396 image->next=next->next; 11397 if (image->next != (Image *) NULL) 11398 image->next->previous=image; 11399 DeleteImageFromRegistry(*pv,next); 11400 } 11401 sv_setiv(*pv,PTR2IV(image)); 11402 next=image; 11403 } 11404 if (*pv) 11405 pv++; 11406 } 11407 11408 PerlException: 11409 if (reference_vector) 11410 reference_vector=(SV **) RelinquishMagickMemory(reference_vector); 11411 InheritPerlException(exception,perl_exception); 11412 exception=DestroyExceptionInfo(exception); 11413 sv_setiv(perl_exception,(IV) number_images); 11414 SvPOK_on(perl_exception); 11415 ST(0)=sv_2mortal(perl_exception); 11416 XSRETURN(1); 11417 } 11418 11419 # 11421 ############################################################################### 11422 # # 11423 # # 11424 # # 11425 # M o n t a g e # 11426 # # 11427 # # 11428 # # 11429 ############################################################################### 11430 # 11431 # 11432 void 11433 Montage(ref,...) 11434 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 11435 ALIAS: 11436 MontageImage = 1 11437 montage = 2 11438 montageimage = 3 11439 PPCODE: 11440 { 11441 AV 11442 *av; 11443 11444 char 11445 *attribute; 11446 11447 ExceptionInfo 11448 *exception; 11449 11450 HV 11451 *hv; 11452 11453 Image 11454 *image, 11455 *next; 11456 11457 PixelInfo 11458 transparent_color; 11459 11460 MontageInfo 11461 *montage_info; 11462 11463 register ssize_t 11464 i; 11465 11466 ssize_t 11467 sp; 11468 11469 struct PackageInfo 11470 *info; 11471 11472 SV 11473 *av_reference, 11474 *perl_exception, 11475 *reference, 11476 *rv, 11477 *sv; 11478 11479 PERL_UNUSED_VAR(ref); 11480 PERL_UNUSED_VAR(ix); 11481 exception=AcquireExceptionInfo(); 11482 perl_exception=newSVpv("",0); 11483 sv=NULL; 11484 attribute=NULL; 11485 if (sv_isobject(ST(0)) == 0) 11486 { 11487 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 11488 PackageName); 11489 goto PerlException; 11490 } 11491 reference=SvRV(ST(0)); 11492 hv=SvSTASH(reference); 11493 av=newAV(); 11494 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 11495 SvREFCNT_dec(av); 11496 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 11497 if (image == (Image *) NULL) 11498 { 11499 ThrowPerlException(exception,OptionError,"NoImagesDefined", 11500 PackageName); 11501 goto PerlException; 11502 } 11503 /* 11504 Get options. 11505 */ 11506 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 11507 montage_info=CloneMontageInfo(info->image_info,(MontageInfo *) NULL); 11508 (void) QueryColorCompliance("none",AllCompliance,&transparent_color, 11509 exception); 11510 for (i=2; i < items; i+=2) 11511 { 11512 attribute=(char *) SvPV(ST(i-1),na); 11513 switch (*attribute) 11514 { 11515 case 'B': 11516 case 'b': 11517 { 11518 if (LocaleCompare(attribute,"background") == 0) 11519 { 11520 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11521 &montage_info->background_color,exception); 11522 for (next=image; next; next=next->next) 11523 next->background_color=montage_info->background_color; 11524 break; 11525 } 11526 if (LocaleCompare(attribute,"border") == 0) 11527 { 11528 montage_info->border_width=SvIV(ST(i)); 11529 break; 11530 } 11531 if (LocaleCompare(attribute,"bordercolor") == 0) 11532 { 11533 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11534 &montage_info->border_color,exception); 11535 for (next=image; next; next=next->next) 11536 next->border_color=montage_info->border_color; 11537 break; 11538 } 11539 if (LocaleCompare(attribute,"borderwidth") == 0) 11540 { 11541 montage_info->border_width=SvIV(ST(i)); 11542 break; 11543 } 11544 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11545 attribute); 11546 break; 11547 } 11548 case 'C': 11549 case 'c': 11550 { 11551 if (LocaleCompare(attribute,"compose") == 0) 11552 { 11553 sp=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 11554 MagickComposeOptions,MagickFalse,SvPV(ST(i),na)); 11555 if (sp < 0) 11556 { 11557 ThrowPerlException(exception,OptionError,"UnrecognizedType", 11558 SvPV(ST(i),na)); 11559 break; 11560 } 11561 for (next=image; next; next=next->next) 11562 next->compose=(CompositeOperator) sp; 11563 break; 11564 } 11565 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11566 attribute); 11567 break; 11568 } 11569 case 'F': 11570 case 'f': 11571 { 11572 if (LocaleCompare(attribute,"fill") == 0) 11573 { 11574 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11575 &montage_info->fill,exception); 11576 break; 11577 } 11578 if (LocaleCompare(attribute,"font") == 0) 11579 { 11580 (void) CloneString(&montage_info->font,SvPV(ST(i),na)); 11581 break; 11582 } 11583 if (LocaleCompare(attribute,"frame") == 0) 11584 { 11585 char 11586 *p; 11587 11588 p=SvPV(ST(i),na); 11589 if (IsGeometry(p) == MagickFalse) 11590 { 11591 ThrowPerlException(exception,OptionError,"MissingGeometry", 11592 p); 11593 break; 11594 } 11595 (void) CloneString(&montage_info->frame,p); 11596 if (*p == '\0') 11597 montage_info->frame=(char *) NULL; 11598 break; 11599 } 11600 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11601 attribute); 11602 break; 11603 } 11604 case 'G': 11605 case 'g': 11606 { 11607 if (LocaleCompare(attribute,"geometry") == 0) 11608 { 11609 char 11610 *p; 11611 11612 p=SvPV(ST(i),na); 11613 if (IsGeometry(p) == MagickFalse) 11614 { 11615 ThrowPerlException(exception,OptionError,"MissingGeometry", 11616 p); 11617 break; 11618 } 11619 (void) CloneString(&montage_info->geometry,p); 11620 if (*p == '\0') 11621 montage_info->geometry=(char *) NULL; 11622 break; 11623 } 11624 if (LocaleCompare(attribute,"gravity") == 0) 11625 { 11626 ssize_t 11627 in; 11628 11629 in=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 11630 MagickGravityOptions,MagickFalse,SvPV(ST(i),na)); 11631 if (in < 0) 11632 { 11633 ThrowPerlException(exception,OptionError,"UnrecognizedType", 11634 SvPV(ST(i),na)); 11635 return; 11636 } 11637 montage_info->gravity=(GravityType) in; 11638 for (next=image; next; next=next->next) 11639 next->gravity=(GravityType) in; 11640 break; 11641 } 11642 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11643 attribute); 11644 break; 11645 } 11646 case 'L': 11647 case 'l': 11648 { 11649 if (LocaleCompare(attribute,"label") == 0) 11650 { 11651 for (next=image; next; next=next->next) 11652 (void) SetImageProperty(next,"label",InterpretImageProperties( 11653 info ? info->image_info : (ImageInfo *) NULL,next, 11654 SvPV(ST(i),na),exception),exception); 11655 break; 11656 } 11657 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11658 attribute); 11659 break; 11660 } 11661 case 'M': 11662 case 'm': 11663 { 11664 if (LocaleCompare(attribute,"mattecolor") == 0) 11665 { 11666 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11667 &montage_info->alpha_color,exception); 11668 for (next=image; next; next=next->next) 11669 next->alpha_color=montage_info->alpha_color; 11670 break; 11671 } 11672 if (LocaleCompare(attribute,"mode") == 0) 11673 { 11674 ssize_t 11675 in; 11676 11677 in=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 11678 MagickModeOptions,MagickFalse,SvPV(ST(i),na)); 11679 switch (in) 11680 { 11681 default: 11682 { 11683 ThrowPerlException(exception,OptionError, 11684 "UnrecognizedModeType",SvPV(ST(i),na)); 11685 break; 11686 } 11687 case FrameMode: 11688 { 11689 (void) CloneString(&montage_info->frame,"15x15+3+3"); 11690 montage_info->shadow=MagickTrue; 11691 break; 11692 } 11693 case UnframeMode: 11694 { 11695 montage_info->frame=(char *) NULL; 11696 montage_info->shadow=MagickFalse; 11697 montage_info->border_width=0; 11698 break; 11699 } 11700 case ConcatenateMode: 11701 { 11702 montage_info->frame=(char *) NULL; 11703 montage_info->shadow=MagickFalse; 11704 (void) CloneString(&montage_info->geometry,"+0+0"); 11705 montage_info->border_width=0; 11706 } 11707 } 11708 break; 11709 } 11710 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11711 attribute); 11712 break; 11713 } 11714 case 'P': 11715 case 'p': 11716 { 11717 if (LocaleCompare(attribute,"pointsize") == 0) 11718 { 11719 montage_info->pointsize=SvIV(ST(i)); 11720 break; 11721 } 11722 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11723 attribute); 11724 break; 11725 } 11726 case 'S': 11727 case 's': 11728 { 11729 if (LocaleCompare(attribute,"shadow") == 0) 11730 { 11731 sp=!SvPOK(ST(i)) ? SvIV(ST(i)) : ParseCommandOption( 11732 MagickBooleanOptions,MagickFalse,SvPV(ST(i),na)); 11733 if (sp < 0) 11734 { 11735 ThrowPerlException(exception,OptionError,"UnrecognizedType", 11736 SvPV(ST(i),na)); 11737 break; 11738 } 11739 montage_info->shadow=sp != 0 ? MagickTrue : MagickFalse; 11740 break; 11741 } 11742 if (LocaleCompare(attribute,"stroke") == 0) 11743 { 11744 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11745 &montage_info->stroke,exception); 11746 break; 11747 } 11748 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11749 attribute); 11750 break; 11751 } 11752 case 'T': 11753 case 't': 11754 { 11755 if (LocaleCompare(attribute,"texture") == 0) 11756 { 11757 (void) CloneString(&montage_info->texture,SvPV(ST(i),na)); 11758 break; 11759 } 11760 if (LocaleCompare(attribute,"tile") == 0) 11761 { 11762 char *p=SvPV(ST(i),na); 11763 if (IsGeometry(p) == MagickFalse) 11764 { 11765 ThrowPerlException(exception,OptionError,"MissingGeometry", 11766 p); 11767 break; 11768 } 11769 (void) CloneString(&montage_info->tile,p); 11770 if (*p == '\0') 11771 montage_info->tile=(char *) NULL; 11772 break; 11773 } 11774 if (LocaleCompare(attribute,"title") == 0) 11775 { 11776 (void) CloneString(&montage_info->title,SvPV(ST(i),na)); 11777 break; 11778 } 11779 if (LocaleCompare(attribute,"transparent") == 0) 11780 { 11781 PixelInfo 11782 transparent_color; 11783 11784 QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 11785 &transparent_color,exception); 11786 for (next=image; next; next=next->next) 11787 (void) TransparentPaintImage(next,&transparent_color, 11788 TransparentAlpha,MagickFalse,exception); 11789 break; 11790 } 11791 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11792 attribute); 11793 break; 11794 } 11795 default: 11796 { 11797 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11798 attribute); 11799 break; 11800 } 11801 } 11802 } 11803 image=MontageImageList(info->image_info,montage_info,image,exception); 11804 montage_info=DestroyMontageInfo(montage_info); 11805 if (image == (Image *) NULL) 11806 goto PerlException; 11807 if (transparent_color.alpha != TransparentAlpha) 11808 for (next=image; next; next=next->next) 11809 (void) TransparentPaintImage(next,&transparent_color, 11810 TransparentAlpha,MagickFalse,exception); 11811 for ( ; image; image=image->next) 11812 { 11813 AddImageToRegistry(sv,image); 11814 rv=newRV(sv); 11815 av_push(av,sv_bless(rv,hv)); 11816 SvREFCNT_dec(sv); 11817 } 11818 exception=DestroyExceptionInfo(exception); 11819 ST(0)=av_reference; 11820 SvREFCNT_dec(perl_exception); 11821 XSRETURN(1); 11822 11823 PerlException: 11824 InheritPerlException(exception,perl_exception); 11825 exception=DestroyExceptionInfo(exception); 11826 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 11827 SvPOK_on(perl_exception); 11828 ST(0)=sv_2mortal(perl_exception); 11829 XSRETURN(1); 11830 } 11831 11832 # 11834 ############################################################################### 11835 # # 11836 # # 11837 # # 11838 # M o r p h # 11839 # # 11840 # # 11841 # # 11842 ############################################################################### 11843 # 11844 # 11845 void 11846 Morph(ref,...) 11847 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 11848 ALIAS: 11849 MorphImage = 1 11850 morph = 2 11851 morphimage = 3 11852 PPCODE: 11853 { 11854 AV 11855 *av; 11856 11857 char 11858 *attribute; 11859 11860 ExceptionInfo 11861 *exception; 11862 11863 HV 11864 *hv; 11865 11866 Image 11867 *image; 11868 11869 register ssize_t 11870 i; 11871 11872 ssize_t 11873 number_frames; 11874 11875 struct PackageInfo 11876 *info; 11877 11878 SV 11879 *av_reference, 11880 *perl_exception, 11881 *reference, 11882 *rv, 11883 *sv; 11884 11885 PERL_UNUSED_VAR(ref); 11886 PERL_UNUSED_VAR(ix); 11887 exception=AcquireExceptionInfo(); 11888 perl_exception=newSVpv("",0); 11889 sv=NULL; 11890 av=NULL; 11891 attribute=NULL; 11892 if (sv_isobject(ST(0)) == 0) 11893 { 11894 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 11895 PackageName); 11896 goto PerlException; 11897 } 11898 reference=SvRV(ST(0)); 11899 hv=SvSTASH(reference); 11900 av=newAV(); 11901 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 11902 SvREFCNT_dec(av); 11903 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 11904 if (image == (Image *) NULL) 11905 { 11906 ThrowPerlException(exception,OptionError,"NoImagesDefined", 11907 PackageName); 11908 goto PerlException; 11909 } 11910 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 11911 /* 11912 Get attribute. 11913 */ 11914 number_frames=30; 11915 for (i=2; i < items; i+=2) 11916 { 11917 attribute=(char *) SvPV(ST(i-1),na); 11918 switch (*attribute) 11919 { 11920 case 'F': 11921 case 'f': 11922 { 11923 if (LocaleCompare(attribute,"frames") == 0) 11924 { 11925 number_frames=SvIV(ST(i)); 11926 break; 11927 } 11928 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11929 attribute); 11930 break; 11931 } 11932 default: 11933 { 11934 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 11935 attribute); 11936 break; 11937 } 11938 } 11939 } 11940 image=MorphImages(image,number_frames,exception); 11941 if (image == (Image *) NULL) 11942 goto PerlException; 11943 for ( ; image; image=image->next) 11944 { 11945 AddImageToRegistry(sv,image); 11946 rv=newRV(sv); 11947 av_push(av,sv_bless(rv,hv)); 11948 SvREFCNT_dec(sv); 11949 } 11950 exception=DestroyExceptionInfo(exception); 11951 ST(0)=av_reference; 11952 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 11953 XSRETURN(1); 11954 11955 PerlException: 11956 InheritPerlException(exception,perl_exception); 11957 exception=DestroyExceptionInfo(exception); 11958 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 11959 SvPOK_on(perl_exception); 11960 ST(0)=sv_2mortal(perl_exception); 11961 XSRETURN(1); 11962 } 11963 11964 # 11966 ############################################################################### 11967 # # 11968 # # 11969 # # 11970 # M o s a i c # 11971 # # 11972 # # 11973 # # 11974 ############################################################################### 11975 # 11976 # 11977 void 11978 Mosaic(ref) 11979 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 11980 ALIAS: 11981 MosaicImage = 1 11982 mosaic = 2 11983 mosaicimage = 3 11984 PPCODE: 11985 { 11986 AV 11987 *av; 11988 11989 ExceptionInfo 11990 *exception; 11991 11992 HV 11993 *hv; 11994 11995 Image 11996 *image; 11997 11998 struct PackageInfo 11999 *info; 12000 12001 SV 12002 *perl_exception, 12003 *reference, 12004 *rv, 12005 *sv; 12006 12007 PERL_UNUSED_VAR(ref); 12008 PERL_UNUSED_VAR(ix); 12009 exception=AcquireExceptionInfo(); 12010 perl_exception=newSVpv("",0); 12011 sv=NULL; 12012 if (sv_isobject(ST(0)) == 0) 12013 { 12014 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 12015 PackageName); 12016 goto PerlException; 12017 } 12018 reference=SvRV(ST(0)); 12019 hv=SvSTASH(reference); 12020 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 12021 if (image == (Image *) NULL) 12022 { 12023 ThrowPerlException(exception,OptionError,"NoImagesDefined", 12024 PackageName); 12025 goto PerlException; 12026 } 12027 image=MergeImageLayers(image,MosaicLayer,exception); 12028 /* 12029 Create blessed Perl array for the returned image. 12030 */ 12031 av=newAV(); 12032 ST(0)=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 12033 SvREFCNT_dec(av); 12034 AddImageToRegistry(sv,image); 12035 rv=newRV(sv); 12036 av_push(av,sv_bless(rv,hv)); 12037 SvREFCNT_dec(sv); 12038 (void) CopyMagickString(info->image_info->filename,image->filename, 12039 MagickPathExtent); 12040 SetImageInfo(info->image_info,0,exception); 12041 exception=DestroyExceptionInfo(exception); 12042 SvREFCNT_dec(perl_exception); 12043 XSRETURN(1); 12044 12045 PerlException: 12046 InheritPerlException(exception,perl_exception); 12047 exception=DestroyExceptionInfo(exception); 12048 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 12049 SvPOK_on(perl_exception); /* return messages in string context */ 12050 ST(0)=sv_2mortal(perl_exception); 12051 XSRETURN(1); 12052 } 12053 12054 # 12056 ############################################################################### 12057 # # 12058 # # 12059 # # 12060 # P i n g # 12061 # # 12062 # # 12063 # # 12064 ############################################################################### 12065 # 12066 # 12067 void 12068 Ping(ref,...) 12069 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12070 ALIAS: 12071 PingImage = 1 12072 ping = 2 12073 pingimage = 3 12074 PPCODE: 12075 { 12076 AV 12077 *av; 12078 12079 char 12080 **keep, 12081 **list; 12082 12083 ExceptionInfo 12084 *exception; 12085 12086 Image 12087 *image, 12088 *next; 12089 12090 int 12091 n; 12092 12093 MagickBooleanType 12094 status; 12095 12096 register char 12097 **p; 12098 12099 register ssize_t 12100 i; 12101 12102 ssize_t 12103 ac; 12104 12105 STRLEN 12106 *length; 12107 12108 struct PackageInfo 12109 *info, 12110 *package_info; 12111 12112 SV 12113 *perl_exception, 12114 *reference; 12115 12116 size_t 12117 count; 12118 12119 PERL_UNUSED_VAR(ref); 12120 PERL_UNUSED_VAR(ix); 12121 exception=AcquireExceptionInfo(); 12122 perl_exception=newSVpv("",0); 12123 package_info=(struct PackageInfo *) NULL; 12124 ac=(items < 2) ? 1 : items-1; 12125 list=(char **) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*list)); 12126 keep=list; 12127 length=(STRLEN *) NULL; 12128 if (list == (char **) NULL) 12129 { 12130 ThrowPerlException(exception,ResourceLimitError, 12131 "MemoryAllocationFailed",PackageName); 12132 goto PerlException; 12133 } 12134 keep=list; 12135 length=(STRLEN *) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*length)); 12136 if (length == (STRLEN *) NULL) 12137 { 12138 ThrowPerlException(exception,ResourceLimitError, 12139 "MemoryAllocationFailed",PackageName); 12140 goto PerlException; 12141 } 12142 if (sv_isobject(ST(0)) == 0) 12143 { 12144 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 12145 PackageName); 12146 goto PerlException; 12147 } 12148 reference=SvRV(ST(0)); 12149 if (SvTYPE(reference) != SVt_PVAV) 12150 { 12151 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 12152 PackageName); 12153 goto PerlException; 12154 } 12155 av=(AV *) reference; 12156 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 12157 exception); 12158 package_info=ClonePackageInfo(info,exception); 12159 n=1; 12160 if (items <= 1) 12161 *list=(char *) (*package_info->image_info->filename ? 12162 package_info->image_info->filename : "XC:black"); 12163 else 12164 for (n=0, i=0; i < ac; i++) 12165 { 12166 list[n]=(char *) SvPV(ST(i+1),length[n]); 12167 if ((items >= 3) && strEQcase(list[n],"blob")) 12168 { 12169 void 12170 *blob; 12171 12172 i++; 12173 blob=(void *) (SvPV(ST(i+1),length[n])); 12174 SetImageInfoBlob(package_info->image_info,blob,(size_t) length[n]); 12175 } 12176 if ((items >= 3) && strEQcase(list[n],"filename")) 12177 continue; 12178 if ((items >= 3) && strEQcase(list[n],"file")) 12179 { 12180 FILE 12181 *file; 12182 12183 PerlIO 12184 *io_info; 12185 12186 i++; 12187 io_info=IoIFP(sv_2io(ST(i+1))); 12188 if (io_info == (PerlIO *) NULL) 12189 { 12190 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 12191 PackageName); 12192 continue; 12193 } 12194 file=PerlIO_findFILE(io_info); 12195 if (file == (FILE *) NULL) 12196 { 12197 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 12198 PackageName); 12199 continue; 12200 } 12201 SetImageInfoFile(package_info->image_info,file); 12202 } 12203 if ((items >= 3) && strEQcase(list[n],"magick")) 12204 continue; 12205 n++; 12206 } 12207 list[n]=(char *) NULL; 12208 keep=list; 12209 status=ExpandFilenames(&n,&list); 12210 if (status == MagickFalse) 12211 { 12212 ThrowPerlException(exception,ResourceLimitError, 12213 "MemoryAllocationFailed",PackageName); 12214 goto PerlException; 12215 } 12216 count=0; 12217 for (i=0; i < n; i++) 12218 { 12219 (void) CopyMagickString(package_info->image_info->filename,list[i], 12220 MagickPathExtent); 12221 image=PingImage(package_info->image_info,exception); 12222 if (image == (Image *) NULL) 12223 break; 12224 if ((package_info->image_info->file != (FILE *) NULL) || 12225 (package_info->image_info->blob != (void *) NULL)) 12226 DisassociateImageStream(image); 12227 count+=GetImageListLength(image); 12228 EXTEND(sp,4*count); 12229 for (next=image; next; next=next->next) 12230 { 12231 PUSHs(sv_2mortal(newSViv(next->columns))); 12232 PUSHs(sv_2mortal(newSViv(next->rows))); 12233 PUSHs(sv_2mortal(newSViv((size_t) GetBlobSize(next)))); 12234 PUSHs(sv_2mortal(newSVpv(next->magick,0))); 12235 } 12236 image=DestroyImageList(image); 12237 } 12238 /* 12239 Free resources. 12240 */ 12241 for (i=0; i < n; i++) 12242 if (list[i] != (char *) NULL) 12243 for (p=keep; list[i] != *p++; ) 12244 if (*p == NULL) 12245 { 12246 list[i]=(char *) RelinquishMagickMemory(list[i]); 12247 break; 12248 } 12249 12250 PerlException: 12251 if (package_info != (struct PackageInfo *) NULL) 12252 DestroyPackageInfo(package_info); 12253 if (list && (list != keep)) 12254 list=(char **) RelinquishMagickMemory(list); 12255 if (keep) 12256 keep=(char **) RelinquishMagickMemory(keep); 12257 if (length) 12258 length=(STRLEN *) RelinquishMagickMemory(length); 12259 InheritPerlException(exception,perl_exception); 12260 exception=DestroyExceptionInfo(exception); 12261 SvREFCNT_dec(perl_exception); /* throw away all errors */ 12262 } 12263 12264 # 12266 ############################################################################### 12267 # # 12268 # # 12269 # # 12270 # P r e v i e w # 12271 # # 12272 # # 12273 # # 12274 ############################################################################### 12275 # 12276 # 12277 void 12278 Preview(ref,...) 12279 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12280 ALIAS: 12281 PreviewImage = 1 12282 preview = 2 12283 previewimage = 3 12284 PPCODE: 12285 { 12286 AV 12287 *av; 12288 12289 ExceptionInfo 12290 *exception; 12291 12292 HV 12293 *hv; 12294 12295 Image 12296 *image, 12297 *preview_image; 12298 12299 PreviewType 12300 preview_type; 12301 12302 struct PackageInfo 12303 *info; 12304 12305 SV 12306 *av_reference, 12307 *perl_exception, 12308 *reference, 12309 *rv, 12310 *sv; 12311 12312 PERL_UNUSED_VAR(ref); 12313 PERL_UNUSED_VAR(ix); 12314 exception=AcquireExceptionInfo(); 12315 perl_exception=newSVpv("",0); 12316 sv=NULL; 12317 av=NULL; 12318 if (sv_isobject(ST(0)) == 0) 12319 { 12320 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 12321 PackageName); 12322 goto PerlException; 12323 } 12324 reference=SvRV(ST(0)); 12325 hv=SvSTASH(reference); 12326 av=newAV(); 12327 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 12328 SvREFCNT_dec(av); 12329 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 12330 if (image == (Image *) NULL) 12331 { 12332 ThrowPerlException(exception,OptionError,"NoImagesDefined", 12333 PackageName); 12334 goto PerlException; 12335 } 12336 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 12337 preview_type=GammaPreview; 12338 if (items > 1) 12339 preview_type=(PreviewType) 12340 ParseCommandOption(MagickPreviewOptions,MagickFalse,SvPV(ST(1),na)); 12341 for ( ; image; image=image->next) 12342 { 12343 preview_image=PreviewImage(image,preview_type,exception); 12344 if (preview_image == (Image *) NULL) 12345 goto PerlException; 12346 AddImageToRegistry(sv,preview_image); 12347 rv=newRV(sv); 12348 av_push(av,sv_bless(rv,hv)); 12349 SvREFCNT_dec(sv); 12350 } 12351 exception=DestroyExceptionInfo(exception); 12352 ST(0)=av_reference; 12353 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 12354 XSRETURN(1); 12355 12356 PerlException: 12357 InheritPerlException(exception,perl_exception); 12358 exception=DestroyExceptionInfo(exception); 12359 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 12360 SvPOK_on(perl_exception); 12361 ST(0)=sv_2mortal(perl_exception); 12362 XSRETURN(1); 12363 } 12364 12365 # 12367 ############################################################################### 12368 # # 12369 # # 12370 # # 12371 # Q u e r y C o l o r # 12372 # # 12373 # # 12374 # # 12375 ############################################################################### 12376 # 12377 # 12378 void 12379 QueryColor(ref,...) 12380 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12381 ALIAS: 12382 querycolor = 1 12383 PPCODE: 12384 { 12385 char 12386 *name; 12387 12388 ExceptionInfo 12389 *exception; 12390 12391 PixelInfo 12392 color; 12393 12394 register ssize_t 12395 i; 12396 12397 SV 12398 *perl_exception; 12399 12400 PERL_UNUSED_VAR(ref); 12401 PERL_UNUSED_VAR(ix); 12402 exception=AcquireExceptionInfo(); 12403 perl_exception=newSVpv("",0); 12404 if (items == 1) 12405 { 12406 const ColorInfo 12407 **colorlist; 12408 12409 size_t 12410 colors; 12411 12412 colorlist=GetColorInfoList("*",&colors,exception); 12413 EXTEND(sp,colors); 12414 for (i=0; i < (ssize_t) colors; i++) 12415 { 12416 PUSHs(sv_2mortal(newSVpv(colorlist[i]->name,0))); 12417 } 12418 colorlist=(const ColorInfo **) 12419 RelinquishMagickMemory((ColorInfo **) colorlist); 12420 goto PerlException; 12421 } 12422 EXTEND(sp,5*items); 12423 for (i=1; i < items; i++) 12424 { 12425 name=(char *) SvPV(ST(i),na); 12426 if (QueryColorCompliance(name,AllCompliance,&color,exception) == MagickFalse) 12427 { 12428 PUSHs(&sv_undef); 12429 continue; 12430 } 12431 PUSHs(sv_2mortal(newSViv((size_t) floor(color.red+0.5)))); 12432 PUSHs(sv_2mortal(newSViv((size_t) floor(color.green+0.5)))); 12433 PUSHs(sv_2mortal(newSViv((size_t) floor(color.blue+0.5)))); 12434 if (color.colorspace == CMYKColorspace) 12435 PUSHs(sv_2mortal(newSViv((size_t) floor(color.black+0.5)))); 12436 if (color.alpha_trait != UndefinedPixelTrait) 12437 PUSHs(sv_2mortal(newSViv((size_t) floor(color.alpha+0.5)))); 12438 } 12439 12440 PerlException: 12441 InheritPerlException(exception,perl_exception); 12442 exception=DestroyExceptionInfo(exception); 12443 SvREFCNT_dec(perl_exception); 12444 } 12445 12446 # 12448 ############################################################################### 12449 # # 12450 # # 12451 # # 12452 # Q u e r y C o l o r N a m e # 12453 # # 12454 # # 12455 # # 12456 ############################################################################### 12457 # 12458 # 12459 void 12460 QueryColorname(ref,...) 12461 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12462 ALIAS: 12463 querycolorname = 1 12464 PPCODE: 12465 { 12466 AV 12467 *av; 12468 12469 char 12470 message[MagickPathExtent]; 12471 12472 ExceptionInfo 12473 *exception; 12474 12475 Image 12476 *image; 12477 12478 PixelInfo 12479 target_color; 12480 12481 register ssize_t 12482 i; 12483 12484 struct PackageInfo 12485 *info; 12486 12487 SV 12488 *perl_exception, 12489 *reference; /* reference is the SV* of ref=SvIV(reference) */ 12490 12491 PERL_UNUSED_VAR(ref); 12492 PERL_UNUSED_VAR(ix); 12493 exception=AcquireExceptionInfo(); 12494 perl_exception=newSVpv("",0); 12495 reference=SvRV(ST(0)); 12496 av=(AV *) reference; 12497 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 12498 exception); 12499 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 12500 if (image == (Image *) NULL) 12501 { 12502 ThrowPerlException(exception,OptionError,"NoImagesDefined", 12503 PackageName); 12504 goto PerlException; 12505 } 12506 EXTEND(sp,items); 12507 for (i=1; i < items; i++) 12508 { 12509 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance,&target_color, 12510 exception); 12511 (void) QueryColorname(image,&target_color,SVGCompliance,message, 12512 exception); 12513 PUSHs(sv_2mortal(newSVpv(message,0))); 12514 } 12515 12516 PerlException: 12517 InheritPerlException(exception,perl_exception); 12518 exception=DestroyExceptionInfo(exception); 12519 SvREFCNT_dec(perl_exception); 12520 } 12521 12522 # 12524 ############################################################################### 12525 # # 12526 # # 12527 # # 12528 # Q u e r y F o n t # 12529 # # 12530 # # 12531 # # 12532 ############################################################################### 12533 # 12534 # 12535 void 12536 QueryFont(ref,...) 12537 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12538 ALIAS: 12539 queryfont = 1 12540 PPCODE: 12541 { 12542 char 12543 *name, 12544 message[MagickPathExtent]; 12545 12546 ExceptionInfo 12547 *exception; 12548 12549 register ssize_t 12550 i; 12551 12552 SV 12553 *perl_exception; 12554 12555 volatile const TypeInfo 12556 *type_info; 12557 12558 PERL_UNUSED_VAR(ref); 12559 PERL_UNUSED_VAR(ix); 12560 exception=AcquireExceptionInfo(); 12561 perl_exception=newSVpv("",0); 12562 if (items == 1) 12563 { 12564 const TypeInfo 12565 **typelist; 12566 12567 size_t 12568 types; 12569 12570 typelist=GetTypeInfoList("*",&types,exception); 12571 EXTEND(sp,types); 12572 for (i=0; i < (ssize_t) types; i++) 12573 { 12574 PUSHs(sv_2mortal(newSVpv(typelist[i]->name,0))); 12575 } 12576 typelist=(const TypeInfo **) RelinquishMagickMemory((TypeInfo **) 12577 typelist); 12578 goto PerlException; 12579 } 12580 EXTEND(sp,10*items); 12581 for (i=1; i < items; i++) 12582 { 12583 name=(char *) SvPV(ST(i),na); 12584 type_info=GetTypeInfo(name,exception); 12585 if (type_info == (TypeInfo *) NULL) 12586 { 12587 PUSHs(&sv_undef); 12588 continue; 12589 } 12590 if (type_info->name == (char *) NULL) 12591 PUSHs(&sv_undef); 12592 else 12593 PUSHs(sv_2mortal(newSVpv(type_info->name,0))); 12594 if (type_info->description == (char *) NULL) 12595 PUSHs(&sv_undef); 12596 else 12597 PUSHs(sv_2mortal(newSVpv(type_info->description,0))); 12598 if (type_info->family == (char *) NULL) 12599 PUSHs(&sv_undef); 12600 else 12601 PUSHs(sv_2mortal(newSVpv(type_info->family,0))); 12602 if (type_info->style == UndefinedStyle) 12603 PUSHs(&sv_undef); 12604 else 12605 PUSHs(sv_2mortal(newSVpv(CommandOptionToMnemonic(MagickStyleOptions, 12606 type_info->style),0))); 12607 if (type_info->stretch == UndefinedStretch) 12608 PUSHs(&sv_undef); 12609 else 12610 PUSHs(sv_2mortal(newSVpv(CommandOptionToMnemonic(MagickStretchOptions, 12611 type_info->stretch),0))); 12612 (void) FormatLocaleString(message,MagickPathExtent,"%.20g",(double) 12613 type_info->weight); 12614 PUSHs(sv_2mortal(newSVpv(message,0))); 12615 if (type_info->encoding == (char *) NULL) 12616 PUSHs(&sv_undef); 12617 else 12618 PUSHs(sv_2mortal(newSVpv(type_info->encoding,0))); 12619 if (type_info->foundry == (char *) NULL) 12620 PUSHs(&sv_undef); 12621 else 12622 PUSHs(sv_2mortal(newSVpv(type_info->foundry,0))); 12623 if (type_info->format == (char *) NULL) 12624 PUSHs(&sv_undef); 12625 else 12626 PUSHs(sv_2mortal(newSVpv(type_info->format,0))); 12627 if (type_info->metrics == (char *) NULL) 12628 PUSHs(&sv_undef); 12629 else 12630 PUSHs(sv_2mortal(newSVpv(type_info->metrics,0))); 12631 if (type_info->glyphs == (char *) NULL) 12632 PUSHs(&sv_undef); 12633 else 12634 PUSHs(sv_2mortal(newSVpv(type_info->glyphs,0))); 12635 } 12636 12637 PerlException: 12638 InheritPerlException(exception,perl_exception); 12639 exception=DestroyExceptionInfo(exception); 12640 SvREFCNT_dec(perl_exception); 12641 } 12642 12643 # 12645 ############################################################################### 12646 # # 12647 # # 12648 # # 12649 # Q u e r y F o n t M e t r i c s # 12650 # # 12651 # # 12652 # # 12653 ############################################################################### 12654 # 12655 # 12656 void 12657 QueryFontMetrics(ref,...) 12658 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 12659 ALIAS: 12660 queryfontmetrics = 1 12661 PPCODE: 12662 { 12663 AffineMatrix 12664 affine, 12665 current; 12666 12667 AV 12668 *av; 12669 12670 char 12671 *attribute; 12672 12673 double 12674 x, 12675 y; 12676 12677 DrawInfo 12678 *draw_info; 12679 12680 ExceptionInfo 12681 *exception; 12682 12683 GeometryInfo 12684 geometry_info; 12685 12686 Image 12687 *image; 12688 12689 MagickBooleanType 12690 status; 12691 12692 MagickStatusType 12693 flags; 12694 12695 register ssize_t 12696 i; 12697 12698 ssize_t 12699 type; 12700 12701 struct PackageInfo 12702 *info, 12703 *package_info; 12704 12705 SV 12706 *perl_exception, 12707 *reference; /* reference is the SV* of ref=SvIV(reference) */ 12708 12709 TypeMetric 12710 metrics; 12711 12712 PERL_UNUSED_VAR(ref); 12713 PERL_UNUSED_VAR(ix); 12714 exception=AcquireExceptionInfo(); 12715 package_info=(struct PackageInfo *) NULL; 12716 perl_exception=newSVpv("",0); 12717 reference=SvRV(ST(0)); 12718 av=(AV *) reference; 12719 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 12720 exception); 12721 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 12722 if (image == (Image *) NULL) 12723 { 12724 ThrowPerlException(exception,OptionError,"NoImagesDefined", 12725 PackageName); 12726 goto PerlException; 12727 } 12728 package_info=ClonePackageInfo(info,exception); 12729 draw_info=CloneDrawInfo(package_info->image_info,(DrawInfo *) NULL); 12730 CloneString(&draw_info->text,""); 12731 current=draw_info->affine; 12732 GetAffineMatrix(&affine); 12733 x=0.0; 12734 y=0.0; 12735 EXTEND(sp,7*items); 12736 for (i=2; i < items; i+=2) 12737 { 12738 attribute=(char *) SvPV(ST(i-1),na); 12739 switch (*attribute) 12740 { 12741 case 'A': 12742 case 'a': 12743 { 12744 if (LocaleCompare(attribute,"antialias") == 0) 12745 { 12746 type=ParseCommandOption(MagickBooleanOptions,MagickFalse, 12747 SvPV(ST(i),na)); 12748 if (type < 0) 12749 { 12750 ThrowPerlException(exception,OptionError,"UnrecognizedType", 12751 SvPV(ST(i),na)); 12752 break; 12753 } 12754 draw_info->text_antialias=type != 0 ? MagickTrue : MagickFalse; 12755 break; 12756 } 12757 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12758 attribute); 12759 break; 12760 } 12761 case 'd': 12762 case 'D': 12763 { 12764 if (LocaleCompare(attribute,"density") == 0) 12765 { 12766 CloneString(&draw_info->density,SvPV(ST(i),na)); 12767 break; 12768 } 12769 if (LocaleCompare(attribute,"direction") == 0) 12770 { 12771 draw_info->direction=(DirectionType) ParseCommandOption( 12772 MagickDirectionOptions,MagickFalse,SvPV(ST(i),na)); 12773 break; 12774 } 12775 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12776 attribute); 12777 break; 12778 } 12779 case 'e': 12780 case 'E': 12781 { 12782 if (LocaleCompare(attribute,"encoding") == 0) 12783 { 12784 CloneString(&draw_info->encoding,SvPV(ST(i),na)); 12785 break; 12786 } 12787 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12788 attribute); 12789 break; 12790 } 12791 case 'f': 12792 case 'F': 12793 { 12794 if (LocaleCompare(attribute,"family") == 0) 12795 { 12796 CloneString(&draw_info->family,SvPV(ST(i),na)); 12797 break; 12798 } 12799 if (LocaleCompare(attribute,"fill") == 0) 12800 { 12801 if (info) 12802 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 12803 &draw_info->fill,exception); 12804 break; 12805 } 12806 if (LocaleCompare(attribute,"font") == 0) 12807 { 12808 CloneString(&draw_info->font,SvPV(ST(i),na)); 12809 break; 12810 } 12811 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12812 attribute); 12813 break; 12814 } 12815 case 'g': 12816 case 'G': 12817 { 12818 if (LocaleCompare(attribute,"geometry") == 0) 12819 { 12820 CloneString(&draw_info->geometry,SvPV(ST(i),na)); 12821 break; 12822 } 12823 if (LocaleCompare(attribute,"gravity") == 0) 12824 { 12825 draw_info->gravity=(GravityType) ParseCommandOption( 12826 MagickGravityOptions,MagickFalse,SvPV(ST(i),na)); 12827 break; 12828 } 12829 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12830 attribute); 12831 break; 12832 } 12833 case 'i': 12834 case 'I': 12835 { 12836 if (LocaleCompare(attribute,"interline-spacing") == 0) 12837 { 12838 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12839 draw_info->interline_spacing=geometry_info.rho; 12840 break; 12841 } 12842 if (LocaleCompare(attribute,"interword-spacing") == 0) 12843 { 12844 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12845 draw_info->interword_spacing=geometry_info.rho; 12846 break; 12847 } 12848 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12849 attribute); 12850 break; 12851 } 12852 case 'k': 12853 case 'K': 12854 { 12855 if (LocaleCompare(attribute,"kerning") == 0) 12856 { 12857 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12858 draw_info->kerning=geometry_info.rho; 12859 break; 12860 } 12861 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12862 attribute); 12863 break; 12864 } 12865 case 'p': 12866 case 'P': 12867 { 12868 if (LocaleCompare(attribute,"pointsize") == 0) 12869 { 12870 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12871 draw_info->pointsize=geometry_info.rho; 12872 break; 12873 } 12874 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12875 attribute); 12876 break; 12877 } 12878 case 'r': 12879 case 'R': 12880 { 12881 if (LocaleCompare(attribute,"rotate") == 0) 12882 { 12883 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12884 affine.rx=geometry_info.rho; 12885 affine.ry=geometry_info.sigma; 12886 if ((flags & SigmaValue) == 0) 12887 affine.ry=affine.rx; 12888 break; 12889 } 12890 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12891 attribute); 12892 break; 12893 } 12894 case 's': 12895 case 'S': 12896 { 12897 if (LocaleCompare(attribute,"scale") == 0) 12898 { 12899 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12900 affine.sx=geometry_info.rho; 12901 affine.sy=geometry_info.sigma; 12902 if ((flags & SigmaValue) == 0) 12903 affine.sy=affine.sx; 12904 break; 12905 } 12906 if (LocaleCompare(attribute,"skew") == 0) 12907 { 12908 double 12909 x_angle, 12910 y_angle; 12911 12912 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12913 x_angle=geometry_info.rho; 12914 y_angle=geometry_info.sigma; 12915 if ((flags & SigmaValue) == 0) 12916 y_angle=x_angle; 12917 affine.ry=tan(DegreesToRadians(fmod(x_angle,360.0))); 12918 affine.rx=tan(DegreesToRadians(fmod(y_angle,360.0))); 12919 break; 12920 } 12921 if (LocaleCompare(attribute,"stroke") == 0) 12922 { 12923 if (info) 12924 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 12925 &draw_info->stroke,exception); 12926 break; 12927 } 12928 if (LocaleCompare(attribute,"style") == 0) 12929 { 12930 type=ParseCommandOption(MagickStyleOptions,MagickFalse, 12931 SvPV(ST(i),na)); 12932 if (type < 0) 12933 { 12934 ThrowPerlException(exception,OptionError,"UnrecognizedType", 12935 SvPV(ST(i),na)); 12936 break; 12937 } 12938 draw_info->style=(StyleType) type; 12939 break; 12940 } 12941 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12942 attribute); 12943 break; 12944 } 12945 case 't': 12946 case 'T': 12947 { 12948 if (LocaleCompare(attribute,"text") == 0) 12949 { 12950 CloneString(&draw_info->text,SvPV(ST(i),na)); 12951 break; 12952 } 12953 if (LocaleCompare(attribute,"translate") == 0) 12954 { 12955 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12956 affine.tx=geometry_info.rho; 12957 affine.ty=geometry_info.sigma; 12958 if ((flags & SigmaValue) == 0) 12959 affine.ty=affine.tx; 12960 break; 12961 } 12962 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12963 attribute); 12964 break; 12965 } 12966 case 'w': 12967 case 'W': 12968 { 12969 if (LocaleCompare(attribute,"weight") == 0) 12970 { 12971 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12972 draw_info->weight=(size_t) geometry_info.rho; 12973 break; 12974 } 12975 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12976 attribute); 12977 break; 12978 } 12979 case 'x': 12980 case 'X': 12981 { 12982 if (LocaleCompare(attribute,"x") == 0) 12983 { 12984 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12985 x=geometry_info.rho; 12986 break; 12987 } 12988 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 12989 attribute); 12990 break; 12991 } 12992 case 'y': 12993 case 'Y': 12994 { 12995 if (LocaleCompare(attribute,"y") == 0) 12996 { 12997 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 12998 y=geometry_info.rho; 12999 break; 13000 } 13001 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13002 attribute); 13003 break; 13004 } 13005 default: 13006 { 13007 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13008 attribute); 13009 break; 13010 } 13011 } 13012 } 13013 draw_info->affine.sx=current.sx*affine.sx+current.ry*affine.rx; 13014 draw_info->affine.rx=current.rx*affine.sx+current.sy*affine.rx; 13015 draw_info->affine.ry=current.sx*affine.ry+current.ry*affine.sy; 13016 draw_info->affine.sy=current.rx*affine.ry+current.sy*affine.sy; 13017 draw_info->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; 13018 draw_info->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; 13019 if (draw_info->geometry == (char *) NULL) 13020 { 13021 draw_info->geometry=AcquireString((char *) NULL); 13022 (void) FormatLocaleString(draw_info->geometry,MagickPathExtent, 13023 "%.15g,%.15g",x,y); 13024 } 13025 status=GetTypeMetrics(image,draw_info,&metrics,exception); 13026 (void) CatchImageException(image); 13027 if (status == MagickFalse) 13028 PUSHs(&sv_undef); 13029 else 13030 { 13031 PUSHs(sv_2mortal(newSVnv(metrics.pixels_per_em.x))); 13032 PUSHs(sv_2mortal(newSVnv(metrics.pixels_per_em.y))); 13033 PUSHs(sv_2mortal(newSVnv(metrics.ascent))); 13034 PUSHs(sv_2mortal(newSVnv(metrics.descent))); 13035 PUSHs(sv_2mortal(newSVnv(metrics.width))); 13036 PUSHs(sv_2mortal(newSVnv(metrics.height))); 13037 PUSHs(sv_2mortal(newSVnv(metrics.max_advance))); 13038 PUSHs(sv_2mortal(newSVnv(metrics.bounds.x1))); 13039 PUSHs(sv_2mortal(newSVnv(metrics.bounds.y1))); 13040 PUSHs(sv_2mortal(newSVnv(metrics.bounds.x2))); 13041 PUSHs(sv_2mortal(newSVnv(metrics.bounds.y2))); 13042 PUSHs(sv_2mortal(newSVnv(metrics.origin.x))); 13043 PUSHs(sv_2mortal(newSVnv(metrics.origin.y))); 13044 } 13045 draw_info=DestroyDrawInfo(draw_info); 13046 13047 PerlException: 13048 if (package_info != (struct PackageInfo *) NULL) 13049 DestroyPackageInfo(package_info); 13050 InheritPerlException(exception,perl_exception); 13051 exception=DestroyExceptionInfo(exception); 13052 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 13053 } 13054 13055 # 13057 ############################################################################### 13058 # # 13059 # # 13060 # # 13061 # Q u e r y M u l t i l i n e F o n t M e t r i c s # 13062 # # 13063 # # 13064 # # 13065 ############################################################################### 13066 # 13067 # 13068 void 13069 QueryMultilineFontMetrics(ref,...) 13070 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13071 ALIAS: 13072 querymultilinefontmetrics = 1 13073 PPCODE: 13074 { 13075 AffineMatrix 13076 affine, 13077 current; 13078 13079 AV 13080 *av; 13081 13082 char 13083 *attribute; 13084 13085 double 13086 x, 13087 y; 13088 13089 DrawInfo 13090 *draw_info; 13091 13092 ExceptionInfo 13093 *exception; 13094 13095 GeometryInfo 13096 geometry_info; 13097 13098 Image 13099 *image; 13100 13101 MagickBooleanType 13102 status; 13103 13104 MagickStatusType 13105 flags; 13106 13107 register ssize_t 13108 i; 13109 13110 ssize_t 13111 type; 13112 13113 struct PackageInfo 13114 *info, 13115 *package_info; 13116 13117 SV 13118 *perl_exception, 13119 *reference; /* reference is the SV* of ref=SvIV(reference) */ 13120 13121 TypeMetric 13122 metrics; 13123 13124 PERL_UNUSED_VAR(ref); 13125 PERL_UNUSED_VAR(ix); 13126 exception=AcquireExceptionInfo(); 13127 package_info=(struct PackageInfo *) NULL; 13128 perl_exception=newSVpv("",0); 13129 reference=SvRV(ST(0)); 13130 av=(AV *) reference; 13131 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 13132 exception); 13133 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 13134 if (image == (Image *) NULL) 13135 { 13136 ThrowPerlException(exception,OptionError,"NoImagesDefined", 13137 PackageName); 13138 goto PerlException; 13139 } 13140 package_info=ClonePackageInfo(info,exception); 13141 draw_info=CloneDrawInfo(package_info->image_info,(DrawInfo *) NULL); 13142 CloneString(&draw_info->text,""); 13143 current=draw_info->affine; 13144 GetAffineMatrix(&affine); 13145 x=0.0; 13146 y=0.0; 13147 EXTEND(sp,7*items); 13148 for (i=2; i < items; i+=2) 13149 { 13150 attribute=(char *) SvPV(ST(i-1),na); 13151 switch (*attribute) 13152 { 13153 case 'A': 13154 case 'a': 13155 { 13156 if (LocaleCompare(attribute,"antialias") == 0) 13157 { 13158 type=ParseCommandOption(MagickBooleanOptions,MagickFalse, 13159 SvPV(ST(i),na)); 13160 if (type < 0) 13161 { 13162 ThrowPerlException(exception,OptionError,"UnrecognizedType", 13163 SvPV(ST(i),na)); 13164 break; 13165 } 13166 draw_info->text_antialias=type != 0 ? MagickTrue : MagickFalse; 13167 break; 13168 } 13169 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13170 attribute); 13171 break; 13172 } 13173 case 'd': 13174 case 'D': 13175 { 13176 if (LocaleCompare(attribute,"density") == 0) 13177 { 13178 CloneString(&draw_info->density,SvPV(ST(i),na)); 13179 break; 13180 } 13181 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13182 attribute); 13183 break; 13184 } 13185 case 'e': 13186 case 'E': 13187 { 13188 if (LocaleCompare(attribute,"encoding") == 0) 13189 { 13190 CloneString(&draw_info->encoding,SvPV(ST(i),na)); 13191 break; 13192 } 13193 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13194 attribute); 13195 break; 13196 } 13197 case 'f': 13198 case 'F': 13199 { 13200 if (LocaleCompare(attribute,"family") == 0) 13201 { 13202 CloneString(&draw_info->family,SvPV(ST(i),na)); 13203 break; 13204 } 13205 if (LocaleCompare(attribute,"fill") == 0) 13206 { 13207 if (info) 13208 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 13209 &draw_info->fill,exception); 13210 break; 13211 } 13212 if (LocaleCompare(attribute,"font") == 0) 13213 { 13214 CloneString(&draw_info->font,SvPV(ST(i),na)); 13215 break; 13216 } 13217 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13218 attribute); 13219 break; 13220 } 13221 case 'g': 13222 case 'G': 13223 { 13224 if (LocaleCompare(attribute,"geometry") == 0) 13225 { 13226 CloneString(&draw_info->geometry,SvPV(ST(i),na)); 13227 break; 13228 } 13229 if (LocaleCompare(attribute,"gravity") == 0) 13230 { 13231 draw_info->gravity=(GravityType) ParseCommandOption( 13232 MagickGravityOptions,MagickFalse,SvPV(ST(i),na)); 13233 break; 13234 } 13235 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13236 attribute); 13237 break; 13238 } 13239 case 'p': 13240 case 'P': 13241 { 13242 if (LocaleCompare(attribute,"pointsize") == 0) 13243 { 13244 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13245 draw_info->pointsize=geometry_info.rho; 13246 break; 13247 } 13248 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13249 attribute); 13250 break; 13251 } 13252 case 'r': 13253 case 'R': 13254 { 13255 if (LocaleCompare(attribute,"rotate") == 0) 13256 { 13257 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13258 affine.rx=geometry_info.rho; 13259 affine.ry=geometry_info.sigma; 13260 if ((flags & SigmaValue) == 0) 13261 affine.ry=affine.rx; 13262 break; 13263 } 13264 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13265 attribute); 13266 break; 13267 } 13268 case 's': 13269 case 'S': 13270 { 13271 if (LocaleCompare(attribute,"scale") == 0) 13272 { 13273 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13274 affine.sx=geometry_info.rho; 13275 affine.sy=geometry_info.sigma; 13276 if ((flags & SigmaValue) == 0) 13277 affine.sy=affine.sx; 13278 break; 13279 } 13280 if (LocaleCompare(attribute,"skew") == 0) 13281 { 13282 double 13283 x_angle, 13284 y_angle; 13285 13286 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13287 x_angle=geometry_info.rho; 13288 y_angle=geometry_info.sigma; 13289 if ((flags & SigmaValue) == 0) 13290 y_angle=x_angle; 13291 affine.ry=tan(DegreesToRadians(fmod(x_angle,360.0))); 13292 affine.rx=tan(DegreesToRadians(fmod(y_angle,360.0))); 13293 break; 13294 } 13295 if (LocaleCompare(attribute,"stroke") == 0) 13296 { 13297 if (info) 13298 (void) QueryColorCompliance(SvPV(ST(i),na),AllCompliance, 13299 &draw_info->stroke,exception); 13300 break; 13301 } 13302 if (LocaleCompare(attribute,"style") == 0) 13303 { 13304 type=ParseCommandOption(MagickStyleOptions,MagickFalse, 13305 SvPV(ST(i),na)); 13306 if (type < 0) 13307 { 13308 ThrowPerlException(exception,OptionError,"UnrecognizedType", 13309 SvPV(ST(i),na)); 13310 break; 13311 } 13312 draw_info->style=(StyleType) type; 13313 break; 13314 } 13315 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13316 attribute); 13317 break; 13318 } 13319 case 't': 13320 case 'T': 13321 { 13322 if (LocaleCompare(attribute,"text") == 0) 13323 { 13324 CloneString(&draw_info->text,SvPV(ST(i),na)); 13325 break; 13326 } 13327 if (LocaleCompare(attribute,"translate") == 0) 13328 { 13329 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13330 affine.tx=geometry_info.rho; 13331 affine.ty=geometry_info.sigma; 13332 if ((flags & SigmaValue) == 0) 13333 affine.ty=affine.tx; 13334 break; 13335 } 13336 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13337 attribute); 13338 break; 13339 } 13340 case 'w': 13341 case 'W': 13342 { 13343 if (LocaleCompare(attribute,"weight") == 0) 13344 { 13345 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13346 draw_info->weight=(size_t) geometry_info.rho; 13347 break; 13348 } 13349 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13350 attribute); 13351 break; 13352 } 13353 case 'x': 13354 case 'X': 13355 { 13356 if (LocaleCompare(attribute,"x") == 0) 13357 { 13358 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13359 x=geometry_info.rho; 13360 break; 13361 } 13362 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13363 attribute); 13364 break; 13365 } 13366 case 'y': 13367 case 'Y': 13368 { 13369 if (LocaleCompare(attribute,"y") == 0) 13370 { 13371 flags=ParseGeometry(SvPV(ST(i),na),&geometry_info); 13372 y=geometry_info.rho; 13373 break; 13374 } 13375 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13376 attribute); 13377 break; 13378 } 13379 default: 13380 { 13381 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 13382 attribute); 13383 break; 13384 } 13385 } 13386 } 13387 draw_info->affine.sx=current.sx*affine.sx+current.ry*affine.rx; 13388 draw_info->affine.rx=current.rx*affine.sx+current.sy*affine.rx; 13389 draw_info->affine.ry=current.sx*affine.ry+current.ry*affine.sy; 13390 draw_info->affine.sy=current.rx*affine.ry+current.sy*affine.sy; 13391 draw_info->affine.tx=current.sx*affine.tx+current.ry*affine.ty+current.tx; 13392 draw_info->affine.ty=current.rx*affine.tx+current.sy*affine.ty+current.ty; 13393 if (draw_info->geometry == (char *) NULL) 13394 { 13395 draw_info->geometry=AcquireString((char *) NULL); 13396 (void) FormatLocaleString(draw_info->geometry,MagickPathExtent, 13397 "%.15g,%.15g",x,y); 13398 } 13399 status=GetMultilineTypeMetrics(image,draw_info,&metrics,exception); 13400 (void) CatchException(exception); 13401 if (status == MagickFalse) 13402 PUSHs(&sv_undef); 13403 else 13404 { 13405 PUSHs(sv_2mortal(newSVnv(metrics.pixels_per_em.x))); 13406 PUSHs(sv_2mortal(newSVnv(metrics.pixels_per_em.y))); 13407 PUSHs(sv_2mortal(newSVnv(metrics.ascent))); 13408 PUSHs(sv_2mortal(newSVnv(metrics.descent))); 13409 PUSHs(sv_2mortal(newSVnv(metrics.width))); 13410 PUSHs(sv_2mortal(newSVnv(metrics.height))); 13411 PUSHs(sv_2mortal(newSVnv(metrics.max_advance))); 13412 PUSHs(sv_2mortal(newSVnv(metrics.bounds.x1))); 13413 PUSHs(sv_2mortal(newSVnv(metrics.bounds.y1))); 13414 PUSHs(sv_2mortal(newSVnv(metrics.bounds.x2))); 13415 PUSHs(sv_2mortal(newSVnv(metrics.bounds.y2))); 13416 PUSHs(sv_2mortal(newSVnv(metrics.origin.x))); 13417 PUSHs(sv_2mortal(newSVnv(metrics.origin.y))); 13418 } 13419 draw_info=DestroyDrawInfo(draw_info); 13420 13421 PerlException: 13422 if (package_info != (struct PackageInfo *) NULL) 13423 DestroyPackageInfo(package_info); 13424 InheritPerlException(exception,perl_exception); 13425 exception=DestroyExceptionInfo(exception); 13426 SvREFCNT_dec(perl_exception); /* can't return warning messages */ 13427 } 13428 13429 # 13431 ############################################################################### 13432 # # 13433 # # 13434 # # 13435 # Q u e r y F o r m a t # 13436 # # 13437 # # 13438 # # 13439 ############################################################################### 13440 # 13441 # 13442 void 13443 QueryFormat(ref,...) 13444 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13445 ALIAS: 13446 queryformat = 1 13447 PPCODE: 13448 { 13449 char 13450 *name; 13451 13452 ExceptionInfo 13453 *exception; 13454 13455 register ssize_t 13456 i; 13457 13458 SV 13459 *perl_exception; 13460 13461 volatile const MagickInfo 13462 *magick_info; 13463 13464 PERL_UNUSED_VAR(ref); 13465 PERL_UNUSED_VAR(ix); 13466 exception=AcquireExceptionInfo(); 13467 perl_exception=newSVpv("",0); 13468 if (items == 1) 13469 { 13470 char 13471 format[MagickPathExtent]; 13472 13473 const MagickInfo 13474 **format_list; 13475 13476 size_t 13477 types; 13478 13479 format_list=GetMagickInfoList("*",&types,exception); 13480 EXTEND(sp,types); 13481 for (i=0; i < (ssize_t) types; i++) 13482 { 13483 (void) CopyMagickString(format,format_list[i]->name,MagickPathExtent); 13484 LocaleLower(format); 13485 PUSHs(sv_2mortal(newSVpv(format,0))); 13486 } 13487 format_list=(const MagickInfo **) 13488 RelinquishMagickMemory((MagickInfo *) format_list); 13489 goto PerlException; 13490 } 13491 EXTEND(sp,8*items); 13492 for (i=1; i < items; i++) 13493 { 13494 name=(char *) SvPV(ST(i),na); 13495 magick_info=GetMagickInfo(name,exception); 13496 if (magick_info == (const MagickInfo *) NULL) 13497 { 13498 PUSHs(&sv_undef); 13499 continue; 13500 } 13501 if (magick_info->description == (char *) NULL) 13502 PUSHs(&sv_undef); 13503 else 13504 PUSHs(sv_2mortal(newSVpv(magick_info->description,0))); 13505 if (magick_info->module == (char *) NULL) 13506 PUSHs(&sv_undef); 13507 else 13508 PUSHs(sv_2mortal(newSVpv(magick_info->module,0))); 13509 } 13510 13511 PerlException: 13512 InheritPerlException(exception,perl_exception); 13513 exception=DestroyExceptionInfo(exception); 13514 SvREFCNT_dec(perl_exception); 13515 } 13516 13517 # 13519 ############################################################################### 13520 # # 13521 # # 13522 # # 13523 # Q u e r y O p t i o n # 13524 # # 13525 # # 13526 # # 13527 ############################################################################### 13528 # 13529 # 13530 void 13531 QueryOption(ref,...) 13532 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13533 ALIAS: 13534 queryoption = 1 13535 PPCODE: 13536 { 13537 char 13538 **options; 13539 13540 ExceptionInfo 13541 *exception; 13542 13543 register ssize_t 13544 i; 13545 13546 ssize_t 13547 j, 13548 option; 13549 13550 SV 13551 *perl_exception; 13552 13553 PERL_UNUSED_VAR(ref); 13554 PERL_UNUSED_VAR(ix); 13555 exception=AcquireExceptionInfo(); 13556 perl_exception=newSVpv("",0); 13557 EXTEND(sp,8*items); 13558 for (i=1; i < items; i++) 13559 { 13560 option=ParseCommandOption(MagickListOptions,MagickFalse,(char *) 13561 SvPV(ST(i),na)); 13562 options=GetCommandOptions((CommandOption) option); 13563 if (options == (char **) NULL) 13564 PUSHs(&sv_undef); 13565 else 13566 { 13567 for (j=0; options[j] != (char *) NULL; j++) 13568 PUSHs(sv_2mortal(newSVpv(options[j],0))); 13569 options=DestroyStringList(options); 13570 } 13571 } 13572 13573 InheritPerlException(exception,perl_exception); 13574 exception=DestroyExceptionInfo(exception); 13575 SvREFCNT_dec(perl_exception); 13576 } 13577 13578 # 13580 ############################################################################### 13581 # # 13582 # # 13583 # # 13584 # R e a d # 13585 # # 13586 # # 13587 # # 13588 ############################################################################### 13589 # 13590 # 13591 void 13592 Read(ref,...) 13593 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13594 ALIAS: 13595 ReadImage = 1 13596 read = 2 13597 readimage = 3 13598 PPCODE: 13599 { 13600 AV 13601 *av; 13602 13603 char 13604 **keep, 13605 **list; 13606 13607 ExceptionInfo 13608 *exception; 13609 13610 HV 13611 *hv; 13612 13613 Image 13614 *image; 13615 13616 int 13617 n; 13618 13619 MagickBooleanType 13620 status; 13621 13622 register char 13623 **p; 13624 13625 register ssize_t 13626 i; 13627 13628 ssize_t 13629 ac, 13630 number_images; 13631 13632 STRLEN 13633 *length; 13634 13635 struct PackageInfo 13636 *info, 13637 *package_info; 13638 13639 SV 13640 *perl_exception, /* Perl variable for storing messages */ 13641 *reference, 13642 *rv, 13643 *sv; 13644 13645 PERL_UNUSED_VAR(ref); 13646 PERL_UNUSED_VAR(ix); 13647 exception=AcquireExceptionInfo(); 13648 perl_exception=newSVpv("",0); 13649 sv=NULL; 13650 package_info=(struct PackageInfo *) NULL; 13651 number_images=0; 13652 ac=(items < 2) ? 1 : items-1; 13653 list=(char **) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*list)); 13654 keep=list; 13655 length=(STRLEN *) NULL; 13656 if (list == (char **) NULL) 13657 { 13658 ThrowPerlException(exception,ResourceLimitError, 13659 "MemoryAllocationFailed",PackageName); 13660 goto PerlException; 13661 } 13662 length=(STRLEN *) AcquireQuantumMemory((size_t) ac+1UL,sizeof(*length)); 13663 if (length == (STRLEN *) NULL) 13664 { 13665 ThrowPerlException(exception,ResourceLimitError, 13666 "MemoryAllocationFailed",PackageName); 13667 goto PerlException; 13668 } 13669 if (sv_isobject(ST(0)) == 0) 13670 { 13671 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 13672 PackageName); 13673 goto PerlException; 13674 } 13675 reference=SvRV(ST(0)); 13676 hv=SvSTASH(reference); 13677 if (SvTYPE(reference) != SVt_PVAV) 13678 { 13679 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 13680 PackageName); 13681 goto PerlException; 13682 } 13683 av=(AV *) reference; 13684 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 13685 exception); 13686 package_info=ClonePackageInfo(info,exception); 13687 n=1; 13688 if (items <= 1) 13689 *list=(char *) (*package_info->image_info->filename ? 13690 package_info->image_info->filename : "XC:black"); 13691 else 13692 for (n=0, i=0; i < ac; i++) 13693 { 13694 list[n]=(char *) SvPV(ST(i+1),length[n]); 13695 if ((items >= 3) && strEQcase(list[n],"blob")) 13696 { 13697 void 13698 *blob; 13699 13700 i++; 13701 blob=(void *) (SvPV(ST(i+1),length[n])); 13702 SetImageInfoBlob(package_info->image_info,blob,(size_t) length[n]); 13703 } 13704 if ((items >= 3) && strEQcase(list[n],"filename")) 13705 continue; 13706 if ((items >= 3) && strEQcase(list[n],"file")) 13707 { 13708 FILE 13709 *file; 13710 13711 PerlIO 13712 *io_info; 13713 13714 i++; 13715 io_info=IoIFP(sv_2io(ST(i+1))); 13716 if (io_info == (PerlIO *) NULL) 13717 { 13718 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 13719 PackageName); 13720 continue; 13721 } 13722 file=PerlIO_findFILE(io_info); 13723 if (file == (FILE *) NULL) 13724 { 13725 ThrowPerlException(exception,BlobError,"UnableToOpenFile", 13726 PackageName); 13727 continue; 13728 } 13729 SetImageInfoFile(package_info->image_info,file); 13730 } 13731 if ((items >= 3) && strEQcase(list[n],"magick")) 13732 continue; 13733 n++; 13734 } 13735 list[n]=(char *) NULL; 13736 keep=list; 13737 status=ExpandFilenames(&n,&list); 13738 if (status == MagickFalse) 13739 { 13740 ThrowPerlException(exception,ResourceLimitError, 13741 "MemoryAllocationFailed",PackageName); 13742 goto PerlException; 13743 } 13744 number_images=0; 13745 for (i=0; i < n; i++) 13746 { 13747 if ((package_info->image_info->file == (FILE *) NULL) && 13748 (package_info->image_info->blob == (void *) NULL)) 13749 image=ReadImages(package_info->image_info,list[i],exception); 13750 else 13751 { 13752 image=ReadImages(package_info->image_info, 13753 package_info->image_info->filename,exception); 13754 if (image != (Image *) NULL) 13755 DisassociateImageStream(image); 13756 } 13757 if (image == (Image *) NULL) 13758 break; 13759 for ( ; image; image=image->next) 13760 { 13761 AddImageToRegistry(sv,image); 13762 rv=newRV(sv); 13763 av_push(av,sv_bless(rv,hv)); 13764 SvREFCNT_dec(sv); 13765 number_images++; 13766 } 13767 } 13768 /* 13769 Free resources. 13770 */ 13771 for (i=0; i < n; i++) 13772 if (list[i] != (char *) NULL) 13773 for (p=keep; list[i] != *p++; ) 13774 if (*p == (char *) NULL) 13775 { 13776 list[i]=(char *) RelinquishMagickMemory(list[i]); 13777 break; 13778 } 13779 13780 PerlException: 13781 if (package_info != (struct PackageInfo *) NULL) 13782 DestroyPackageInfo(package_info); 13783 if (list && (list != keep)) 13784 list=(char **) RelinquishMagickMemory(list); 13785 if (keep) 13786 keep=(char **) RelinquishMagickMemory(keep); 13787 if (length) 13788 length=(STRLEN *) RelinquishMagickMemory(length); 13789 InheritPerlException(exception,perl_exception); 13790 exception=DestroyExceptionInfo(exception); 13791 sv_setiv(perl_exception,(IV) number_images); 13792 SvPOK_on(perl_exception); 13793 ST(0)=sv_2mortal(perl_exception); 13794 XSRETURN(1); 13795 } 13796 13797 # 13799 ############################################################################### 13800 # # 13801 # # 13802 # # 13803 # R e m o t e # 13804 # # 13805 # # 13806 # # 13807 ############################################################################### 13808 # 13809 # 13810 void 13811 Remote(ref,...) 13812 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13813 ALIAS: 13814 RemoteCommand = 1 13815 remote = 2 13816 remoteCommand = 3 13817 PPCODE: 13818 { 13819 AV 13820 *av; 13821 13822 ExceptionInfo 13823 *exception; 13824 13825 register ssize_t 13826 i; 13827 13828 SV 13829 *perl_exception, 13830 *reference; 13831 13832 struct PackageInfo 13833 *info; 13834 13835 PERL_UNUSED_VAR(ref); 13836 PERL_UNUSED_VAR(ix); 13837 exception=AcquireExceptionInfo(); 13838 perl_exception=newSVpv("",0); 13839 reference=SvRV(ST(0)); 13840 av=(AV *) reference; 13841 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 13842 exception); 13843 for (i=1; i < items; i++) 13844 (void) RemoteDisplayCommand(info->image_info,(char *) NULL,(char *) 13845 SvPV(ST(i),na),exception); 13846 InheritPerlException(exception,perl_exception); 13847 exception=DestroyExceptionInfo(exception); 13848 SvREFCNT_dec(perl_exception); /* throw away all errors */ 13849 } 13850 13851 # 13853 ############################################################################### 13854 # # 13855 # # 13856 # # 13857 # S e t # 13858 # # 13859 # # 13860 # # 13861 ############################################################################### 13862 # 13863 # 13864 void 13865 Set(ref,...) 13866 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13867 ALIAS: 13868 SetAttributes = 1 13869 SetAttribute = 2 13870 set = 3 13871 setattributes = 4 13872 setattribute = 5 13873 PPCODE: 13874 { 13875 ExceptionInfo 13876 *exception; 13877 13878 Image 13879 *image; 13880 13881 register ssize_t 13882 i; 13883 13884 struct PackageInfo 13885 *info; 13886 13887 SV 13888 *perl_exception, 13889 *reference; /* reference is the SV* of ref=SvIV(reference) */ 13890 13891 PERL_UNUSED_VAR(ref); 13892 PERL_UNUSED_VAR(ix); 13893 exception=AcquireExceptionInfo(); 13894 perl_exception=newSVpv("",0); 13895 if (sv_isobject(ST(0)) == 0) 13896 { 13897 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 13898 PackageName); 13899 goto PerlException; 13900 } 13901 reference=SvRV(ST(0)); 13902 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 13903 if (items == 2) 13904 SetAttribute(aTHX_ info,image,"size",ST(1),exception); 13905 else 13906 for (i=2; i < items; i+=2) 13907 SetAttribute(aTHX_ info,image,SvPV(ST(i-1),na),ST(i),exception); 13908 13909 PerlException: 13910 InheritPerlException(exception,perl_exception); 13911 exception=DestroyExceptionInfo(exception); 13912 sv_setiv(perl_exception,(IV) (SvCUR(perl_exception) != 0)); 13913 SvPOK_on(perl_exception); 13914 ST(0)=sv_2mortal(perl_exception); 13915 XSRETURN(1); 13916 } 13917 13918 # 13920 ############################################################################### 13921 # # 13922 # # 13923 # # 13924 # S e t P i x e l # 13925 # # 13926 # # 13927 # # 13928 ############################################################################### 13929 # 13930 # 13931 void 13932 SetPixel(ref,...) 13933 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 13934 ALIAS: 13935 setpixel = 1 13936 setPixel = 2 13937 PPCODE: 13938 { 13939 AV 13940 *av; 13941 13942 char 13943 *attribute; 13944 13945 ChannelType 13946 channel, 13947 channel_mask; 13948 13949 ExceptionInfo 13950 *exception; 13951 13952 Image 13953 *image; 13954 13955 MagickBooleanType 13956 normalize; 13957 13958 RectangleInfo 13959 region; 13960 13961 register ssize_t 13962 i; 13963 13964 register Quantum 13965 *q; 13966 13967 ssize_t 13968 option; 13969 13970 struct PackageInfo 13971 *info; 13972 13973 SV 13974 *perl_exception, 13975 *reference; /* reference is the SV* of ref=SvIV(reference) */ 13976 13977 PERL_UNUSED_VAR(ref); 13978 PERL_UNUSED_VAR(ix); 13979 exception=AcquireExceptionInfo(); 13980 perl_exception=newSVpv("",0); 13981 reference=SvRV(ST(0)); 13982 av=(AV *) reference; 13983 info=GetPackageInfo(aTHX_ (void *) av,(struct PackageInfo *) NULL, 13984 exception); 13985 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 13986 if (image == (Image *) NULL) 13987 { 13988 ThrowPerlException(exception,OptionError,"NoImagesDefined", 13989 PackageName); 13990 goto PerlException; 13991 } 13992 av=(AV *) NULL; 13993 normalize=MagickTrue; 13994 region.x=0; 13995 region.y=0; 13996 region.width=image->columns; 13997 region.height=1; 13998 if (items == 1) 13999 (void) ParseAbsoluteGeometry(SvPV(ST(1),na),®ion); 14000 channel=DefaultChannels; 14001 for (i=2; i < items; i+=2) 14002 { 14003 attribute=(char *) SvPV(ST(i-1),na); 14004 switch (*attribute) 14005 { 14006 case 'C': 14007 case 'c': 14008 { 14009 if (LocaleCompare(attribute,"channel") == 0) 14010 { 14011 ssize_t 14012 option; 14013 14014 option=ParseChannelOption(SvPV(ST(i),na)); 14015 if (option < 0) 14016 { 14017 ThrowPerlException(exception,OptionError,"UnrecognizedType", 14018 SvPV(ST(i),na)); 14019 return; 14020 } 14021 channel=(ChannelType) option; 14022 break; 14023 } 14024 if (LocaleCompare(attribute,"color") == 0) 14025 { 14026 if (SvTYPE(ST(i)) != SVt_RV) 14027 { 14028 char 14029 message[MagickPathExtent]; 14030 14031 (void) FormatLocaleString(message,MagickPathExtent, 14032 "invalid %.60s value",attribute); 14033 ThrowPerlException(exception,OptionError,message, 14034 SvPV(ST(i),na)); 14035 } 14036 av=(AV *) SvRV(ST(i)); 14037 break; 14038 } 14039 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14040 attribute); 14041 break; 14042 } 14043 case 'g': 14044 case 'G': 14045 { 14046 if (LocaleCompare(attribute,"geometry") == 0) 14047 { 14048 (void) ParseAbsoluteGeometry(SvPV(ST(i),na),®ion); 14049 break; 14050 } 14051 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14052 attribute); 14053 break; 14054 } 14055 case 'N': 14056 case 'n': 14057 { 14058 if (LocaleCompare(attribute,"normalize") == 0) 14059 { 14060 option=ParseCommandOption(MagickBooleanOptions,MagickFalse, 14061 SvPV(ST(i),na)); 14062 if (option < 0) 14063 { 14064 ThrowPerlException(exception,OptionError,"UnrecognizedType", 14065 SvPV(ST(i),na)); 14066 break; 14067 } 14068 normalize=option != 0 ? MagickTrue : MagickFalse; 14069 break; 14070 } 14071 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14072 attribute); 14073 break; 14074 } 14075 case 'x': 14076 case 'X': 14077 { 14078 if (LocaleCompare(attribute,"x") == 0) 14079 { 14080 region.x=SvIV(ST(i)); 14081 break; 14082 } 14083 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14084 attribute); 14085 break; 14086 } 14087 case 'y': 14088 case 'Y': 14089 { 14090 if (LocaleCompare(attribute,"y") == 0) 14091 { 14092 region.y=SvIV(ST(i)); 14093 break; 14094 } 14095 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14096 attribute); 14097 break; 14098 } 14099 default: 14100 { 14101 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14102 attribute); 14103 break; 14104 } 14105 } 14106 } 14107 (void) SetImageStorageClass(image,DirectClass,exception); 14108 channel_mask=SetImageChannelMask(image,channel); 14109 q=GetAuthenticPixels(image,region.x,region.y,1,1,exception); 14110 if ((q == (Quantum *) NULL) || (av == (AV *) NULL) || 14111 (SvTYPE(av) != SVt_PVAV)) 14112 PUSHs(&sv_undef); 14113 else 14114 { 14115 double 14116 scale; 14117 14118 register ssize_t 14119 i; 14120 14121 i=0; 14122 scale=1.0; 14123 if (normalize != MagickFalse) 14124 scale=QuantumRange; 14125 if (((GetPixelRedTraits(image) & UpdatePixelTrait) != 0) && 14126 (i <= av_len(av))) 14127 { 14128 SetPixelRed(image,ClampToQuantum(scale*SvNV(*( 14129 av_fetch(av,i,0)))),q); 14130 i++; 14131 } 14132 if (((GetPixelGreenTraits(image) & UpdatePixelTrait) != 0) && 14133 (i <= av_len(av))) 14134 { 14135 SetPixelGreen(image,ClampToQuantum(scale*SvNV(*( 14136 av_fetch(av,i,0)))),q); 14137 i++; 14138 } 14139 if (((GetPixelBlueTraits(image) & UpdatePixelTrait) != 0) && 14140 (i <= av_len(av))) 14141 { 14142 SetPixelBlue(image,ClampToQuantum(scale*SvNV(*( 14143 av_fetch(av,i,0)))),q); 14144 i++; 14145 } 14146 if ((((GetPixelBlackTraits(image) & UpdatePixelTrait) != 0) && 14147 (image->colorspace == CMYKColorspace)) && (i <= av_len(av))) 14148 { 14149 SetPixelBlack(image,ClampToQuantum(scale* 14150 SvNV(*(av_fetch(av,i,0)))),q); 14151 i++; 14152 } 14153 if (((GetPixelAlphaTraits(image) & UpdatePixelTrait) != 0) && 14154 (i <= av_len(av))) 14155 { 14156 SetPixelAlpha(image,ClampToQuantum(scale* 14157 SvNV(*(av_fetch(av,i,0)))),q); 14158 i++; 14159 } 14160 (void) SyncAuthenticPixels(image,exception); 14161 } 14162 (void) SetImageChannelMask(image,channel_mask); 14163 14164 PerlException: 14165 InheritPerlException(exception,perl_exception); 14166 exception=DestroyExceptionInfo(exception); 14167 SvREFCNT_dec(perl_exception); 14168 } 14169 14170 # 14172 ############################################################################### 14173 # # 14174 # # 14175 # # 14176 # S m u s h # 14177 # # 14178 # # 14179 # # 14180 ############################################################################### 14181 # 14182 # 14183 void 14184 Smush(ref,...) 14185 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 14186 ALIAS: 14187 SmushImage = 1 14188 smush = 2 14189 smushimage = 3 14190 PPCODE: 14191 { 14192 AV 14193 *av; 14194 14195 char 14196 *attribute; 14197 14198 ExceptionInfo 14199 *exception; 14200 14201 HV 14202 *hv; 14203 14204 Image 14205 *image; 14206 14207 register ssize_t 14208 i; 14209 14210 ssize_t 14211 offset, 14212 stack; 14213 14214 struct PackageInfo 14215 *info; 14216 14217 SV 14218 *av_reference, 14219 *perl_exception, 14220 *reference, 14221 *rv, 14222 *sv; 14223 14224 PERL_UNUSED_VAR(ref); 14225 PERL_UNUSED_VAR(ix); 14226 exception=AcquireExceptionInfo(); 14227 perl_exception=newSVpv("",0); 14228 sv=NULL; 14229 attribute=NULL; 14230 av=NULL; 14231 if (sv_isobject(ST(0)) == 0) 14232 { 14233 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 14234 PackageName); 14235 goto PerlException; 14236 } 14237 reference=SvRV(ST(0)); 14238 hv=SvSTASH(reference); 14239 av=newAV(); 14240 av_reference=sv_2mortal(sv_bless(newRV((SV *) av),hv)); 14241 SvREFCNT_dec(av); 14242 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 14243 if (image == (Image *) NULL) 14244 { 14245 ThrowPerlException(exception,OptionError,"NoImagesDefined", 14246 PackageName); 14247 goto PerlException; 14248 } 14249 info=GetPackageInfo(aTHX_ (void *) av,info,exception); 14250 /* 14251 Get options. 14252 */ 14253 offset=0; 14254 stack=MagickTrue; 14255 for (i=2; i < items; i+=2) 14256 { 14257 attribute=(char *) SvPV(ST(i-1),na); 14258 switch (*attribute) 14259 { 14260 case 'O': 14261 case 'o': 14262 { 14263 if (LocaleCompare(attribute,"offset") == 0) 14264 { 14265 offset=(ssize_t) StringToLong((char *) SvPV(ST(1),na)); 14266 break; 14267 } 14268 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14269 attribute); 14270 break; 14271 } 14272 case 'S': 14273 case 's': 14274 { 14275 if (LocaleCompare(attribute,"stack") == 0) 14276 { 14277 stack=ParseCommandOption(MagickBooleanOptions,MagickFalse, 14278 SvPV(ST(i),na)); 14279 if (stack < 0) 14280 { 14281 ThrowPerlException(exception,OptionError,"UnrecognizedType", 14282 SvPV(ST(i),na)); 14283 return; 14284 } 14285 break; 14286 } 14287 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14288 attribute); 14289 break; 14290 } 14291 default: 14292 { 14293 ThrowPerlException(exception,OptionError,"UnrecognizedAttribute", 14294 attribute); 14295 break; 14296 } 14297 } 14298 } 14299 image=SmushImages(image,stack != 0 ? MagickTrue : MagickFalse,offset, 14300 exception); 14301 if (image == (Image *) NULL) 14302 goto PerlException; 14303 for ( ; image; image=image->next) 14304 { 14305 AddImageToRegistry(sv,image); 14306 rv=newRV(sv); 14307 av_push(av,sv_bless(rv,hv)); 14308 SvREFCNT_dec(sv); 14309 } 14310 exception=DestroyExceptionInfo(exception); 14311 ST(0)=av_reference; 14312 SvREFCNT_dec(perl_exception); 14313 XSRETURN(1); 14314 14315 PerlException: 14316 InheritPerlException(exception,perl_exception); 14317 exception=DestroyExceptionInfo(exception); 14318 sv_setiv(perl_exception,(IV) SvCUR(perl_exception) != 0); 14319 SvPOK_on(perl_exception); 14320 ST(0)=sv_2mortal(perl_exception); 14321 XSRETURN(1); 14322 } 14323 14324 # 14326 ############################################################################### 14327 # # 14328 # # 14329 # # 14330 # S t a t i s t i c s # 14331 # # 14332 # # 14333 # # 14334 ############################################################################### 14335 # 14336 # 14337 void 14338 Statistics(ref,...) 14339 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 14340 ALIAS: 14341 StatisticsImage = 1 14342 statistics = 2 14343 statisticsimage = 3 14344 PPCODE: 14345 { 14346 #define ChannelStatistics(channel) \ 14347 { \ 14348 (void) FormatLocaleString(message,MagickPathExtent,"%.20g", \ 14349 (double) channel_statistics[channel].depth); \ 14350 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14351 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14352 channel_statistics[channel].minima/scale); \ 14353 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14354 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14355 channel_statistics[channel].maxima/scale); \ 14356 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14357 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14358 channel_statistics[channel].mean/scale); \ 14359 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14360 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14361 channel_statistics[channel].standard_deviation/scale); \ 14362 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14363 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14364 channel_statistics[channel].kurtosis); \ 14365 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14366 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14367 channel_statistics[channel].skewness); \ 14368 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14369 (void) FormatLocaleString(message,MagickPathExtent,"%.15g", \ 14370 channel_statistics[channel].entropy); \ 14371 PUSHs(sv_2mortal(newSVpv(message,0))); \ 14372 } 14373 14374 AV 14375 *av; 14376 14377 char 14378 message[MagickPathExtent]; 14379 14380 ChannelStatistics 14381 *channel_statistics; 14382 14383 double 14384 scale; 14385 14386 ExceptionInfo 14387 *exception; 14388 14389 Image 14390 *image; 14391 14392 ssize_t 14393 count; 14394 14395 struct PackageInfo 14396 *info; 14397 14398 SV 14399 *perl_exception, 14400 *reference; 14401 14402 PERL_UNUSED_VAR(ref); 14403 PERL_UNUSED_VAR(ix); 14404 exception=AcquireExceptionInfo(); 14405 perl_exception=newSVpv("",0); 14406 av=NULL; 14407 if (sv_isobject(ST(0)) == 0) 14408 { 14409 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 14410 PackageName); 14411 goto PerlException; 14412 } 14413 reference=SvRV(ST(0)); 14414 av=newAV(); 14415 SvREFCNT_dec(av); 14416 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 14417 if (image == (Image *) NULL) 14418 { 14419 ThrowPerlException(exception,OptionError,"NoImagesDefined", 14420 PackageName); 14421 goto PerlException; 14422 } 14423 count=0; 14424 for ( ; image; image=image->next) 14425 { 14426 channel_statistics=GetImageStatistics(image,exception); 14427 if (channel_statistics == (ChannelStatistics *) NULL) 14428 continue; 14429 count++; 14430 EXTEND(sp,35*count); 14431 scale=(double) QuantumRange; 14432 ChannelStatistics(RedChannel); 14433 ChannelStatistics(GreenChannel); 14434 ChannelStatistics(BlueChannel); 14435 if (image->colorspace == CMYKColorspace) 14436 ChannelStatistics(BlackChannel); 14437 if (image->alpha_trait != UndefinedPixelTrait) 14438 ChannelStatistics(AlphaChannel); 14439 channel_statistics=(ChannelStatistics *) 14440 RelinquishMagickMemory(channel_statistics); 14441 } 14442 14443 PerlException: 14444 InheritPerlException(exception,perl_exception); 14445 exception=DestroyExceptionInfo(exception); 14446 SvREFCNT_dec(perl_exception); 14447 } 14448 14449 # 14451 ############################################################################### 14452 # # 14453 # # 14454 # # 14455 # S y n c A u t h e n t i c P i x e l s # 14456 # # 14457 # # 14458 # # 14459 ############################################################################### 14460 # 14461 # 14462 void 14463 SyncAuthenticPixels(ref,...) 14464 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 14465 ALIAS: 14466 Syncauthenticpixels = 1 14467 SyncImagePixels = 2 14468 syncimagepixels = 3 14469 CODE: 14470 { 14471 ExceptionInfo 14472 *exception; 14473 14474 Image 14475 *image; 14476 14477 MagickBooleanType 14478 status; 14479 14480 struct PackageInfo 14481 *info; 14482 14483 SV 14484 *perl_exception, 14485 *reference; 14486 14487 PERL_UNUSED_VAR(ref); 14488 PERL_UNUSED_VAR(ix); 14489 exception=AcquireExceptionInfo(); 14490 perl_exception=newSVpv("",0); 14491 if (sv_isobject(ST(0)) == 0) 14492 { 14493 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 14494 PackageName); 14495 goto PerlException; 14496 } 14497 14498 reference=SvRV(ST(0)); 14499 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 14500 if (image == (Image *) NULL) 14501 { 14502 ThrowPerlException(exception,OptionError,"NoImagesDefined", 14503 PackageName); 14504 goto PerlException; 14505 } 14506 14507 status=SyncAuthenticPixels(image,exception); 14508 if (status != MagickFalse) 14509 return; 14510 14511 PerlException: 14512 InheritPerlException(exception,perl_exception); 14513 exception=DestroyExceptionInfo(exception); 14514 SvREFCNT_dec(perl_exception); /* throw away all errors */ 14515 } 14516 14517 14518 # 14519 ############################################################################### 14520 # # 14521 # # 14522 # # 14523 # W r i t e # 14524 # # 14525 # # 14526 # # 14527 ############################################################################### 14528 # 14529 # 14530 void 14531 Write(ref,...) 14532 Image::Magick::@MAGICK_ABI_SUFFIX@ ref = NO_INIT 14533 ALIAS: 14534 WriteImage = 1 14535 write = 2 14536 writeimage = 3 14537 PPCODE: 14538 { 14539 char 14540 filename[MagickPathExtent]; 14541 14542 ExceptionInfo 14543 *exception; 14544 14545 Image 14546 *image, 14547 *next; 14548 14549 register ssize_t 14550 i; 14551 14552 ssize_t 14553 number_images, 14554 scene; 14555 14556 struct PackageInfo 14557 *info, 14558 *package_info; 14559 14560 SV 14561 *perl_exception, 14562 *reference; 14563 14564 PERL_UNUSED_VAR(ref); 14565 PERL_UNUSED_VAR(ix); 14566 exception=AcquireExceptionInfo(); 14567 perl_exception=newSVpv("",0); 14568 number_images=0; 14569 package_info=(struct PackageInfo *) NULL; 14570 if (sv_isobject(ST(0)) == 0) 14571 { 14572 ThrowPerlException(exception,OptionError,"ReferenceIsNotMyType", 14573 PackageName); 14574 goto PerlException; 14575 } 14576 reference=SvRV(ST(0)); 14577 image=SetupList(aTHX_ reference,&info,(SV ***) NULL,exception); 14578 if (image == (Image *) NULL) 14579 { 14580 ThrowPerlException(exception,OptionError,"NoImagesDefined", 14581 PackageName); 14582 goto PerlException; 14583 } 14584 package_info=ClonePackageInfo(info,exception); 14585 if (items == 2) 14586 SetAttribute(aTHX_ package_info,NULL,"filename",ST(1),exception); 14587 else 14588 if (items > 2) 14589 for (i=2; i < items; i+=2) 14590 SetAttribute(aTHX_ package_info,image,SvPV(ST(i-1),na),ST(i), 14591 exception); 14592 (void) CopyMagickString(filename,package_info->image_info->filename, 14593 MagickPathExtent); 14594 scene=0; 14595 for (next=image; next; next=next->next) 14596 { 14597 (void) CopyMagickString(next->filename,filename,MagickPathExtent); 14598 next->scene=scene++; 14599 } 14600 *package_info->image_info->magick='\0'; 14601 SetImageInfo(package_info->image_info,(unsigned int) 14602 GetImageListLength(image),exception); 14603 for (next=image; next; next=next->next) 14604 { 14605 (void) WriteImage(package_info->image_info,next,exception); 14606 number_images++; 14607 if (package_info->image_info->adjoin) 14608 break; 14609 } 14610 14611 PerlException: 14612 if (package_info != (struct PackageInfo *) NULL) 14613 DestroyPackageInfo(package_info); 14614 InheritPerlException(exception,perl_exception); 14615 exception=DestroyExceptionInfo(exception); 14616 sv_setiv(perl_exception,(IV) number_images); 14617 SvPOK_on(perl_exception); 14618 ST(0)=sv_2mortal(perl_exception); 14619 XSRETURN(1); 14620 } 14621