# Test displaying 32-bit float images using the pawt and the Img package.
# Note, that the Img extension has no parser for the FITS file format.
#
# Copyright: 2021-2024 Paul Obermeier (obermeier@poSoft.de)
# Distributed under BSD license.

if { [file exists "TestUtils.tcl"] } {
    source "TestUtils.tcl"
}

package require pawt

if { ! [pawt::HavePkg "Img"] } {
    puts "Error: pawt test suite needs the Img extension."
    exit 1
}

package require Img
# The following special formats are not loaded by the general Img package.
package require img::raw
package require img::flir

if { ! [file isdirectory "testOut"] } {
    file mkdir "testOut"
}

set testCase "04_PhotoTkimg-float"

set inFileList [lsort -dictionary [glob -nocomplain "testOut/03_Convert-float*.*"]]
if { [llength $inFileList] == 0 } {
    puts "Test 03_Convert-float.tcl must have been executed to create needed test images."
    exit 1
}

set count  0
set winNum 1
foreach inFilePath $inFileList {
    set inFileName [file tail $inFilePath]
    puts "Reading file $inFilePath ..."
    set imgDict [pawt ReadImageFile $inFilePath]
    set photoGrey [pawt GetImageAsPhoto imgDict]

    set retVal [catch { image create photo -file $inFilePath } photoImg]
    if { $retVal == 0 } {
        pawtTest AddImgPhotos $photoGrey "pawt: $inFileName" \
                              $photoImg  "Img: $inFileName" \
                              -title "$testCase Part $winNum" -zoom 50 -window $winNum
    } else {
        set photoUnsupported [pawtTest CreatePhotoUnsupported [pawt GetImageWidth imgDict] [pawt GetImageHeight imgDict]]
        pawtTest AddImgPhotos $photoGrey "pawt: $inFileName" $photoUnsupported "Img: $photoImg" \
                              -title "$testCase Part $winNum" -zoom 50 -window $winNum
    }
    incr count
    if { $count % 4 == 0 } {
        incr winNum
        puts ""
    }
}

if { [lindex $argv 0] eq "auto" } {
    update
    after 500
    exit 0
}
