Changeset 2035 for trunk/gui


Ignore:
Timestamp:
Jan 16, 2011, 10:09:17 AM (14 years ago)
Author:
dkearney
Message:

adding aspect ratio calculations.
disable analyze button when no movie has been choosen in piv
rename some functions

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/videopreview.tcl

    r2028 r2035  
    246246    set _movie [Rappture::Video $type $data]
    247247    file delete $fname
    248     set _framerate [${_movie} get framerate]
     248    set _framerate [${_movie} framerate]
    249249    set _mspf [expr round(((1.0/${_framerate})*1000))]
    250250    set _delay [expr {${_mspf} - ${_ofrd}}]
     
    265265    }
    266266
    267     set _lastFrame [$_movie get position end]
     267    set _lastFrame [${_movie} get position end]
    268268
    269269    # update the dial with video information
     
    426426        # because the underlying c lib is too slow at reading.
    427427        $_movie seek $cur
    428         $_imh put [$_movie get image ${_width} ${_height}]
     428        $_imh put [${_movie} get image ${_width} ${_height}]
    429429    } 1]
    430430    regexp {(\d+\.?\d*) microseconds per iteration} ${_ofrd} match _ofrd
     
    439439    }
    440440
    441     set cur [$_movie get position cur]
     441    set cur [${_movie} get position cur]
    442442
    443443    # update the dial and framenum widgets
     
    469469        error "bad value: \"$val\": should be \"seek value\""
    470470    }
    471     set cur [$_movie get position cur]
     471    set cur [${_movie} get position cur]
    472472    if {[string compare $cur $val] == 0} {
    473473        # already at the frame to seek to
     
    478478
    479479    # update the dial and framenum widgets
    480     set _settings($this-framenum) [$_movie get position cur]
     480    set _settings($this-framenum) [${_movie} get position cur]
    481481    event generate $itk_component(main) <<Frame>>
    482482
     
    505505                # no play pending schedule one
    506506                set _pendings(play) 1
    507                 set _nextframe [expr {[$_movie get position cur] + 1}]
     507                set _nextframe [expr {[${_movie} get position cur] + 1}]
    508508                after idle [itcl::code $this Play]
    509509            } else {
  • trunk/gui/scripts/videoscreen.tcl

    r2029 r2035  
    1616package require RapptureGUI
    1717
    18 option add *Video.width 300 widgetDefault
    19 option add *Video.height 300 widgetDefault
     18option add *Video.width -1 widgetDefault
     19option add *Video.height -1 widgetDefault
    2020option add *Video.foreground black widgetDefault
    2121option add *Video.controlBackground gray widgetDefault
     
    7070    private common   _counters
    7171
    72     private variable _width -1      ;# start x for rubberbanding
    73     private variable _height -1     ;# start x for rubberbanding
     72    private variable _width -1      ;# width of the movie
     73    private variable _height -1     ;# height of the movie
    7474    private variable _movie ""      ;# movie we grab images from
    7575    private variable _lastFrame 0   ;# last frame in the movie
     
    120120
    121121    itk_component add main {
    122         canvas $itk_interior.main \
    123             -background black
     122        canvas $itk_interior.main
    124123    } {
    125124        usual
     
    128127    bind $itk_component(main) <Configure> [itcl::code $this fixSize]
    129128
     129    # setup the image display
    130130    # hold the video frames in an image on the canvas
    131131    set _imh [image create photo]
    132     $itk_component(main) create image 0 0 -anchor nw -image $_imh
     132
     133    $itk_component(main) create image 0 0 \
     134        -anchor center \
     135        -image ${_imh} \
     136        -tags videoframe
    133137
    134138    # setup movie controls
     
    311315
    312316    itk_component add framenumlabel {
    313         label $itk_component(frnumfr).framenuml -text "Frame:" -font $fg \
     317        label $itk_component(frnumfr).framenuml -text "Frame:" -font "arial 9" \
    314318            -highlightthickness 0
    315319    } {
     
    376380        1,3 $itk_component(seekforward) -padx {4 0} \
    377381        1,4 $itk_component(loop) -padx {4 0} \
    378         2,0 $itk_component(frnumfr) -padx {2 0} -columnspan 3 \
     382        2,0 $itk_component(frnumfr) -padx {0 0} -columnspan 3 \
    379383        2,3 $itk_component(speed) -padx {2 0} -columnspan 2
    380384
     
    392396
    393397    eval itk_initialize $args
     398
     399    $itk_component(main) configure -background black
    394400}
    395401
     
    404410
    405411
    406     if {[info exists _imh]} {
     412    if {[info exists _imh] && ("" != ${_imh})} {
    407413        image delete ${_imh}
    408414        set _imh ""
     
    466472itcl::body Rappture::VideoScreen::load {type data} {
    467473
     474    video stop
     475
    468476    # open the file
    469477    set fname ""
     
    493501    }
    494502
    495     video stop
    496 
    497503    if {"file" == $type} {
    498504        if {("" != [info commands ${_movie}])} {
     
    502508            # if they are different, close the old movie
    503509            # and clear out all old drawings from the canvas.
    504             set err [catch {${_movie} get filename} filename]
     510            set err [catch {${_movie} filename} filename]
    505511            if {($err == 0)&& ($data == $filename)} {
    506512                # video file already open, don't reopen it.
     
    509515                # clear the old movie
    510516                ${_movie} release
     517                set _width -1
     518                set _height -1
    511519
    512520                # delete drawings objects from canvas
     
    520528        file delete $fname
    521529    }
    522     set _framerate [${_movie} get framerate]
     530    set _framerate [${_movie} framerate]
    523531    video speed
    524 
    525     video seek 0
    526 
    527     # update the dial and framenum widgets
    528     set _settings(framenum) 0
    529 
    530 
    531     # setup the image display
    532 
    533     foreach {w h} [query dimensions] break
    534     if {${_width} == -1} {
    535         set _width $w
    536     }
    537     if {${_height} == -1} {
    538         set _height $h
    539     }
    540 
    541     set _lastFrame [$_movie get position end]
     532    puts stderr "framerate: ${_framerate}"
     533
     534    set _lastFrame [${_movie} get position end]
    542535
    543536    # update the dial with video information
     
    559552
    560553    fixSize
     554
     555    # goto the first frame
     556    # update the dial and framenum widgets
     557    video seek 0
     558    set _settings(framenum) 0
    561559}
    562560
     
    600598    }
    601599
    602 #    set _width [winfo width $itk_component(main)]
    603 #    set _height [winfo height $itk_component(main)]
    604 #
    605 #    # get an image with the new size
    606 #    ${_imh} put [${_movie} get image ${_width} ${_height}]
    607 #
    608 #    # fix the dimesions of the canvas
    609 #    #$itk_component(main) configure -width ${_width} -height ${_height}
    610 #
    611 #    $itk_component(main) configure -scrollregion [$itk_component(main) bbox all]
    612 
    613 ######################
     600    # get dimensions for the new image
     601    # adjust the aspect ratio, if necessary
     602
     603    puts stderr "aspect ratio: [query aspectratio]"
     604
     605    foreach {w h} [query dimensions] break
     606    foreach {num den} [query aspectratio] break
     607
     608    if {[expr 1.0*$w/$h] != [expr 1.0*$num/$den]} {
     609        # we need to adjust the frame height and width
     610        # to keep the correct aspect ratio
     611        # hold the height constant,
     612        # adjust the width as close as we can
     613        # to the correct aspect ratio
     614        set w [expr int(1.0*$num/$den*$h)]
     615    }
     616
     617    if {-1 == ${_width}} {
     618        set _width $w
     619    }
     620    if {-1 == ${_height}} {
     621        set _height $h
     622    }
    614623
    615624    # get an image with the new size
     625    ${_imh} blank
     626    ${_imh} configure -width 1 -height 1
     627    ${_imh} configure -width 0 -height 0
    616628    ${_imh} put [${_movie} get image ${_width} ${_height}]
    617     puts stderr "${_width} ${_height}"
    618 
    619     # fix the dimesions of the video canvas
    620     $itk_component(main) configure -width ${_width} -height ${_height}
     629
     630    # place the image in the center of the canvas
     631    set ccw [winfo width $itk_component(main)]
     632    set cch [winfo height $itk_component(main)]
     633    $itk_component(main) coords videoframe [expr $ccw/2.0] [expr $cch/2.0]
     634
     635    puts stderr "----------------------------"
     636    puts stderr "adjusted = $w $h"
     637    puts stderr "data     = ${_width} ${_height}"
     638    puts stderr "image    = [image width ${_imh}] [image height ${_imh}]"
     639    foreach {x0 y0 x1 y1} [$itk_component(main) bbox videoframe] break
     640    puts stderr "bbox     = $x0 $y0 $x1 $y1"
     641    puts stderr "ccw cch  = [expr $ccw/2.0] [expr $cch/2.0]"
     642    puts stderr "main     = [winfo width $itk_component(main)] [winfo height $itk_component(main)]"
     643    puts stderr "hull     = [winfo width $itk_component(hull)] [winfo height $itk_component(hull)]"
    621644}
    622645
     
    670693    set ret ""
    671694    switch -- $type {
     695        "aspectratio" {
     696            set ret [${_movie} aspect display]
     697        }
    672698        "dimensions" {
    673699            set ret [${_movie} size]
     
    698724        # not the current frame+1. this happens when we skip frames
    699725        # because the underlying c lib is too slow at reading.
    700         $_movie seek $cur
    701         $_imh put [$_movie get image ${_width} ${_height}]
     726        ${_movie} seek $cur
     727        ${_imh} put [${_movie} get image ${_width} ${_height}]
    702728    } 1]
    703729    regexp {(\d+\.?\d*) microseconds per iteration} ${_ofrd} match _ofrd
     
    712738    }
    713739
    714     set cur [$_movie get position cur]
     740    set cur [${_movie} get position cur]
    715741
    716742    # update the dial and framenum widgets
     
    751777        error "bad value: \"$val\": should be \"seek value\""
    752778    }
    753     set cur [$_movie get position cur]
     779    set cur [${_movie} get position cur]
    754780    if {[string compare $cur $val] == 0} {
    755781        # already at the frame to seek to
     
    761787
    762788    # update the dial and framenum widgets
    763     set _settings(framenum) [$_movie get position cur]
     789    set _settings(framenum) [${_movie} get position cur]
    764790    event generate $itk_component(main) <<Frame>>
    765791
     
    790816                # no play pending schedule one
    791817                set _pendings(play) 1
    792                 set _nextframe [expr {[$_movie get position cur] + 1}]
     818                set _nextframe [expr {[${_movie} get position cur] + 1}]
    793819                after idle [itcl::code $this Play]
    794820            } else {
     
    12171243        $itk_component(dialminor) loop disable
    12181244    } else {
    1219         set cur [$_movie get position cur]
    1220         set end [$_movie get position end]
     1245        set cur [${_movie} get position cur]
     1246        set end [${_movie} get position end]
    12211247
    12221248        set startframe [expr $cur-10]
     
    12361262
    12371263# ----------------------------------------------------------------------
    1238 # OPTION: -width
     1264# OPTION: -width - width of the video
    12391265# ----------------------------------------------------------------------
    12401266itcl::configbody Rappture::VideoScreen::width {
     
    12481274
    12491275# ----------------------------------------------------------------------
    1250 # OPTION: -height
     1276# OPTION: -height - height of the video
    12511277# ----------------------------------------------------------------------
    12521278itcl::configbody Rappture::VideoScreen::height {
Note: See TracChangeset for help on using the changeset viewer.