source pkgsNeeded.tcl

ui_init "t_transp.tcl" "magenta"
SetFileTypes

PH "Function to set transparency according to a color"

set fname "testIn/Colorbar.tga"

poImgUtil SetFormatChan $MATTE $UBYTE
poImageMode GetFileInfo $fname w h a g
set imgColorbar [poImage NewImage $w $h $a]
$imgColorbar ReadImage $fname
set msg "Original image"
ui_addimg $imgColorbar $msg

set i 0
for { set x 32 } { $x < $w } { incr x 64 } {
    $imgColorbar GetPixel $x [expr $h/2] pixVal
    set r [lindex $pixVal $RED]
    set g [lindex $pixVal $GREEN]
    set b [lindex $pixVal $BLUE]

    set imgTransp [poImgUtil CopyImg $imgColorbar]

    poImgUtil SetTransparentColor $imgTransp $r $g $b
    set fname "testOut/transp_$i$fInfo(suf)"
    set msg   [format "$fname: Transparent color (%.2f, %.2f %.2f)" $r $g $b]
    P $msg
    $imgTransp WriteSimple $fname $fInfo(fmt) $fInfo(vsn)
    ui_addimg $imgTransp $msg [list $RED $GREEN $BLUE $MATTE]

    poImgUtil DeleteImg $imgTransp
    incr i
}

poImgUtil DeleteImg $imgColorbar

PS
P "End of test"

ui_show

if { [lindex $argv 0] eq "auto" } {
    ui_exit
    exit 0
}
