# Test handling RAW images skipping header information using the pawt package.
# Note, that the RAW format supports storing rows in TopDown and BottomUp order.
#
# 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 "03_Read-Raw-SkipHeader"

# A RAW header has exactly 140 bytes.
set skipBytes 140

set soMap(bu) "BottomUp"
set soMap(td) "TopDown"
set winNum 1
foreach pixelType { byte short int float double } {
    set rowNum 1
    foreach numChan { 1 3 } {
        foreach scanOrder { bu td } {
            set inFileName [format "%s-%dchan-%s.raw" $pixelType $numChan $scanOrder]
            set inFilePath [file join "testIn" $inFileName]
            puts "Reading file $inFilePath ..."
            set rawNames($rowNum) $inFileName
            set rawDicts($rowNum) [pawt::ReadImageFile $inFilePath \
                         -useheader false -skipbytes $skipBytes \
                         -width 6 -height 2 \
                         -pixeltype $pixelType -scanorder $soMap($scanOrder) -numchan $numChan]

            incr rowNum
        }
    }
    pawtTest AddImgDicts $rawDicts(1) $rawNames(1) \
                         $rawDicts(2) $rawNames(2) \
                         $rawDicts(3) $rawNames(3) \
                         $rawDicts(4) $rawNames(4) \
                         -title "$testCase Part $winNum" -window $winNum -zoom 50
    incr winNum
}

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