#
# transparency.test --
#
#    Unit tests for transparency.c
#
# Copyright (c) 2016-2017 by Simon Bachmann <simonbachmann@bluewin.ch>
# All rights reserved.
#
# Permission is hereby granted, without written agreement and without
# license or royalty fees, to use, copy, modify, and distribute this
# software and its documentation for any purpose, provided that the
# above copyright notice and the following two paragraphs appear in
# all copies of this software.
# 

package require tcltest 2.3

eval ::tcltest::configure $argv

#source [file join [::tcltest::workingDirectory] utils.tcl]

namespace eval ::imgtools::test::transparency {
    namespace import ::tcltest::*
    namespace import ::imgtools::test::*
    #testConstraint X [expr {...}]
    variable setup {
        set smiley [file join [file normalize [workingDirectory]] smiley.png]
        set blue [file join [file normalize [workingDirectory]] blue.png]
        set red [file join [file normalize [workingDirectory]] red.png]
        set rot0 [file join [file normalize [workingDirectory]] drawing.png]
        set maskHorizF [file join [file normalize [workingDirectory]] maskHoriz.png]
        set maskVertF [file join [file normalize [workingDirectory]] maskVert.png]
        set photo [file join [file normalize [workingDirectory]] photo.png]
        image create photo smiley -file $smiley         ;#15x15
        image create photo emptyImg
        image create photo emptyImg2
        image create photo emptyImg3
        image create photo destImg
        image create photo blueImg -file $blue
        image create photo redImg -file $red
        image create photo rotated0 -file $rot0         ;#39x22
        image create photo maskHoriz -file $maskHorizF
        image create photo maskVert -file $maskVertF
        image create photo photo -file $photo           ;#100x75
    }
    variable cleanup {
        image delete smiley
        image delete destImg
        image delete emptyImg emptyImg2 emptyImg3
        image delete blueImg redImg
        image delete rotated0 
        image delete maskHoriz maskVert
        image delete photo
    }
    
