#
# Copyright (c) 1993-1995 Regents of the University of California.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
# 3. All advertising materials mentioning features or use of this software
#    must display the following acknowledgement:
#	This product includes software developed by the Computer Systems
#	Engineering Group at Lawrence Berkeley Laboratory.
# 4. Neither the name of the University nor of the Laboratory may be used
#    to endorse or promote products derived from this software without
#    specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#

#
# This file contains stubs for building any grabber specific controls.
# If a device is named foo, then create define build.foo proc here
# that builds UI.  If this proc doesn't exist, then it will be ommitted.
# If there are multiple devices with the same name, they should be
# called foo-1, foo-2, etc. and you'll only need build.foo
#

proc build.slicvideo w {
	set f [smallfont]
	label $w.title -text "Grabber"
	frame $w.f -relief sunken -borderwidth 2

	frame $w.f.h -relief flat
       
	label $w.f.h.label  -font $f -anchor e -text "Hue"
       
	scale $w.f.h.scale -orient horizontal -width 12 -length 20 \
		           -relief groove -showvalue 0 -from -128 -to 127 \
                          -command "grabber set HUE"
	pack  $w.f.h.label $w.f.h.scale -side left -fill x -expand 1

	frame $w.f.ll -relief flat 
       
	label $w.f.ll.label  -font $f -text "Luma" -anchor s
       
	label $w.f.ll.clabel -font $f -text "Contrast" -anchor s
      
	label $w.f.ll.blabel -font $f -text "Brightness" -anchor s
	pack  $w.f.ll.clabel $w.f.ll.label $w.f.ll.blabel \
			     -side left -fill x -expand 1

	frame $w.f.l  -relief flat
       
	scale $w.f.l.cscale   -orient horizontal -width 12 -relief groove \
                              -showvalue 0 -from 0 -to 127 \
                              -command "grabber set LUMA_CONTRAST"
       
	scale $w.f.l.bscale -orient horizontal -width 12 -relief groove \
                            -showvalue 0 -from 0 -to 255 \
                            -command "grabber set LUMA_BRIGHTNESS"
	pack  $w.f.l.cscale $w.f.l.bscale  -side left -fill x -expand 1

	frame $w.f.cl  -relief flat

	label $w.f.cl.label  -font $f -text "Chroma" -anchor n
       
	label $w.f.cl.glabel -font $f -text "Gain" -anchor n
       
	label $w.f.cl.slabel -font $f -text "Saturation" -anchor n
	pack  $w.f.cl.glabel $w.f.cl.label $w.f.cl.slabel \
			     -side left -fill x -expand 1

	frame $w.f.c -relief flat
       
	scale $w.f.c.gscale -orient horizontal -width 12 -relief groove \
                             -showvalue 0 -from 0 -to 255 \
                             -command "grabber set CHROMA_GAIN"
       
	scale $w.f.c.sscale -orient horizontal -width 12 -relief groove \
                            -showvalue 0 -from 0 -to 127 \
                            -command "grabber set CHROMA_SATURATION"
	pack  $w.f.c.gscale $w.f.c.sscale -side left -fill x -expand 1

     
	pack  $w.f.h $w.f.ll $w.f.l $w.f.c $w.f.cl \
	      -fill x -expand 1 -padx 1m 


	pack $w.title $w.f -fill x -expand 1

	$w.f.h.scale  set 0
	$w.f.l.cscale set 64
	$w.f.l.bscale set 128
	$w.f.c.gscale set 44
	$w.f.c.sscale set 64
}

proc build.still w {

    set f [smallfont]
    label $w.title -text "Grabber"

    frame $w.f -relief sunken -borderwidth 2
    
    label $w.f.label  -font $f -anchor e -text "File"
    
    mk.entry $w.f set.still.frame "frame"

    pack $w.title $w.f -fill x -expand 1
    
    pack $w.f.label -side left 
    pack $w.f.entry -side left -fill x -expand 1
}

proc set.still.frame {w s } {
    global lastDevice
    $lastDevice file $s
}

