namespace eval shelliconTest {

    variable ns [namespace current]

    # Utility procs.
    namespace export getPhotoSize
    namespace export isValidPhoto
    namespace export arePhotosIdent

    proc getPhotoSize { phImg } {
        return [list [image width $phImg] [image height $phImg]]
    }

    proc isValidPhoto { phImg } {
        if { [lsearch -exact [image names] $phImg] >= 0 && \
             [image width  $phImg] > 0 && \
             [image height $phImg] > 0 } {
            return true
        }
        return false
    }

    proc arePhotosIdent { phImg1 phImg2 } {
        set w1 [image width  $phImg1]
        set h1 [image height $phImg1]
        set w2 [image width  $phImg2]
        set h2 [image height $phImg2]
        if { $w1 != $w2 && $h1 != $h2 } {
            return false
        }
        for { set y 0 } { $y < $h1 } { incr y } {
            for { set x 0 } { $x < $w1 } { incr x } {
                set left  [$phImg1 get $x $y]
                set right [$phImg2 get $x $y]

                set dr [expr { [lindex $right 0] - [lindex $left 0] }]
                if { $dr != 0 } { return false }

                set dg [expr { [lindex $right 1] - [lindex $left 1] }]
                if { $dg != 0 } { return false }

                set db [expr { [lindex $right 2] - [lindex $left 2] }]
                if { $db != 0 } { return false }
            }
        }
        return true
    }
}

namespace import -force shelliconTest::*
