# Test handling 16-bit FLIR FPF images using the pawt package.
#
# Note, that the FLIR format has the following restrictions:
#   NumChan   is always 1.
#   ByteOrder is always "Intel".
#   ScanOrder is always "TopDown".
#   PixelType is "short" or "float".
#
# Copyright: 2021-2023 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
}

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

set testCase "02_Format-Flir-short"

puts "\nCreate 1-channel short image"
set imgDict [pawt CreateImage -width 6 -height 2 -pixeltype "short" -numchan 1 -list [pawtTest GetGreyListTD-short]]

set outFilePath [file join "testOut" [format "%s_1chan.fpf" $testCase]]
puts "Write  1-channel short image [file tail $outFilePath]"
pawt::flir::WriteImageFile $imgDict $outFilePath

puts "Read   1-channel short image [file tail $outFilePath]"
set flirDict1 [pawt::flir::ReadImageFile $outFilePath]
set flirImgAsList [pawt GetImageAsList flirDict1 -scanorder "TopDown"]
pawtTest CheckList [pawtTest GetGreyListTD-short] $flirImgAsList "Check input vs. FLIR"
pawtTest AddImgDicts $imgDict "In: 1-channel short"  $flirDict1 "Out: 1-channel short"  -zoom 50 -title $testCase

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