1########################################################### 2# MagickWand test 3# - The purpose is to test the correctness of TclMagick, 4# not to produce meaningful output 5# 6########################################################### 7 8 9############################################ 10# Load debugging version 11# or require TclMagick package from library 12# 13if { $tcl_platform(platform) == "unix" } { 14 set auto_path [linsert $auto_path 0 [file join .. unix]] 15 package require TclMagick 16} else { 17 set dll [file join .. win debug tclMagick.dll] 18 if {[file exists $dll]} { 19 load $dll 20 } 21 package require TclMagick 22} 23puts [info script] 24 25 26########################################## 27# Global options 28# 29set IMG "logo:" 30set SEQ "../images/sequence.miff" 31set MAP "../images/map6colors.gif" 32set CLIP "../images/clippath.tif" 33set TMP "../tmp" 34 35########################################## 36# Check which tests should be performed 37# 38# ImageMagick only: FxImage, FxImageChannel, PreviewImages, TintImage 39set TestFunctions { 40 AdaptiveThresholdImage img 1 41 AddImage seq 1 42 AddNoiseImage img 1 43 AffineTransformImage img 1 44 ???-how-to-AnnotateImage img 0 45 AppendImages seq 1 46 AverageImages seq 1 47 BlackThresholdImage img 1 48 BlurImage img 1 49 BorderImage img 1 50 CharcoalImage img 1 51 ChopImage img 1 52 ClipImage img 1 53 ClipPathImage img 1 54 CoalesceImages seq 1 55 ColorFloodfillImage img 1 56 ColorizeImage img 1 57 CommentImage img 1 58 CompareImages img 1 59 CompareImageChannels img 1 60 CompositeImage img 1 61 ContrastImage img 1 62 ConvolveImage img 1 63 CropImage img 1 64 CycleColormapImage img 1 65 DeconstructImages seq 1 66 DescribeImage img 1 67 DespeckleImage img 1 68 DrawImage img 1 69 EdgeImage img 1 70 EmbossImage img 1 71 EnhanceImage img 1 72 EqualizeImage img 1 73 FlattenImage seq 1 74 FlipImage img 1 75 FlopImage img 1 76 FrameImage img 1 77 FxImage img 0 78 FxImageChannel img 0 79 GammaImage img 1 80 GammaImageChannel img 1 81 82 GetSetImage seq 1 83 GetSetFilename img 1 84 GetSetBackgroundColor img 1 85 GetSetBluePrimary img 1 86 GetSetBorderColor img 1 87 GetSetChannelDepth img 1 88 GetChannelExtrema img 1 89 GetChannelMean img 1 90 GetSetColormapColor img 1 91 GetColors img 1 92 GetSetColorspace img 1 93 GetSetCompose img 1 94 GetSetCompression img 1 95 GetSetDelay seq 1 96 GetSetDepth img 1 97 GetSetDispose img 1 98 GetExtrema img 1 99 GetFormat img 1 100 GetSetGamma img 1 101 GetSetGreenPrimary img 1 102 GetHeight img 1 103 GetSetIndex seq 1 104 GetSetInterlaceScheme img 1 105 GetSetIterations img 1 106 GetSetMatteColor img 1 107 GetSetImageFilename img 1 108 GetSetPixels img 1 109 GetSetRemoveProfile img 1 110 GetSetRedPrimary img 1 111 GetSetRendering img 1 112 GetSetResolution img 1 113 GetSetScene seq 1 114 GetImageSize img 1 115 GetSignature img 1 116 GetSetImageType img 1 117 GetSetImageUnits img 1 118 GetSetVirtualPixelMethod img 1 119 GetSetWhitePoint img 1 120 GetWidth img 1 121 GetNumberImages seq 1 122 GetSetSamplingFactors img 1 123 GetSetSize img 1 124 ImplodeImage img 0 125 LabelImage img 1 126 LevelImage img 1 127 LevelImageChannel img 1 128 MagnifyImage img 1 129 MapImage img 1 130 MatteFloodfillImage img 1 131 MedianFilterImage img 1 132 MinifyImage img 1 133 ModulateImage img 1 134 MontageImage seq 1 135 MorphImages seq 1 136 MosaicImages seq 1 137 MotionBlurImage img 1 138 NegateImage img 1 139 NormalizeImage img 1 140 141 NextPrevious seq 1 142 143 OilPaintImage img 1 144 OpaqueImage img 1 145 PingImage SEQ 1 146 PreviewImages img 0 147 QuantizeImage img 1 148 QueryFontMetrics img 1 149 RaiseImage img 1 150 ReadImageBlob SEQ 1 151 ReduceNoiseImage img 1 152 RemoveImage seq 1 153 ResampleImage img 1 154 ResizeImage img 1 155 RollImage img 1 156 RotateImage img 1 157 SampleImage img 1 158 ScaleImage img 1 159 SeparateImageChannel img 1 160 161 SetOption img 1 162 SetPassphrase img 1 163 164 SharpenImage img 1 165 ShaveImage img 1 166 ShearImage img 1 167 SolarizeImage img 1 168 SpreadImage img 1 169 SteganoImage img 1 170 StereoImage img 1 171 StripImage img 1 172 SwirlImage img 1 173 TextureImage img 1 174 ThresholdImage img 1 175 ThresholdImageChannel img 1 176 TintImage img 0 177 TransformImage img 1 178 TransparentImage img 1 179 TrimImage img 1 180 UnsharpMaskImage img 1 181 WaveImage img 1 182 WhiteThresholdImage img 1 183} 184 185############################################ 186# Command debugging 187# 188catch { 189 wm withdraw . 190 console show 191 console eval {wm protocol . WM_DELETE_WINDOW exit} 192} 193proc debug {args} { 194 foreach cmdMask $args { 195 foreach cmd [info commands $cmdMask] { 196 trace add execution $cmd leave debugLeave 197 } 198 } 199} 200proc debugLeave {cmdstr code result op} { 201 puts [format " %s ==>{%s}" [string range $cmdstr 0 50] [string range $result 0 50]] 202 update 203} 204 205########################################## 206# Single image tests 207# 208proc AdaptiveThresholdImage {img} { 209 set wand [$img clone imgX] 210 debug $wand 211 $wand AdaptiveThresholdImage 5 5 0 212 $wand WriteImage "$::TMP/x-Adaptive.jpg" 213 magick delete $wand 214} 215proc AddImage {seq} { 216 set wand [$seq clone seqX] 217 debug $wand 218 219 $wand SetIndex 3 220 set x [$wand GetImage imgX] 221 $wand SetIndex 0 222 $wand AddImage $x 223 $wand WriteImages "$::TMP/x-Add.gif" 1 224 225 magick delete $wand $x 226} 227proc AddNoiseImage {img} { 228 foreach noise {impulse poisson} { ;# uniform gaussian multiplicativegaussian impulse laplacian poisson 229 set wand [$img clone imgX] 230 debug $wand 231 $wand AddNoiseImage $noise 232 $wand WriteImage "$::TMP/x-AddNoise-$noise.jpg" 233 magick delete $wand 234 } 235} 236proc AffineTransformImage {img} { 237 set wand [$img clone imgX] 238 set draw [magick create drawing] 239 debug $wand $draw 240 241 $draw Rotate 10 242 $draw Affine 1.0 3.0 3.0 2.0 2.0 2.0 243 $wand AffineTransformImage $draw 244 $wand WriteImage "$::TMP/x-Affine.jpg" 245 246 magick delete $draw $wand 247} 248proc AnnotateImage {img} { 249 set wand [$img clone imgX] 250 set draw [magick create drawing] 251 debug $wand $draw 252 253 [magick create pixel pix] SetColor "blue" 254 $draw push graph 255 $draw SetStrokeWidth 1 256 $draw SetStrokeColor pix 257 $draw SetFillColor pix 258 $draw SetFontSize 18 259 $draw pop graph 260 261 $wand AnnotateImage $draw 20 50 0 "Hello world" 262 $wand WriteImage "$::TMP/x-Annotate.jpg" 263 264 magick delete $draw $wand pix 265} 266proc AppendImages {seq} { 267 set wand [$seq AppendImages 0 seqX] 268 debug $wand 269 $wand WriteImages "$::TMP/x-Append.gif" 1 270 magick delete $wand 271} 272proc AverageImages {seq} { 273 set wand [$seq AverageImages seqX] 274 debug $wand 275 $wand WriteImage "$::TMP/x-Average.jpg" 276 magick delete $wand 277} 278proc BlackThresholdImage {img} { 279 set wand [$img clone imgX] 280 set pix [magick create pixel] 281 debug $wand $pix 282 283 $pix set red 0.5 green 0.5 blue 0.5 284 $pix GetColor 285 $wand BlackThresholdImage $pix 286 $wand WriteImage "$::TMP/x-BlackThreshold.jpg" 287 288 magick delete $pix $wand 289} 290proc BlurImage {img} { 291 set wand [$img clone imgX] 292 debug $wand 293 $wand BlurImage 2 3 294 $wand WriteImage "$::TMP/x-Blur.jpg" 295 magick delete $wand 296} 297proc BorderImage {img} { 298 set wand [$img clone imgX] 299 set pix [magick create pixel] 300 debug $wand $pix 301 302 $pix set red 1.0 green 1.0 blue 0.0 303 $pix GetColor 304 $wand BorderImage $pix 4 6 305 $wand WriteImage "$::TMP/x-Border.jpg" 306 307 magick delete $pix $wand 308} 309proc CharcoalImage {img} { 310 set wand [$img clone imgX] 311 debug $wand 312 $wand CharcoalImage 2.0 1.0 313 $wand WriteImage "$::TMP/x-Charcoal.jpg" 314 magick delete $wand 315} 316proc ChopImage {img} { 317 set wand [$img clone imgX] 318 debug $wand 319 $wand ChopImage 100 60 350 200 320 $wand WriteImage "$::TMP/x-Chop.jpg" 321 magick delete $wand 322} 323proc ClipImage {img} { 324 set wand [magick create wand] 325 debug $wand 326 327 $wand ReadImage $::CLIP 328 $wand ClipImage 329 $wand GammaImage 5.0 330 331 $wand WriteImage "$::TMP/x-Clip-Gamma.jpg" 332 magick delete $wand 333} 334proc ClipPathImage {img} { 335 set wand [magick create wand] 336 debug $wand 337 338 $wand ReadImage $::CLIP 339 $wand ClipPathImage "#1" 0 340 $wand SolarizeImage 3 341 342 $wand WriteImage "$::TMP/x-ClipPath-Solarize.jpg" 343 magick delete $wand 344} 345proc CoalesceImages {img} { 346 set new [$img CoalesceImages] 347 $new WriteImages "$::TMP/x-Coalesce.gif" 1 348 magick delete $new 349} 350proc ColorFloodfillImage {img} { 351 set wand [$img clone imgX] 352 set fill [magick create pixel] 353 set border [magick create pixel] 354 debug $wand $fill $border 355 356 $fill SetColor "lightgreen" 357 $border SetColor "black" 358 359 set max [magick library -maxrgb] 360 $wand ColorFloodfillImage $fill [expr {0.01 * $max}] {} 0 0 361 $wand WriteImage "$::TMP/x-ColorFloodfill-1.jpg" 362 363 $fill SetColor "lightblue" 364 $wand ColorFloodfillImage $fill [expr {0.01 * $max}] $border 0 0 365 $wand WriteImage "$::TMP/x-ColorFloodfill-2.jpg" 366 367 magick delete $fill $border $wand 368} 369proc ColorizeImage {img} { 370 set wand [$img clone imgX] 371 set fill [magick create pixel] 372 set opacity [magick create pixel] 373 debug $wand $fill $opacity 374 375 $fill color rgb(70%,0,0) 376 $opacity SetColor rgb(0,0,0) 377 $wand ColorizeImage $fill $opacity 378 379 $wand WriteImage "$::TMP/x-Colorize.jpg" 380 magick delete $fill $opacity $wand 381} 382proc CommentImage {img} { 383 set wand [$img clone imgX] 384 debug $wand 385 $wand CommentImage "This is a comment" 386 $wand WriteImage "$::TMP/x-Comment.jpg" 387 magick delete $wand 388} 389proc CompareImages {img} { 390 set wand [$img clone imgX] 391 debug $wand 392 $wand CompareImages $img peakabsoluteerror 393 $wand BlurImage 1.0 1.0 394 $wand CompareImages $img meansquarederror 395 magick delete $wand 396} 397proc CompareImageChannels {img} { 398 set wand [$img clone imgX] 399 debug $wand 400 $wand BlurImage 1.0 1.0 401 $wand CompareImageChannels $img red peakabsoluteerror 402 $wand CompareImageChannels $img blue peakabsoluteerror 403 magick delete $wand 404} 405proc CompositeImage {img} { 406 set wand [$img clone imgX] 407 set bg [magick create pixel] 408 debug $wand $bg 409 410 $bg SetColor rgb(50%,50%,50%) 411 $wand rotate $bg 90 412 $wand CompositeImage $img add 0 0 413 $wand WriteImage "$::TMP/x-Composite.jpg" 414 415 magick delete $wand $bg 416} 417proc ContrastImage {img} { 418 set wand [$img clone imgX] 419 debug $wand 420 $wand ContrastImage 1 421 $wand WriteImage "$::TMP/x-Contrast.jpg" 422 magick delete $wand 423} 424proc ConvolveImage {img} { 425 set wand [$img clone imgX] 426 debug $wand 427 $wand ConvolveImage 3 {0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1 0.1} 428 $wand WriteImage "$::TMP/x-Convolve.jpg" 429 magick delete $wand 430} 431proc CropImage {img} { 432 set wand [$img clone imgX] 433 debug $wand 434 $wand CropImage 100 60 350 200 435 $wand WriteImage "$::TMP/x-Crop.jpg" 436 magick delete $wand 437} 438proc CycleColormapImage {img} { 439 set wand [$img clone imgX] 440 debug $wand 441 $wand CycleColormapImage 10 442 $wand WriteImage "$::TMP/x-CycleColormap.jpg" 443 magick delete $wand 444} 445proc DeconstructImages {seq} { 446 set wand [$seq DeconstructImages seqX] 447 debug $wand 448 $wand WriteImage "$::TMP/x-Deconstruct-%d.jpg" 449 magick delete $wand 450} 451proc DescribeImage {img} { 452 set txt [$img DescribeImage] 453 set f [open "$::TMP/x-Describe.txt" w] 454 puts $f $txt 455 close $f 456} 457proc DespeckleImage {img} { 458 set wand [$img clone imgX] 459 debug $wand 460 $wand Despeckle 461 $wand WriteImage "$::TMP/x-Despeckle.jpg" 462 magick delete $wand 463} 464proc DrawImage {img} { 465 set wand [$img clone imgX] 466 set draw [magick create draw drawX] 467 debug $wand $draw 468 469 [magick create pixel whitePix] SetColor "white" 470 [magick create pixel bluePix] SetColor "blue" 471 [magick create pixel redPix] SetColor "red" 472 473 $draw push graph 474 $draw Rotate -45 475 $draw push graph 476 $draw SetStrokeWidth 2 477 $draw SetFillColor whitePix 478 $draw SetStrokeColor bluePix 479 $draw Rectangle -200 280 +90 310 480 $draw pop graph 481 482 $draw push graph 483 $draw SetStrokeWidth 0.5 484 $draw SetStrokeColor bluePix 485 $draw SetFillColor bluePix 486 $draw SetFontSize 18 487 $draw Annotation -197 300 "Tcl/Tk + ImageMagick = TclMagick" 488 $draw pop graph 489 $draw pop graph 490 491 $draw push graph 492 $draw SetStrokeWidth 0.5 493 $draw SetStrokeColor redPix 494 $draw SetFillColor redPix 495 $draw SetFontSize 14 496 $draw Annotation 10 400 "Image %wx%h (%xx%y dpi) format=%m size=%b" 497 $draw pop graph 498 499 $wand DrawImage $draw 500 $wand WriteImage "$::TMP/x-Draw.jpg" 501 502 magick delete whitePix bluePix redPix 503 magick delete $draw $wand 504} 505proc EdgeImage {img} { 506 set wand [$img clone imgX] 507 debug $wand 508 $wand EdgeImage 4.0 509 $wand WriteImage "$::TMP/x-Edge.jpg" 510 magick delete $wand 511} 512proc EmbossImage {img} { 513 set wand [$img clone imgX] 514 debug $wand 515 $wand EmbossImage 2.0 5.0 516 $wand WriteImage "$::TMP/x-Emboss.jpg" 517 magick delete $wand 518} 519proc EnhanceImage {img} { 520 set wand [$img clone imgX] 521 debug $wand 522 $wand AddNoiseImage impulse 523 $wand EnhanceImage 524 $wand WriteImage "$::TMP/x-Enhance.jpg" 525 magick delete $wand 526} 527proc EqualizeImage {img} { 528 set wand [$img clone imgX] 529 debug $wand 530 $wand EqualizeImage 531 $wand WriteImage "$::TMP/x-Equalize.jpg" 532 magick delete $wand 533} 534proc FlattenImage {seq} { 535 set wand [$seq FlattenImage] 536 debug $wand 537 $wand WriteImage "$::TMP/x-Flatten.jpg" 538 magick delete $wand 539} 540proc FlipImage {img} { 541 set wand [$img clone imgX] 542 debug $wand 543 $wand FlipImage 544 $wand WriteImage "$::TMP/x-Flip.jpg" 545 magick delete $wand 546} 547proc FlopImage {img} { 548 set wand [$img clone imgX] 549 debug $wand 550 $wand FlopImage 551 $wand WriteImage "$::TMP/x-Flop.jpg" 552 magick delete $wand 553} 554proc FrameImage {img} { 555 set wand [$img clone imgX] 556 set frm [magick create pixel] 557 debug $wand $frm 558 559 $frm set red 1.0 green 1.0 blue 0 560 $frm GetColor 561 $wand FrameImage $frm 8 8 3 3 562 563 $wand WriteImage "$::TMP/x-Frame.jpg" 564 magick delete $frm $wand 565} 566proc FxImage {img} { 567 set wand [$img FxImage "r/2"] 568 $wand WriteImage "$::TMP/x-Fx.jpg" 569 magick delete $wand 570} 571proc FxImageChannel {img} { 572 set wand [$img FxImageChannel blue "b/4"] 573 $wand WriteImage "$::TMP/x-FxChannel.jpg" 574 magick delete $wand 575} 576proc GammaImage {img} { 577 set wand [$img clone imgX] 578 debug $wand 579 580 $wand GammaImage 2.0 581 582 $wand WriteImage "$::TMP/x-Gamma.jpg" 583 magick delete $wand 584} 585proc GammaImageChannel {img} { 586 set wand [$img clone imgX] 587 debug $wand 588 589 $wand GammaImageChannel blue 2.0 590 591 $wand WriteImage "$::TMP/x-GammaChannel.jpg" 592 magick delete $wand 593} 594proc GetSetImage {seq} { 595 set wand [$seq clone seqX] 596 debug $wand 597 598 $wand SetIndex 2 599 set new [$wand GetImage imgX] 600 $wand SetIndex 1 601 while {[$wand HasNext]} { 602 $wand SetImage $new 603 $wand NextImage 604 } 605 $wand WriteImages "$::TMP/x-SetImage.gif" 1 606 607 magick delete $wand $new 608} 609proc GetSetFilename {img} { 610 set wand [$img clone imgX] 611 debug $wand 612 613 $img GetFilename 614 $wand filename "foo.jpg" 615 $wand filename 616 $wand SetFilename "bar.jpg" 617 $wand GetFilename 618 619 magick delete $wand 620} 621proc GetSetBackgroundColor {img} { 622 set wand [$img clone imgX] 623 set pix [magick create pixel pixX] 624 debug $wand $pix 625 626 $pix set red 0.0 green 0.5 blue 0.5 627 $wand SetBackgroundColor $pix 628 $pix set red 0 green 0 blue 0 629 $wand GetBackgroundColor $pix 630 $pix GetColor 631 632 magick delete $pix $wand 633} 634proc GetSetBluePrimary {img} { 635 set wand [$img clone imgX] 636 debug $wand 637 638 $wand GetBluePrimary 639 $wand SetBluePrimary 100 50 640 $wand GetBluePrimary 641 642 magick delete $wand 643} 644proc GetSetBorderColor {img} { 645 set wand [$img clone imgX] 646 set pix [magick create pixel pixX] 647 debug $wand $pix 648 649 $pix set red 0.0 green 0.5 blue 0.5 650 $wand SetBorderColor $pix 651 $pix set red 0 green 0 blue 0 652 $wand GetBorderColor $pix 653 $pix GetColor 654 655 magick delete $pix $wand 656} 657proc GetSetChannelDepth {img} { 658 set wand [$img clone imgX] 659 debug $wand 660 661 $wand GetChannelDepth red 662 $wand SetChannelDepth red 16 663 $wand GetChannelDepth red 664 665 magick delete $wand 666} 667proc GetChannelExtrema {img} { 668 $img GetChannelExtrema blue 669} 670proc GetChannelMean {img} { 671 $img GetChannelMean blue 672} 673proc GetSetColormapColor {img} { 674 set wand [$img clone imgX] 675 set pix [magick create pixel pixX] 676 debug $wand $pix 677 678 $pix set red 0 green 0.5 blue 0.7 679 $wand SetColormapColor 0 $pix 680 $pix GetColor 681 $pix set red 0 green 0 blue 0 682 $wand GetColormapColor 0 $pix 683 $pix GetColor 684 685 magick delete $pix $wand 686} 687proc GetColors {img} { 688 $img GetColors 689} 690proc GetSetColorspace {img} { 691 set wand [$img clone imgX] 692 debug $wand 693 694 $wand GetColorspace 695 $wand SetColorspace "RGB" 696 $wand GetColorspace 697 698 magick delete $wand 699} 700proc GetSetCompose {img} { 701 set wand [$img clone imgX] 702 debug $wand 703 704 $wand GetCompose 705 $wand SetCompose "xor" 706 $wand GetCompose 707 708 magick delete $wand 709} 710proc GetSetCompression {img} { 711 set wand [$img clone imgX] 712 debug $wand 713 714 $wand GetCompression 715 $wand SetCompression "zip" 716 $wand GetCompression 717 718 magick delete $wand 719} 720proc GetSetDelay {seq} { 721 set wand [$seq clone seqX] 722 debug $wand 723 724 $wand GetDelay 725 $wand SetDelay 123 726 $wand GetDelay 727 728 magick delete $wand 729} 730proc GetSetDepth {img} { 731 set wand [$img clone imgX] 732 debug $wand 733 734 $wand GetDepth 735 $wand SetDepth 16 736 $wand GetDepth 737 738 magick delete $wand 739} 740proc GetSetDispose {img} { 741 set wand [$img clone imgX] 742 debug $wand 743 744 $wand GetDispose 745 $wand SetDispose "background" 746 $wand GetDispose 747 748 magick delete $wand 749} 750proc GetExtrema {img} { 751 $img GetExtrema 752} 753proc GetFormat {img} { 754 $img GetFormat 755} 756proc GetSetGamma {img} { 757 set wand [$img clone imgX] 758 debug $wand 759 760 $wand GetGamma 761 $wand SetGamma 2.5 762 $wand GetGamma 763 764 magick delete $wand 765} 766proc GetSetGreenPrimary {img} { 767 set wand [$img clone imgX] 768 debug $wand 769 770 $wand GetGreenPrimary 771 $wand SetGreenPrimary 100 50 772 $wand GetGreenPrimary 773 774 magick delete $wand 775} 776proc GetHeight {img} { 777 $img GetHeight 778} 779proc GetSetIndex {seq} { 780 set wand [$seq clone seqX] 781 debug $wand 782 783 $wand GetIndex 784 $wand SetIndex 3 785 $wand GetIndex 786 787 magick delete $wand 788} 789proc GetSetInterlaceScheme {img} { 790 set wand [$img clone imgX] 791 debug $wand 792 793 $wand GetInterlaceScheme 794 $wand SetInterlaceScheme "plane" 795 $wand GetInterlaceScheme 796 797 magick delete $wand 798} 799proc GetSetIterations {img} { 800 set wand [$img clone imgX] 801 debug $wand 802 803 $wand GetIterations 804 $wand SetIterations 3 805 $wand GetIterations 806 807 magick delete $wand 808} 809proc GetSetMatteColor {img} { 810 set wand [$img clone imgX] 811 set pix [magick create pixel pixX] 812 debug $wand $pix 813 814 $pix set red 0 green 0.5 blue 0.7 815 $wand SetMatteColor $pix 816 $pix GetColor 817 $pix set red 0 green 0 blue 0 818 $wand GetMatteColor $pix 819 $pix GetColor 820 821 magick delete $pix $wand 822} 823proc GetSetImageFilename {img} { 824 set wand [$img clone imgX] 825 debug $wand 826 827 $wand GetImageFilename 828 $wand SetImageFilename "foo" 829 $wand GetImageFilename 830 831 magick delete $wand 832} 833proc GetSetPixels {img} { 834 set wand [$img clone imgX] 835 debug $wand 836 set pixelList { 837 0 0 0 838 0 0 255 839 0 255 0 840 0 255 255 841 255 255 255 842 255 0 0 843 255 0 255 844 255 255 0 845 128 128 128 846 } 847 set pix1 [binary format c* $pixelList] 848 849 $wand SetPixels 0 0 3 3 "RGB" char $pix1 850 set pix2 [$wand GetPixels 0 0 3 3 "RGB" char] 851 if {! [string equal $pix1 $pix2]} { 852 error "Get pixels do not match set pixels" 853 } 854 set data [$wand GetPixels 10 5 10 5 "RGB" char] 855 puts [format "image pixels: %d bytes, expected: %d bytes" [string length $data] 150] 856 $wand SetPixels 10 5 10 5 "RGB" char [binary format x150] 857 858 $wand WriteImage "$::TMP/x-Pixels.jpg" 859 magick delete $wand 860} 861proc GetSetRemoveProfile {img} { 862 set wand [$img clone imgX] 863 debug $wand 864 865 $wand SetProfile "icc" "foo" 866 $wand SetProfile "8bim" "bar" 867 $wand GetProfile "icc" 868 $wand GetProfile "8bim" 869 $wand RemoveProfile "icc" 870 $wand GetProfile "icc" 871 872 magick delete $wand 873} 874proc GetSetRemoveSetProfile {img} { 875 set wand [$img clone imgX] 876 debug $wand 877 $wand SetProfile ICC HALLO 878 $wand WriteImage "$::TMP/x-Profile.jpg" 879 magick delete $wand 880} 881proc GetSetRedPrimary {img} { 882 set wand [$img clone imgX] 883 debug $wand 884 885 $wand GetRedPrimary 886 $wand SetRedPrimary 100 50 887 $wand GetRedPrimary 888 889 magick delete $wand 890} 891proc GetSetRendering {img} { 892 set wand [$img clone imgX] 893 debug $wand 894 895 $wand GetRendering 896 $wand SetRendering "perceptual" 897 $wand GetRendering 898 899 magick delete $wand 900} 901proc GetSetResolution {img} { 902 set wand [$img clone imgX] 903 debug $wand 904 905 $wand GetResolution 906 $wand SetResolution 360 720 907 $wand GetResolution 908 909 magick delete $wand 910} 911proc GetSetScene {seq} { 912 set wand [$seq clone seqX] 913 debug $wand 914 915 $wand GetScene 916 $wand SetScene 3 917 $wand GetScene 918 919 magick delete $wand 920} 921proc GetImageSize {img} { 922 $img GetImageSize 923} 924proc GetSignature {img} { 925 $img GetSignature 926} 927proc GetSetImageType {seq} { 928 set wand [$seq clone seqX] 929 debug $wand 930 931 $wand GetImageType 932 $wand SetImageType grayscale 933 $wand GetImageType 934 935 magick delete $wand 936} 937proc GetSetImageUnits {seq} { 938 set wand [$seq clone seqX] 939 debug $wand 940 941 $wand GetImageUnits 942 $wand SetImageUnits "ppcm" 943 $wand GetImageUnits 944 945 magick delete $wand 946} 947proc GetSetVirtualPixelMethod {seq} { 948 set wand [$seq clone seqX] 949 debug $wand 950 951 $wand GetVirtualPixelMethod 952 $wand SetVirtualPixelMethod "mirror" 953 $wand GetVirtualPixelMethod 954 $wand SetVirtualPixelMethod "undefined" 955 956 magick delete $wand 957} 958proc GetWidth {img} { 959 $img GetWidth 960} 961proc GetNumberImages {seq} { 962 $seq GetNumberImages 963} 964proc GetSetSamplingFactors {img} { 965 set wand [$img clone imgX] 966 debug $wand 967 968 $wand GetSamplingFactors 969 $wand SetSamplingFactors {1 2 3 4 5} 970 $wand GetSamplingFactors 971 972 magick delete $wand 973} 974proc GetSetSize {img} { 975 set wand [$img clone imgX] 976 debug $wand 977 978 $img GetSize 979 $wand size 100 200 980 $wand size 981 $wand SetSize 300 400 982 $wand GetSize 983 984 magick delete $wand 985} 986proc GetSetWhitePoint {img} { 987 set wand [$img clone imgX] 988 debug $wand 989 990 $wand GetWhitePoint 991 $wand SetWhitePoint 100 50 992 $wand GetWhitePoint 993 994 magick delete $wand 995} 996proc ImplodeImage {img} { 997 set wand [$img clone imgX] 998 debug $wand 999 $wand ImplodeImage 1.0 1000 $wand WriteImage "$::TMP/x-Implode.jpg" 1001 magick delete $wand 1002} 1003proc LabelImage {img} { 1004 set wand [$img clone imgX] 1005 debug $wand 1006 $wand LabelImage "This is my label" 1007 $wand WriteImage "$::TMP/x-Label.jpg" 1008 magick delete $wand 1009} 1010proc LevelImage {img} { 1011 set wand [$img clone imgX] 1012 debug $wand 1013 $wand LevelImage 10000 2.0 50000 1014 $wand WriteImage "$::TMP/x-Level.jpg" 1015 magick delete $wand 1016} 1017proc LevelImageChannel {img} { 1018 set wand [$img clone imgX] 1019 debug $wand 1020 $wand LevelImageChannel blue 10000 2.0 50000 1021 $wand WriteImage "$::TMP/x-LevelChannel.jpg" 1022 magick delete $wand 1023} 1024proc MagnifyImage {img} { 1025 set wand [$img clone imgX] 1026 debug $wand 1027 $wand MagnifyImage 1028 $wand WriteImage "$::TMP/x-Magnify.jpg" 1029 magick delete $wand 1030} 1031proc MapImage {img} { 1032 set wand [$img clone imgX] 1033 set map [magick create wand] 1034 debug $wand $map 1035 1036 $map ReadImage $::MAP 1037 $wand MapImage $map 1038 $wand WriteImage "$::TMP/x-Map.jpg" 1039 magick delete $wand $map 1040} 1041proc MatteFloodfillImage {img} { 1042 set wand [$img clone imgX] 1043 set pix [magick create pixel] 1044 debug $wand $pix 1045 1046 $pix color rgb(50%,50%,50%) 1047# $pix set red 0.5 green 0.5 blue 0.5 1048 $pix GetColor 1049 $wand MatteFloodfillImage 30000 10.0 $pix 1050 $wand WriteImage "$::TMP/x-MatteFlood.gif" 1051 magick delete $wand $pix 1052} 1053proc MedianFilterImage {img} { 1054 set wand [$img clone imgX] 1055 debug $wand 1056 $wand MedianFilterImage 3 1057 $wand WriteImage "$::TMP/x-Median.jpg" 1058 magick delete $wand 1059} 1060proc MinifyImage {img} { 1061 set wand [$img clone imgX] 1062 debug $wand 1063 $wand MinifyImage 1064 $wand WriteImage "$::TMP/x-Minify.jpg" 1065 magick delete $wand 1066} 1067proc ModulateImage {img} { 1068 set wand [$img clone imgX] 1069 debug $wand 1070 $wand ModulateImage +90 +50 -30 1071 $wand WriteImage "$::TMP/x-Modulate.jpg" 1072 magick delete $wand 1073} 1074proc MontageImage {seq} { 1075 set wand [$seq clone seqX] 1076 set draw [magick create drawing drawX] 1077 debug $wand $draw 1078 1079 set x [$wand MontageImage $draw "40x40" "400x400" frame "4x4" imgX] 1080 $x WriteImage "$::TMP/x-Montage.jpg" 1081 1082 magick delete $wand $draw $x 1083} 1084proc MorphImages {seq} { 1085 $seq GetNumberImages 1086 set wand [$seq MorphImages 5 seqY] 1087 debug $wand 1088 $wand GetNumberImages 1089 $wand WriteImages "$::TMP/x-Morph.gif" 1 1090 magick delete $wand 1091} 1092proc MosaicImages {seq} { 1093 set wand [$seq MosaicImages imgX] 1094 debug $wand 1095 $wand WriteImage "$::TMP/x-Mosaic.gif" 1096 magick delete $wand 1097} 1098proc MotionBlurImage {img} { 1099 set wand [$img clone imgX] 1100 debug $wand 1101 $wand MotionBlurImage 0 5 45 1102 $wand WriteImage "$::TMP/x-MotionBlur.jpg" 1103 magick delete $wand 1104} 1105proc NegateImage {img} { 1106 set wand [$img clone imgX] 1107 debug $wand 1108 $wand NegateImage no 1109 $wand WriteImage "$::TMP/x-Negate.jpg" 1110 magick delete $wand 1111} 1112proc NormalizeImage {img} { 1113 set wand [$img clone imgX] 1114 debug $wand 1115 $wand NormalizeImage 1116 $wand WriteImage "$::TMP/x-Normalize.jpg" 1117 magick delete $wand 1118} 1119proc NextPrevious {seq} { 1120 set wand [$seq clone seqX] 1121 debug $wand 1122 1123 set max [$wand GetNumberImages] 1124 for {set i 0} {$i < $max} {incr i} { 1125 $wand SetIndex $i 1126 $wand HasPrevious 1127 $wand HasNext 1128 } 1129 $wand ResetIterator 1130 $wand GetIndex 1131 1132 magick delete $wand 1133} 1134proc OilPaintImage {img} { 1135 set wand [$img clone imgX] 1136 debug $wand 1137 $wand OilPaintImage 3 1138 $wand WriteImage "$::TMP/x-OilPaint.jpg" 1139 magick delete $wand 1140} 1141proc OpaqueImage {img} { 1142 set wand [$img clone imgX] 1143 set pix1 [magick create pixel pix1] 1144 set pix2 [magick create pixel pix2] 1145 debug $wand $pix1 $pix2 1146 1147 $pix1 color rgb(100%,100%,100%) 1148 $pix2 color rgb(0,100%,100%) 1149 $wand OpaqueImage $pix1 $pix2 10 1150 $wand WriteImage "$::TMP/x-Opaque.jpg" 1151 1152 magick delete $wand $pix1 $pix2 1153} 1154proc PingImage {filename} { 1155 set wand [magick create wand imgX] 1156 debug $wand 1157 1158 $wand PingImage $filename 1159 $wand GetFormat 1160 $wand GetHeight 1161 $wand GetWidth 1162 $wand GetImageSize 1163 1164 magick delete $wand 1165} 1166proc PreviewImages {img} { 1167 set wand [$img PreviewImages grayscale imgX] 1168 debug $wand 1169 $wand GetNumberImages 1170 $wand WriteImage "$::TMP/x-Preview.jpg" 1171 magick delete $wand 1172} 1173proc QueryFontMetrics {img} { 1174 set draw [magick create draw drawX] 1175 debug $draw 1176 $img QueryFontMetrics $draw "Hello world" 1177 magick delete $draw 1178} 1179proc QuantizeImage {img} { 1180 set wand [$img clone imgX] 1181 debug $wand 1182 $wand QuantizeImage 10 GRAY 1 no no 1183 $wand WriteImage "$::TMP/x-Quantize.jpg" 1184 magick delete $wand 1185} 1186proc RaiseImage {img} { 1187 set wand [$img clone imgX] 1188 debug $wand 1189 $wand RaiseImage 100 100 100 100 yes 1190 $wand WriteImage "$::TMP/x-Raise.jpg" 1191 magick delete $wand 1192} 1193proc ReadImageBlob {filename} { 1194 set wand [magick create wand imgX] 1195 debug $wand 1196 1197 set f [open $filename r] 1198 fconfigure $f -translation binary 1199 set data [read $f] 1200 close $f 1201 1202 $wand ReadImageBlob $data 1203 $wand GetNumberImages 1204 1205 magick delete $wand 1206} 1207proc ReduceNoiseImage {img} { 1208 set wand [$img clone imgX] 1209 debug $wand 1210 $wand AddNoise impulse 1211 $wand ReduceNoiseImage 1 1212 $wand WriteImage "$::TMP/x-ReduceNoise.jpg" 1213 magick delete $wand 1214} 1215proc RemoveImage {seq} { 1216 set wand [$seq clone seqX] 1217 debug $wand 1218 1219 $wand GetNumberImages 1220 $wand SetIndex 1 1221 while {[$wand HasNext]} { 1222 $wand RemoveImage 1223 } 1224 $wand GetNumberImages 1225 $wand WriteImages "$::TMP/x-Remove.gif" 1 1226 1227 magick delete $wand 1228} 1229proc ResampleImage {img} { 1230 set wand [$img clone imgX] 1231 debug $wand 1232 $wand ResampleImage 150 150 triangle 2.0 1233 $wand WriteImage "$::TMP/x-Resample.jpg" 1234 magick delete $wand 1235} 1236proc ResizeImage {img} { 1237 set wand [$img clone imgX] 1238 debug $wand 1239 1240 $wand ResizeImage 100 200 triangle 1241 $wand WriteImage "$::TMP/x-Resize.jpg" 1242 magick delete $wand 1243} 1244proc RollImage {img} { 1245 set wand [$img clone imgX] 1246 debug $wand 1247 $wand TrimImage 1248 $wand RollImage -60 -30 1249 $wand WriteImage "$::TMP/x-Roll.jpg" 1250 magick delete $wand 1251} 1252proc RotateImage {img} { 1253 set wand [$img clone imgX] 1254 set bg [magick create pixel] 1255 debug $wand $bg 1256 1257 $bg color rgb(50%,50%,50%) 1258 $wand RotateImage $bg -45 1259 $wand WriteImage "$::TMP/x-Rotate.jpg" 1260 1261 magick delete $wand $bg 1262} 1263proc SampleImage {img} { 1264 set wand [$img clone imgX] 1265 debug $wand 1266 $wand SampleImage 200 300 1267 $wand WriteImage "$::TMP/x-Sample.jpg" 1268 magick delete $wand 1269} 1270proc ScaleImage {img} { 1271 set wand [$img clone imgX] 1272 debug $wand 1273 $wand ScaleImage 300 200 1274 $wand WriteImage "$::TMP/x-Scale.jpg" 1275 magick delete $wand 1276} 1277proc SeparateImageChannel {img} { 1278 # Test RGB space 1279 foreach chan {red green blue} { 1280 set wand [$img clone imgX] 1281 debug $wand 1282 $wand SeparateImageChannel $chan 1283 $wand WriteImage "$::TMP/x-Separate-$chan.jpg" 1284 magick delete $wand 1285 } 1286 # Test CMYK space 1287 foreach chan {cyan magenta yellow black} { 1288 set wand [$img clone imgX] 1289 $wand SetColorspace "CMYK" 1290 debug $wand 1291 $wand SeparateImageChannel $chan 1292 $wand WriteImage "$::TMP/x-Separate-$chan.jpg" 1293 magick delete $wand 1294 } 1295} 1296proc SetOption {img} { 1297 set wand [$img clone imgX] 1298 debug $wand 1299 $wand SetOption "jpeg" "perserve" "yes" 1300 $wand WriteImage "$::TMP/x-SetOption.jpg" 1301 magick delete $wand 1302} 1303proc SetPassphrase {img} { 1304 set wand [$img clone imgX] 1305 debug $wand 1306 $wand SetPassphrase "foo" 1307 $wand WriteImage "$::TMP/x-Passphrase.jpg" 1308 magick delete $wand 1309} 1310proc SharpenImage {img} { 1311 set wand [$img clone imgX] 1312 debug $wand 1313 $wand SharpenImage 4.0 2.0 1314 $wand WriteImage "$::TMP/x-Sharpen.jpg" 1315 magick delete $wand 1316} 1317proc ShaveImage {img} { 1318 set wand [$img clone imgX] 1319 debug $wand 1320 $wand ShaveImage 50 30 1321 $wand WriteImage "$::TMP/x-Shave.jpg" 1322 magick delete $wand 1323} 1324proc ShearImage {img} { 1325 set wand [$img clone imgX] 1326 set pix [magick create pixel pix1] 1327 debug $wand $pix 1328 1329 $pix color rgb(50%,50%,50%) 1330 $wand ShearImage $pix 30 20 1331 $wand WriteImage "$::TMP/x-Shear.jpg" 1332 magick delete $wand $pix 1333} 1334proc SolarizeImage {img} { 1335 set wand [$img clone imgX] 1336 debug $wand 1337 $wand SolarizeImage 10 1338 $wand WriteImage "$::TMP/x-Solarize.jpg" 1339 magick delete $wand 1340} 1341proc SpreadImage {img} { 1342 set wand [$img clone imgX] 1343 debug $wand 1344 $wand SpreadImage 3 1345 $wand WriteImage "$::TMP/x-Spread.jpg" 1346 magick delete $wand 1347} 1348proc SteganoImage {img} { 1349 set wand [$img clone imgX] 1350 set water [$img clone imgY] 1351 debug $wand $water 1352 1353 $water resize 50 50 1354 set new [$wand SteganoImage $water] 1355 $new WriteImage "$::TMP/x-Stegano.jpg" 1356 1357 magick delete $wand $water $new 1358} 1359proc StereoImage {img} { 1360 set wand [$img clone imgX] 1361 set another [$img clone imgY] 1362 debug $wand $another 1363 1364 $another RollImage 5 5 1365 set new [$wand StereoImage $another] 1366 $new WriteImage "$::TMP/x-Stereo.jpg" 1367 1368 magick delete $wand $another $new 1369} 1370proc StripImage {img} { 1371 set wand [$img clone imgX] 1372 debug $wand 1373 $wand StripImage 1374 set txt [$wand DescribeImage] 1375 $wand WriteImage "$::TMP/x-Strip.jpg" 1376 magick delete $wand 1377} 1378proc SwirlImage {img} { 1379 set wand [$img clone imgX] 1380 debug $wand 1381 $wand SwirlImage 45 1382 $wand WriteImage "$::TMP/x-Swirl.jpg" 1383 magick delete $wand 1384} 1385proc TextureImage {img} { 1386 set wand [$img clone imgX] 1387 set text [magick create wand] 1388 debug $wand $text 1389 1390 $text ReadImage "xc:gray" 1391 $text ResizeImage 500 500 1392 $wand ResizeImage 110 110 triangle 1393 1394 set new [$text TextureImage $wand] 1395 $new WriteImage "$::TMP/x-Texture.jpg" 1396 1397 magick delete $wand $text $new 1398} 1399proc ThresholdImage {img} { 1400 set wand [$img clone imgX] 1401 debug $wand 1402 $wand ThresholdImage 30000 1403 $wand WriteImage "$::TMP/x-Threshold.jpg" 1404 magick delete $wand 1405} 1406proc ThresholdImageChannel {img} { 1407 set wand [$img clone imgX] 1408 debug $wand 1409 $wand ThresholdImageChannel blue 3000 1410 $wand WriteImage "$::TMP/x-ThresholdChannel.jpg" 1411 magick delete $wand 1412} 1413proc TintImage {img} { 1414 set wand [$img clone imgX] 1415 set pix1 [magick create pixel pix1] 1416 set pix2 [magick create pixel pix2] 1417 debug $wand $pix1 $pix2 1418 1419 $pix1 color "blue" 1420 $pix2 color "black" 1421 $wand TintImage $pix1 $pix2 1422 $wand WriteImage "$::TMP/x-Tint.jpg" 1423 1424 magick delete $wand $pix1 $pix2 1425} 1426proc TransformImage {img} { 1427 set wand [$img TransformImage "200x300+250+100" "600x600"] 1428 debug $wand 1429 $wand WriteImage "$::TMP/x-Transform.gif" 1430 magick delete $wand 1431} 1432proc TransparentImage {img} { 1433 set wand [$img clone imgX] 1434 set pix [magick create pixel] 1435 debug $wand $pix 1436 1437 $pix color "blue" 1438 $wand TransparentImage $pix 40000 100 1439 $wand WriteImage "$::TMP/x-Transparent.gif" 1440 1441 magick delete $wand $pix 1442} 1443proc TrimImage {img} { 1444 set wand [$img clone imgX] 1445 debug $wand 1446 $wand TrimImage 10 1447 $wand WriteImage "$::TMP/x-Trim.jpg" 1448 magick delete $wand 1449} 1450proc UnsharpMaskImage {img} { 1451 set wand [$img clone imgX] 1452 debug $wand 1453 $wand UnsharpMaskImage 0 3 50 10 1454 $wand WriteImage "$::TMP/x-Unsharp.jpg" 1455 magick delete $wand 1456} 1457proc WaveImage {img} { 1458 set wand [$img clone imgX] 1459 debug $wand 1460 $wand WaveImage 4 10 1461 $wand WriteImage "$::TMP/x-Wave.jpg" 1462 magick delete $wand 1463} 1464proc WhiteThresholdImage {img} { 1465 set wand [$img clone imgX] 1466 set pix [magick create pixel] 1467 debug $wand $pix 1468 1469 $pix color "white" 1470 $wand WhiteThresholdImage $pix 1471 $wand WriteImage "$::TMP/x-WhiteThreshold.jpg" 1472 1473 magick delete $wand $pix 1474} 1475 1476########################################## 1477# Prepare tests 1478# 1479 1480if {! [file isdirectory $::TMP] } { 1481 file mkdir $::TMP 1482} 1483debug magick 1484 1485magick fonts 1486magick formats 1487 1488set img [magick create wand img0] 1489set seq [magick create wand img1] 1490debug $img $seq 1491 1492$img ReadImage $IMG 1493$img WriteImage "$::TMP/x-0.jpg" 1494 1495$seq ReadImage $SEQ 1496magick names 1497 1498 1499########################################## 1500# Main test loop 1501# 1502 1503set ERRORS 0 1504set TESTED 0 1505set SKIPPED 0 1506 1507foreach {func var flag} $TestFunctions { 1508 if {$flag} { 1509 incr TESTED 1510 puts [format "%s:" $func $var] 1511 set num1 [llength [magick names]] 1512 1513 set err [catch {$func [set $var]} result] 1514 if {$err} { 1515 incr ERRORS 1516 puts stderr $result 1517 } 1518 # Check for unfree'd resources 1519 # 1520 set num2 [llength [magick names]] 1521 if {! $err && ($num2 > $num1)} { 1522 puts stderr "Check resources (magick names) !!!" 1523 set err 1 1524 } 1525 if {$err} { 1526 update ; after 5000 1527 } 1528 } else { 1529 incr SKIPPED 1530 } 1531} 1532 1533puts "*********** READY **************" 1534if {$SKIPPED} { 1535 puts [format "tested=%d errors=%d skipped=%d" $TESTED $ERRORS $SKIPPED] 1536} 1537if {!$ERRORS} { 1538# after 3000 exit 1539} 1540