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

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

set testCase "03_ReadWrite-Raw-NoHeader"

puts "\nCreate 3-channel byte image"
set imgDict [pawt CreateImage -width 6 -height 2 -pixeltype "byte" -numchan 3 -list [pawtTest GetRgbListTD-byte]]

set outFilePath [file join "testOut" [format "%s_3chan_NoHeader.raw" $testCase]]
puts "Write  3-channel byte image [file tail $outFilePath]"
pawt::raw::WriteImageFile $imgDict $outFilePath -scanorder "TopDown" -useheader false

puts "Read   3-channel byte image [file tail $outFilePath]"
set rawDict3 [pawt::raw::ReadImageFile $outFilePath -useheader false -width 6 -height 2 -numchan 3 -scanorder "TopDown"]
set rawImgAsList [pawt GetImageAsList rawDict3]
pawtTest CheckList [pawtTest GetRgbListTD-byte] $rawImgAsList "Check input vs. RAW-NoHeader"
pawtTest AddImgDicts $imgDict "In: 3-channel byte (NoHeader)"  $rawDict3 "Out: 3-channel byte (NoHeader)"  -zoom 50 -title $testCase

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