source pkgsNeeded.tcl

ui_init "t_photo.tcl"
SetFileTypes

PH "Functions to copy between poImages and photo images"

set swatch [poImgUtil NewSwatch]

set srcImg [poImage NewImageFromFile "testIn/Colorbar.tga"]
$srcImg GetImgInfo sw sh a g
CheckNumber 512 $sw "Source image width"  false
CheckNumber 512 $sh "Source image height" false

set sizeList { 1000 2000 5000 10000 }
foreach size $sizeList {
    set phImg  [image create photo -width $size -height $size]

    set poImg1 [poImgUtil ScaleImg $srcImg $size $size]
    $poImg1 GetImgInfo nw nh a g
    CheckNumber $size $nw "Scaled image width"  false
    CheckNumber $size $nh "Scaled image height" false

    $swatch reset
    $poImg1 AsPhoto $phImg
    set tImg2Photo [$swatch lookup]
    P [format "poImg -> photo (%5d x %5d pixels): %.4f seconds" $size $size $tImg2Photo]

    $swatch reset
    set poImg2 [poImage NewImageFromPhoto $phImg]
    set tPhoto2Img [$swatch lookup]
    P [format "photo -> poImg (%5d x %5d pixels): %.4f seconds" $size $size $tPhoto2Img]

    image delete $phImg

    set diffImg [poImgUtil DifferenceImage $poImg1 $poImg2]

    poImgUtil DeleteImg $poImg1
    poImgUtil DeleteImg $poImg2

    set markImg [poImage NewImage $size $size $a $g]
    $markImg MarkNonZeroPixels $diffImg 0 numMarked
    CheckNumber 0 $numMarked "Differing pixels" false

    poImgUtil DeleteImg $diffImg
    poImgUtil DeleteImg $markImg
}

poImgUtil DeleteImg $srcImg
poImgUtil DeleteSwatch $swatch

PS
P "End of test"

ui_show

if { [lindex $argv 0] eq "auto" } {
    ui_exit
    exit 0
}