proc build.qcam {w} {
    global qcamwindow

    set f [smallfont]
    label $w.title -text "Grabber"

    frame $w.f -relief sunken -borderwidth 2

    frame $w.f.s -relief flat

    frame $w.f.s.l -relief flat
    label $w.f.s.l.bright -font $f -anchor w -text "Brightness"
    label $w.f.s.l.cont   -font $f -anchor w -text "Contrast"
    label $w.f.s.l.wbal   -font $f -anchor w -text "White balance"
    pack  $w.f.s.l.bright $w.f.s.l.cont $w.f.s.l.wbal \
	-side top -fill x -expand 1

    frame $w.f.s.s -relief flat
    scale $w.f.s.s.bright -orient horizontal -width 12 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set BRIGHT"
    scale $w.f.s.s.cont   -orient horizontal -width 12 \
                          -relief groove -showvalue 0 \
                          -from 0 -to 1.0 -resolution 0.002 \
                          -command "grabber contrast"

    frame $w.f.s.s.wbal -relief flat
    scale $w.f.s.s.wbal.scale  -orient horizontal -width 12 \
                             -relief groove -showvalue 0 -from 1 -to 254 \
                             -command "grabber set WBAL"
    button $w.f.s.s.wbal.button -font $f -text Auto \
	-command "grabber set WBAL auto"
    pack  $w.f.s.s.wbal.scale $w.f.s.s.wbal.button \
	-side left -fill x -expand 1

    pack $w.f.s.s.bright $w.f.s.s.cont $w.f.s.s.wbal \
        -side top -fill x -expand 1

    pack $w.f.s.l $w.f.s.s -side left -fill x -expand 1

    frame $w.f.bpp -relief flat
    label $w.f.bpp.label  -font $f -anchor w -text "Pixel depth"
    radiobutton $w.f.bpp.bpp4 -font $f -text "4-bit" \
	-variable qcambpp -value 4 -command "grabber set BPP 4"
    radiobutton $w.f.bpp.bpp6 -font $f -text "6-bit" \
	-variable qcambpp -value 6 -command "grabber set BPP 6"
    pack $w.f.bpp.label $w.f.bpp.bpp4 $w.f.bpp.bpp6 \
	-side left -fill x -expand 1

    pack  $w.f.s $w.f.bpp \
	 -fill x -expand 1 -padx 1m 

    pack $w.title $w.f -fill x -expand 1

    set qcamwindow(setbright) "$w.f.s.s.bright set"
    set qcamwindow(setcont) "$w.f.s.s.cont set"
    set qcamwindow(setwbal) "$w.f.s.s.wbal.scale set"
    set qcamwindow(setbpp) "set qcambpp"
}