    #
    # ### Imgtools_Transparency
    #
    test transparency-1.1 {No subcommand} -setup $setup -body {
        ::imgtools::transparency
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* subcommand ?options?"}
    
    test transparency-1.2 {Unknown subcommand} -setup $setup -body {
        ::imgtools::transparency invalid
    } -cleanup $cleanup -returnCodes error -match glob -result {bad subcommand "invalid": must be *}
    
    #
    # ### Imgtools_TransparencyModify
    #
    
    #
    # Options and arguments
    #
    # the list of allowed options is used quite often in results. Keep it in 
    # one central place to simplify modifications
    set allowedOpts "-compositingrule, -shrink, -from*-to*"
    test modify-1.1 {Too few arguments} -setup $setup -body {
        ::imgtools::transparency decrease smiley 1
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* decrease sourceImg alphaValue ?options? destImg"}
    
    test modify-1.2 {source image does not exist} -setup $setup -body {
        ::imgtools::transparency increase invalid 1 destImg
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test modify-1.3 {dest image does not exist} -setup $setup -body {
        ::imgtools::transparency set smiley 1 invalid
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test modify-1.4 {invalid alphaVal} -setup $setup -body {
        ::imgtools::transparency decrease smiley invalid destImg
    } -cleanup $cleanup -returnCodes error -result {expected floating-point number but got "invalid"}
    
    test modify-1.5 {existing, but not accepted common opt: -alpha} -setup $setup -body {
        ::imgtools::transparency increase smiley 30% -alpha 1 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-alpha\": must be $allowedOpts"
    
    test modify-1.6 {existing, but not accepted common opt: -background} -setup $setup -body {
        ::imgtools::transparency increase smiley 30% -background blue destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-background\": must be $allowedOpts"
    
    test modify-1.6.1 {existing, but not accepted common opt: -clipping} -setup $setup -body {
        ::imgtools::transparency set rotated0 0.5 -clipping none destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-clipping\": must be $allowedOpts"
    
    test modify-1.7 {existing, but not accepted common opt: -interpolation} -setup $setup -body {
        ::imgtools::transparency increase smiley 30% -interpolation nearest destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-interpolation\": must be $allowedOpts"
    
    test modify-1.8 {existing, but not accepted common opt: -orient} -setup $setup -body {
        ::imgtools::transparency increase smiley 30% -orient horizontal destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-orient\": must be $allowedOpts"
    
    test modify-1.9 {not existing option} -setup $setup -body {
        ::imgtools::transparency set smiley 0% -invalid destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-invalid\": must be $allowedOpts"
    
    test modify-1.10 {accepted common opts} -setup $setup -body {
        ::imgtools::transparency decrease smiley 1 -compositingrule set -shrink -to 1 -from 4 destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # note: tests modify-1.11 thru modify-1.16 were deleted. They tested invalid values
    # for the -to option. The implementation of the option has changed since v0.3
    # so those tests no longer make sense. 
    # Also, the out-of-bound errors for -to / -from coordinates are checked in 
    # imgtools/getregion.
    #
    # To avoid confusion, use 1.17 as the number for the next test in this section
    #
    
    test modify-1.17 {-from coords must be within image I} -setup $setup -body {
        ::imgtools::transparency increase smiley 99% -from 2 -1 8 9 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-1\": must be $allowedOpts"
    
    test modify-1.18 {-from coords must be within image II} -setup $setup -body {
        ::imgtools::transparency set smiley 12.34% -from 0 1 17 14 destImg
    } -cleanup $cleanup -returnCodes error -result {coordinates extend outside image}
    
    test modify-1.19 {only two coords to -from, size} -setup $setup -body {
        ::imgtools::transparency decrease rotated0 .6 -from 5 6 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {34 16}
    
    #
    # functionality
    #
    test modify-2.1 {decrease functionality, alphaValue 0} -setup $setup -body {
        ::imgtools::transparency decrease rotated0 0 destImg
        set testVal1 [lindex [getPixel destImg 0 0] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 38 21] 3]
        expr {$testVal1 == 0 && $testVal2 == 166 && $testVal3 == 255}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.2 {decrease functionality, alphaValue 1} -setup $setup -body {
        ::imgtools::transparency decrease rotated0 1 destImg
        set testVal {}
        lappend testVal [lindex [getPixel destImg 38 0] 3]
        lappend testVal [lindex [getPixel destImg 30 15] 3]
        lappend testVal [lindex [getPixel destImg 0 21] 3]
        #expr {$testVal1 == 255 && $testVal2 == 255 && $testVal3 == 255}
    } -cleanup $cleanup -returnCodes ok -result {255 255 255}
    
    test modify-2.3 {decrease functionality, alphaValue 0.7} -setup $setup -body {
        ::imgtools::transparency decrease rotated0 0.7 destImg
        set testVal {}
        lappend testVal [lindex [getPixel destImg 0 0] 3]
        lappend testVal [lindex [getPixel destImg 30 15] 3]
        lappend testVal [lindex [getPixel destImg 38 21] 3]
        #expr {$testVal1 == 179 && $testVal2 == 228 && $testVal3 == 255}
    } -cleanup $cleanup -returnCodes ok -result {179 228 255}
    
    test modify-2.4 {increase functionality, alphaValue 0} -setup $setup -body {
        ::imgtools::transparency increase rotated0 0 destImg
        set testVal1 [lindex [getPixel destImg 38 0] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 0 21] 3]
        expr {$testVal1 == 0 && $testVal2 == 0 && $testVal3 == 0}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.5 {increase functionality, alphaValue 1} -setup $setup -body {
        ::imgtools::transparency increase rotated0 1 destImg
        set testVal1 [lindex [getPixel destImg 0 0] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 38 21] 3]
        expr {$testVal1 == 0 && $testVal2 == 166 && $testVal3 == 255}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.6 {increase functionality, alphaValue 0.7} -setup $setup -body {
        ::imgtools::transparency increase rotated0 0.7 destImg
        set testVal1 [lindex [getPixel destImg 38 0] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 0 21] 3]
        expr {$testVal1 == 0 && $testVal2 == 116 && $testVal3 == 179}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.7 {set functionality, alphaValue 0} -setup $setup -body {
        ::imgtools::transparency set rotated0 0 destImg
        set testVal1 [lindex [getPixel destImg 15 15] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 32 15] 3]
        expr {$testVal1 == 0 && $testVal2 == 0 && $testVal3 == 0}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.8 {set functionality, alphaValue 1} -setup $setup -body {
        ::imgtools::transparency set rotated0 1 destImg
        set testVal1 [lindex [getPixel destImg 15 15] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 32 15] 3]
        expr {$testVal1 == 255 && $testVal2 == 255 && $testVal3 == 255}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.9 {set functionality, alphaValue 0.7} -setup $setup -body {
        ::imgtools::transparency set rotated0 0.7 destImg
        set testVal1 [lindex [getPixel destImg 15 15] 3]
        set testVal2 [lindex [getPixel destImg 30 15] 3]
        set testVal3 [lindex [getPixel destImg 32 15] 3]
        expr {$testVal1 == 179 && $testVal2 == 179 && $testVal3 == 179}
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    #
    # The meaning of the -to option has changed for the transparency 
    # modify commands.
    # As a consequence, the tests modify-2.10 thru modify-2.14 have
    # become meaningless and would have failed.
    #
    # Deleted
    #
    
    test modify-2.15 {empty src image} -setup $setup -body {
        ::imgtools::transparency decrease emptyImg .4e-1 destImg
        compareImages emptyImg destImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-2.16 {Check that the source image is not affected} -setup $setup -body {
        emptyImg copy smiley
        ::imgtools::transparency set smiley .5 -compositingrule set destImg
        compareImages emptyImg smiley
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-3.1 {-to option, functionality} -setup $setup -body {
        ::imgtools::transparency set smiley 11% emptyImg
        ::imgtools::transparency set smiley 11% -to 2 5 35 44 destImg
        emptyImg2 copy emptyImg -to 2 5 35 44
        compareImages emptyImg2 destImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test modify-3.2 {-to option with only two coords, correct size} -setup $setup -body {
        ::imgtools::transparency increase smiley 12% -to 0 12 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {15 27}
    
    test modify-4.1 {correct return value} -setup $setup -body {
        ::imgtools::transparency increase emptyImg 1 smiley
    } -cleanup $cleanup -returnCodes ok -result {smiley}
    
    #
    # ### Imgtools_TransparencyGet
    #
    test get-1.1 {Too few arguments} -setup $setup -body {
        ::imgtools::transparency get blueImg 2
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* get sourceImg x y"}
    
    test get-1.2 {Too many arguments} -setup $setup -body {
        ::imgtools::transparency get redImg 1 2 3
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* get sourceImg x y"}
    
    test get-1.3 {source image does not exist} -setup $setup -body {
        ::imgtools::transparency get invalid 4 5
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test get-1.4 {invalid value for x} -setup $setup -body {
        ::imgtools::transparency get smiley invalid 4
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "invalid"}
    
    test get-1.5 {invalid value for y} -setup $setup -body {
        ::imgtools::transparency get rotated0 42 invalid
    } -cleanup $cleanup -returnCodes error -result {expected integer but got "invalid"}
    
    test get-1.6 {negative x} -setup $setup -body {
        ::imgtools::transparency get rotated0 -1 4
    } -cleanup $cleanup -returnCodes error -result {coordinates out of range}
    
    test get-1.7 {negative y} -setup $setup -body {
        ::imgtools::transparency get rotated0 4 -2
    } -cleanup $cleanup -returnCodes error -result {coordinates out of range}
    
    test get-1.8 {x too large} -setup $setup -body {
        ::imgtools::transparency get rotated0 39 4
    } -cleanup $cleanup -returnCodes error -result {coordinates out of range}
    
    test get-1.9 {y too large} -setup $setup -body {
        ::imgtools::transparency get rotated0 5 22
    } -cleanup $cleanup -returnCodes error -result {coordinates out of range}
    
    test get-1.10 {empty source image} -setup $setup -body {
        ::imgtools::transparency get emptyImg 0 0
    } -cleanup $cleanup -returnCodes error -result {coordinates out of range}
    
    #
    # Functionality - test a few known pixels
    #
    test get-2.1 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get smiley 4 6]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {197}
    
    test get-2.2 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get smiley 13 7]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {253}
    
    test get-2.3 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get smiley 6 10]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {255}
    
    test get-2.4 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get rotated0 0 0]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {0}
    
    test get-2.5 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get rotated0 29 16]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {166}
    
    test get-2.6 {test result} -setup $setup -body {
        set alpha [::imgtools::transparency get rotated0 38 21]
        expr {round($alpha * 255)}
    } -cleanup $cleanup -returnCodes ok -result {255}
    
    #
    # ### Imgtools_TransparencyMask
    #
    
    #
    # options and args
    #
    
    set allowedOpts "-compositingrule, -shrink, -from*-to*"
    test mask-1.1 {Too few arguments} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0
    } -cleanup $cleanup -returnCodes error -match glob -result {wrong # args: should be "* mask sourceImage maskImage ?options? destImage"}
    
    test mask-1.2 {source image does not exist} -setup $setup -body {
        ::imgtools::transparency mask invalid smiley destImg
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test mask-1.3 {mask image does not exist} -setup $setup -body {
        ::imgtools::transparency mask smiley invalid destImg
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test mask-1.4 {destination image does not exist} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley invalid
    } -cleanup $cleanup -returnCodes error -result {image "invalid" not found}
    
    test mask-1.5 {mask image is empty} -setup $setup -body {
        ::imgtools::transparency mask smiley emptyImg destImg
    } -cleanup $cleanup -returnCodes error -result {mask image is empty}
    
    test mask-1.6 {existing, but not accepted common opt: -alpha} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 -alpha 1 destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-alpha\": must be $allowedOpts"
    
    test mask-1.7 {existing, but not accepted common opt: -background} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley -background blue destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-background\": must be $allowedOpts"
    
    # test mask-1.7.1 deleted. -from is now supported
    
    test mask-1.8 {existing, but not accepted common opt: -interpolation} -setup $setup -body {
        ::imgtools::transparency mask smiley emptyImg -interpolation nearest destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-interpolation\": must be $allowedOpts"
    
    test mask-1.9 {existing, but not accepted common opt: -orient} -setup $setup -body {
        ::imgtools::transparency mask emptyImg smiley -orient horizontal destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-orient\": must be $allowedOpts"
    
    # test mask-1.10 deleted. -to is now supported
    
    test mask-1.13 {existing, but not accepted opt: -clipping} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley -clipping keepsize destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-clipping\": must be $allowedOpts"
    
    test mask-1.11 {not existing option} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 -invalid destImg
    } -cleanup $cleanup -returnCodes error -match glob -result "bad option \"-invalid\": must be $allowedOpts"
    
    test mask-1.12 {accepted common opts} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 -compositingrule set -shrink -from 2 3 11 10 -to 2  destImg
    } -cleanup $cleanup -returnCodes ok -result {destImg}
    
    #
    # functionality
    #
    test mask-2.1 {equal sized images, mask is fully opaque #1} -setup $setup -body {
        ::imgtools::transparency mask smiley blueImg destImg
        getPixel destImg 1 1
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 255}
    
    test mask-2.2 {equal sized images, mask is fully opaque #2} -setup $setup -body {
        ::imgtools::transparency mask smiley blueImg destImg
        getPixel destImg 4 3
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 255}
    
    test mask-2.3 {equal sized images, mask is fully opaque #3} -setup $setup -body {
        ::imgtools::transparency mask smiley blueImg destImg
        getPixel destImg 5 7 
    } -cleanup $cleanup -returnCodes ok -result {255 255 0 255}
    
    test mask-2.4 {mask is larger than srcImg #1} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 destImg
        getPixel destImg 7 7
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 255}
    
    test mask-2.5 {mask is larger than srcImg #2} -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 destImg
        #only test alpha value because with alpha = 0 color values are meaningless
        lindex [getPixel destImg 0 0] 3
    } -cleanup $cleanup -returnCodes ok -result {0}
    
    test mask-2.6 {mask is smaller than srcImg #1} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley destImg
        getPixel destImg 14 11
    } -cleanup $cleanup -returnCodes ok -result {9 118 0 115}
    
    test mask-2.7 {mask is smaller than srcImg #2} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley destImg
        getPixel destImg 15 11
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 115}
    
    test mask-2.8 {mask is smaller than srcImg #3} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley destImg
        getPixel destImg 24 16
    } -cleanup $cleanup -returnCodes ok -result {60 50 113 209}
    
    test mask-2.9 {mask is smaller than srcImg #4} -setup $setup -body {
        ::imgtools::transparency mask rotated0 smiley destImg
        getPixel destImg 24 17
    } -cleanup $cleanup -returnCodes ok -result {60 50 113 255}
    
    test mask-2.10 {mask width is larger, height smaller than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskHoriz destImg
        getPixel destImg 14 7
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 166}
    
    test mask-2.11 {mask width is larger, height smaller than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskHoriz destImg
        getPixel destImg 5 11
    } -cleanup $cleanup -returnCodes ok -result {117 117 0 255}
    
    test mask-2.12 {mask width is larger, height smaller than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskHoriz destImg
        getPixel destImg 5 12
    } -cleanup $cleanup -returnCodes ok -result {0 0 0 68}
    
    test mask-2.13 {mask width is larger, height smaller than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskHoriz destImg
        getPixel destImg 14 14
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 68}
    
    test mask-2.14 {mask width is smaller, height larger than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskVert destImg
        getPixel destImg 0 0 
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 255}
    
    test mask-2.15 {mask width is smaller, height larger than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskVert destImg
        getPixel destImg 14 10 
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 232}
    
    test mask-2.16 {mask width is smaller, height larger than src} -setup $setup -body {
        ::imgtools::transparency mask smiley maskVert destImg
        getPixel destImg 7 14
    } -cleanup $cleanup -returnCodes ok -result {255 255 255 166}
    
    test mask-2.17 {srcImage is not affected} -setup $setup -body {
        emptyImg copy rotated0
        ::imgtools::transparency mask rotated0 maskVert destImg
        compareImages emptyImg rotated0
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test mask-2.18 {use same image for src and mask: result shoud be equal source} -setup $setup -body {
        ::imgtools::transparency mask smiley smiley destImg
        compareImages smiley destImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test mask-2.19 {-from / ApplySubregion works} -setup $setup -body {
        emptyImg copy rotated0 -from 0 5 20 22
        ::imgtools::transparency mask emptyImg smiley emptyImg2
        ::imgtools::transparency mask rotated0 smiley -from 0 22 20 5 destImg
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test mask-2.20 {-to functionality } -setup $setup -body {
        ::imgtools::transparency mask smiley rotated0 emptyImg
        ::imgtools::transparency mask smiley rotated0 -to 100 99 2 3 destImg
        emptyImg2 copy emptyImg -to 100 99 2 3
        compareImages destImg emptyImg2
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test mask-2.21 {empty source image} -setup $setup -body {
        ::imgtools::transparency mask emptyImg smiley destImg
        compareImages destImg emptyImg
    } -cleanup $cleanup -returnCodes ok -result {1}
    
    test mask-2.22 {-from with only two coords, size} -setup $setup -body {
        ::imgtools::transparency mask photo smiley -from 80 70 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {20 5}
    
    test mask-2.23 {-to with only two coords, size} -setup $setup -body {
        ::imgtools::transparency mask photo smiley -to 11 0 destImg
        list [image width destImg] [image height destImg]
    } -cleanup $cleanup -returnCodes ok -result {111 75}
    
    test mask-2.24 {result} -setup $setup -body {
        ::imgtools::transparency mask photo rotated0 emptyImg3
    } -cleanup $cleanup -returnCodes ok -result {emptyImg3}
    
    
    cleanupTests
}
namespace delete ::imgtools::test::transparency
