# Test displaying 16-bit images as pseudo-color using the pawt package.
#
# 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 "04_PhotoPseudocolor-short"

set inFileList { "short-1chan-td" "short-3chan-td" }

foreach inFilePrefix $inFileList {
    set inFileName [format "%s.%s" $inFilePrefix "raw"]
    set inFilePath [file join "testIn" $inFileName]
    puts "Reading file $inFilePath ..."
    set imgDict [pawt::raw::ReadImageFile $inFilePath]

    puts "Get photo with default scale values ..."
    set photoGrey1 [pawt GetImageAsPhoto imgDict]
    set retVal [catch { pawt GetImageAsPseudoColorPhoto imgDict } photoPseudo1]
    if { $retVal == 0 } {
        set photoRG1 [pawt GetImageAsPseudoColorPhoto imgDict -mode "redgreen"]
        pawtTest AddImgPhotos $photoGrey1   "$inFilePrefix Greyscale (Gamma 1)" \
                              $photoPseudo1 "$inFilePrefix PseudoColor" \
                              $photoRG1     "$inFilePrefix RG Color" \
                              -title $testCase -zoom 50
    } else {
        set photoUnsupported [pawtTest CreatePhotoUnsupported [pawt GetImageWidth imgDict] [pawt GetImageHeight imgDict]]
        pawtTest AddImgPhotos $photoGrey1 "$inFilePrefix Greyscale (Gamma 1)"  $photoUnsupported $photoPseudo1 -zoom 50
    }

    puts "Get photo with gamma scale values ..."
    set photoGrey2 [pawt GetImageAsPhoto imgDict -gamma 2.0]
    set retVal [catch { pawt GetImageAsPseudoColorPhoto imgDict -mode "pseudo" } photoPseudo2]
    if { $retVal == 0 } {
        set photoRG2 [pawt GetImageAsPseudoColorPhoto imgDict -mode "redgreen"]
        pawtTest AddImgPhotos $photoGrey2   "$inFilePrefix Greyscale (Gamma 2)" \
                              $photoPseudo2 "$inFilePrefix PseudoColor" \
                              $photoRG2     "$inFilePrefix RG Color" \
                              -title $testCase -zoom 50
    } else {
        set photoUnsupported [pawtTest CreatePhotoUnsupported [pawt GetImageWidth imgDict] [pawt GetImageHeight imgDict]]
        pawtTest AddImgPhotos $photoGrey2 "$inFilePrefix Greyscale (Gamma 2)"  $photoUnsupported $photoPseudo2 -zoom 50
    }

    puts ""
}


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