proc build.cqcam {w} {
    global cqcamwindow

    set f [smallfont]
    label $w.title -text "Grabber"

    frame $w.f -relief sunken -borderwidth 2

    frame $w.f.s -relief flat

    frame $w.f.s.l -relief flat
    label $w.f.s.l.bright -font $f -anchor w -text "Brightness"
    label $w.f.s.l.hue -font $f -anchor w -text "Hue (Hw)"
    label $w.f.s.l.red -font $f -anchor w -text "Red (Sw)"
    label $w.f.s.l.green -font $f -anchor w -text "Green (Sw)"
    label $w.f.s.l.blue -font $f -anchor w -text "Blue (Sw)"
    label $w.f.s.l.sat -font $f -anchor w -text "Saturation"
    label $w.f.s.l.cont   -font $f -anchor w -text "Contrast"
    label $w.f.s.l.wbal   -font $f -anchor w -text "White balance"
    label $w.f.s.l.bbal   -font $f -anchor w -text "Black balance"
    label $w.f.s.l.left   -font $f -anchor w -text "X offset"
    label $w.f.s.l.top   -font $f -anchor w -text "Y offset"
    pack  $w.f.s.l.bright $w.f.s.l.hue $w.f.s.l.red $w.f.s.l.green \
	$w.f.s.l.blue \
	$w.f.s.l.sat $w.f.s.l.cont \
	$w.f.s.l.wbal $w.f.s.l.bbal \
	$w.f.s.l.left $w.f.s.l.top \
	-side top -fill x -expand 1

    frame $w.f.s.s -relief flat
    scale $w.f.s.s.bright -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set BRIGHT"
    scale $w.f.s.s.red -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 254 -to 1 \
                          -command "grabber set RED"
    scale $w.f.s.s.green -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 254 -to 1 \
                          -command "grabber set GREEN"
    scale $w.f.s.s.blue -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 254 -to 1 \
                          -command "grabber set BLUE"
    scale $w.f.s.s.sat -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set SATURATION"
    scale $w.f.s.s.hue -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set HUE"
    scale $w.f.s.s.cont   -orient horizontal -width 9 \
                          -relief groove -showvalue 0 \
                          -from 1 -to 254 \
                          -command "grabber set CONTRAST"
    scale $w.f.s.s.wbal -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set WBAL"
    scale $w.f.s.s.bbal -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 254 \
                          -command "grabber set BBAL"

    scale $w.f.s.s.left -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 160 \
                          -command "grabber set LEFT"

    scale $w.f.s.s.top -orient horizontal -width 9 \
		          -relief groove -showvalue 0 -from 1 -to 240 \
                          -command "grabber set TOP"

    frame $w.f.bpp -relief flat
    label $w.f.bpp.label  -font $f -anchor w -text "Transfer size"
    radiobutton $w.f.bpp.bpp24 -font $f -text "24bit" \
        -variable cqcambpp -value 24 -command "grabber set BPP 24"
    radiobutton $w.f.bpp.bpp32 -font $f -text "32bit" \
        -variable cqcambpp -value 32 -command "grabber set BPP 32"
    pack $w.f.bpp.label $w.f.bpp.bpp24 $w.f.bpp.bpp32 \
        -side left -fill x -expand 1



    frame $w.f.decimate -relief flat
    label $w.f.decimate.label  -font $f -anchor w -text "Decimation"
    radiobutton $w.f.decimate.decimate1 -font $f -text "1" \
        -variable cqcamdecimate -value 1 -command "grabber set DECIMATE 1"
    radiobutton $w.f.decimate.decimate2 -font $f -text "2" \
        -variable cqcamdecimate -value 2 -command "grabber set DECIMATE 2"
    radiobutton $w.f.decimate.decimate4 -font $f -text "4" \
        -variable cqcamdecimate -value 4 -command "grabber set DECIMATE 4"
    pack $w.f.decimate.label $w.f.decimate.decimate1 $w.f.decimate.decimate2 \
         $w.f.decimate.decimate4 -side left -fill x -expand 1


    frame $w.f.process -relief flat
    label $w.f.process.label  -font $f -anchor w -text "Auto Adjust"
    button $w.f.process.color -font $f -text "Color" \
        -command "grabber set auto_color 1"
    button $w.f.process.bright -font $f -text "Brightness" \
         -command "grabber set auto_bright 1"
    button $w.f.process.despeckle -font $f -text "DeSpeckle" \
         -command "grabber set despeckle 1"
    pack $w.f.process.label  $w.f.process.color \
         $w.f.process.bright $w.f.process.despeckle -side left \
	-fill x -expand 1


    pack $w.f.s.s.bright $w.f.s.s.red $w.f.s.s.green \
	$w.f.s.s.blue  -side top -fill x -expand 1

    pack $w.f.s.s.hue $w.f.s.s.sat $w.f.s.s.cont \
	$w.f.s.s.wbal $w.f.s.s.bbal \
	$w.f.s.s.left $w.f.s.s.top \
        -side top -fill x -expand 1

    pack  $w.f.s $w.f.process \
         -fill x -expand 1 -padx 1m -side top

    pack  $w.f.s $w.f.bpp \
         -fill x -expand 1 -padx 1m -side top

    pack  $w.f.s $w.f.decimate \
         -fill x -expand 1 -padx 1m -side top


    pack $w.f.s.l $w.f.s.s -side left -fill x -expand 1


    pack  $w.f.s  \
	 -fill x -expand 1 -padx 1m 

    pack $w.title $w.f -fill x -expand 1

    set cqcamwindow(setbright) "$w.f.s.s.bright set"
    set cqcamwindow(sethue) "$w.f.s.s.hue set"
    set cqcamwindow(setred) "$w.f.s.s.red set"
    set cqcamwindow(setgreen) "$w.f.s.s.green set"
    set cqcamwindow(setblue) "$w.f.s.s.blue set"
    set cqcamwindow(setsat) "$w.f.s.s.sat set"
    set cqcamwindow(setcont) "$w.f.s.s.cont set"
    set cqcamwindow(setwbal) "$w.f.s.s.wbal set"
    set cqcamwindow(setbbal) "$w.f.s.s.bbal set"
    set cqcamwindow(setleft) "$w.f.s.s.left set"
    set cqcamwindow(settop) "$w.f.s.s.top set"
    set cqcamwindow(setbpp) "set cqcambpp"
    set cqcamwindow(setdecimate) "set cqcamdecimate"
}





