@@ -45,9 +45,9 @@ def main():
4545StopCapture = 'StopCapture'
4646
4747VideoFormatLabels = ['Video off' , 'rgb8' , 'grey8' , 'grey4' , 'grey2' , \
48- 'grey2 dith' , 'mono dith' , 'mono thresh' ]
48+ 'grey2 dith' , 'mono dith' , 'mono thresh' , 'rgb24' , 'rgb24-jpeg' ]
4949VideoFormats = ['' , 'rgb8' , 'grey' , 'grey4' , 'grey2' , \
50- 'grey2' , 'mono' , 'mono' ]
50+ 'grey2' , 'mono' , 'mono' , 'rgb' , 'jpeg' ]
5151
5252VideoModeLabels = ['Continuous' , 'Burst' , 'Single frame' , 'VCR sync' ]
5353[VM_CONT , VM_BURST , VM_SINGLE , VM_VCR ] = range (1 , 5 )
@@ -56,11 +56,17 @@ def main():
5656 '16 bit mono' , '16 bit stereo' , '8 bit mono' , '8 bit stereo' ]
5757[A_OFF , A_16_MONO , A_16_STEREO , A_8_MONO , A_8_STEREO ] = range (1 , 6 )
5858
59+ VcrSpeedLabels = ['normal' , '1/3' , '1/5' , '1/10' , '1/30' , 'single-step' ]
60+ VcrSpeeds = [None , 5 , 4 , 3 , 2 , 1 , 0 ]
61+
62+ RgbSizeLabels = ['full' , 'quarter' , 'sixteenth' ]
63+
5964class VideoBagOfTricks :
6065
6166 # Init/close stuff
6267
6368 def init (self ):
69+ self .window = None
6470 formdef = flp .parse_form ('VbForm' , 'form' )
6571 flp .create_full_form (self , formdef )
6672 self .g_cont .hide_object ()
@@ -119,6 +125,15 @@ def setdefaults(self):
119125 self .in_nframes .set_input ('0' )
120126 self .in_nframes_vcr .set_input ('1' )
121127 self .in_rate_vcr .set_input ('1' )
128+ self .c_vcrspeed .clear_choice ()
129+ for label in VcrSpeedLabels :
130+ self .c_vcrspeed .addto_choice (label )
131+ self .c_vcrspeed .set_choice (4 )
132+ self .c_rgb24_size .clear_choice ()
133+ for label in RgbSizeLabels :
134+ self .c_rgb24_size .addto_choice (label )
135+ self .c_rgb24_size .set_choice (1 )
136+ self .rgb24_size = 1
122137 # Audio defaults
123138 self .aout = None
124139 self .aport = None
@@ -174,6 +189,17 @@ def makewindow(self):
174189 gl .qdevice (DEVICE .WINQUIT )
175190 gl .qdevice (DEVICE .WINSHUT )
176191
192+ def optfullsizewindow (self ):
193+ if not self .window :
194+ return
195+ gl .winset (self .window )
196+ if not self .use_24 :
197+ gl .winconstraints ()
198+ return
199+ gl .prefsize (self .maxx , self .maxy )
200+ gl .winconstraints ()
201+ self .bindvideo ()
202+
177203 def bindvideo (self ):
178204 if not self .video : return
179205 x , y = gl .getsize ()
@@ -287,6 +313,14 @@ def cb_nframes_vcr(self, *args):
287313 def cb_rate_vcr (self , * args ):
288314 pass
289315
316+ def cb_vcrspeed (self , * args ):
317+ pass
318+
319+ def cb_rgb24_size (self , * args ):
320+ i = self .c_rgb24_size .get_choice ()
321+ if i :
322+ self .rgb24_size = i
323+
290324 # Audio controls: format, file
291325
292326 def cb_aformat (self , * args ):
@@ -318,7 +352,7 @@ def cb_capture(self, *args):
318352 elif self .vmode == VM_BURST :
319353 self .burst_capture ()
320354 elif self .vmode == VM_SINGLE :
321- self .single_capture ()
355+ self .single_capture (None , None )
322356 elif self .vmode == VM_VCR :
323357 self .vcr_capture ()
324358
@@ -338,6 +372,9 @@ def burst_capture(self):
338372 self .setwatch ()
339373 gl .winset (self .window )
340374 x , y = gl .getsize ()
375+ if self .use_24 :
376+ fl .show_message ('Sorry, no 24 bit continuous capture yet' , '' , '' )
377+ return
341378 vformat = SV .RGB8_FRAMES
342379 nframes = self .getint (self .in_nframes , 0 )
343380 if nframes == 0 :
@@ -424,7 +461,7 @@ def cont_capture(self):
424461 self .reset ()
425462 self .b_capture .label = saved_label
426463
427- def single_capture (self ):
464+ def single_capture (self , stepfunc , timecode ):
428465 self .open_if_closed ()
429466 self .init_cont ()
430467 while 1 :
@@ -434,11 +471,32 @@ def single_capture(self):
434471 except sv .error :
435472 pass
436473 sgi .nap (1 )
437- data = cd .InterleaveFields (1 )
474+ if stepfunc : # This might step the video
475+ d = stepfunc () # to the next frame
476+ if not self .use_24 :
477+ data = cd .InterleaveFields (1 )
478+ else :
479+ x , y = self .vout .getsize ()
480+ if self .rgb24_size == 1 :
481+ data = cd .YUVtoRGB (1 )
482+ elif self .rgb24_size == 2 :
483+ data = cd .YUVtoRGB_quarter (1 )
484+ x = x / 2
485+ y = y / 2
486+ elif self .rgb24_size == 3 :
487+ data = cd .YUVtoRGB_sixteenth (1 )
488+ x = x / 4
489+ y = y / 4
490+ else :
491+ raise 'Kaboo! Kaboo!'
492+ if self .use_jpeg :
493+ import jpeg
494+ data = jpeg .compress (data , x , y , 4 )
438495 cd .UnlockCaptureData ()
439496 self .end_cont ()
440- t = (self .nframes + 1 ) * (1000 / 25 )
441- return self .write_frame (t , data )
497+ if timecode == None :
498+ timecode = (self .nframes + 1 ) * (1000 / 25 )
499+ return self .write_frame (timecode , data )
442500
443501 def vcr_capture (self ):
444502 if not self .vcr :
@@ -462,9 +520,15 @@ def vcr_capture(self):
462520 self .open_if_closed ()
463521 rate = self .getint (self .in_rate_vcr , 1 )
464522 rate = max (rate , 1 )
523+ vcrspeed = self .c_vcrspeed .get_choice ()
524+ vcrspeed = VcrSpeeds [vcrspeed ]
525+ if vcrspeed == 0 :
526+ stepfunc = self .vcr .step
527+ else :
528+ stepfunc = None
465529 self .speed_factor = rate
466- addr = self .vcr .sense ()
467- if not self .single_capture ():
530+ addr = start_addr = self .vcr .sense ()
531+ if not self .single_capture (None , 0 ):
468532 return
469533 print 'captured %02d:%02d:%02d:%02d' % self .vcr .addr2tc (addr )
470534 count = self .getint (self .in_nframes_vcr , 1 ) - 1
@@ -477,7 +541,7 @@ def vcr_capture(self):
477541 rate = rate - (here - addr )
478542 addr = here
479543 return
480- if not self .vcr .fwdshuttle (2 ): # one tenth speed
544+ if not self .vcr .fwdshuttle (vcrspeed ): # one tenth speed
481545 self .vcr_error ('fwd shuttle failed' )
482546 return
483547 cycle = 0
@@ -494,7 +558,9 @@ def vcr_capture(self):
494558 print 'frame' + 's' * (here - addr - 1 <> 1 )
495559 cycle = (cycle + 1 ) % rate
496560 if cycle == 0 :
497- if not self .single_capture ():
561+ tc = (here - start_addr )* 40
562+ if not self .single_capture (stepfunc , \
563+ tc ):
498564 break
499565 print 'captured %02d:%02d:%02d:%02d' \
500566 % self .vcr .addr2tc (here )
@@ -516,7 +582,10 @@ def init_cont(self):
516582 else :
517583 self .rate = 2
518584 x , y = self .vout .getsize ()
519- info = (SV .RGB8_FRAMES , x , y , qsize , self .rate )
585+ if self .use_24 :
586+ info = (SV .YUV411_FRAMES , x , y , qsize , self .rate )
587+ else :
588+ info = (SV .RGB8_FRAMES , x , y , qsize , self .rate )
520589 info2 = self .video .InitContinuousCapture (info )
521590 if info2 <> info :
522591 # XXX This is really only debug info
@@ -558,6 +627,13 @@ def get_vformat(self):
558627 self .rgb = (format [:3 ] == 'rgb' )
559628 self .mono = (format == 'mono' )
560629 self .grey = (format [:4 ] == 'grey' )
630+ self .use_24 = (format in ('rgb' , 'jpeg' ))
631+ # Does not work.... if self.use_24:
632+ if 0 :
633+ self .g_rgb24 .show_object ()
634+ else :
635+ self .g_rgb24 .hide_object ()
636+ self .use_jpeg = (format == 'jpeg' )
561637 self .mono_use_thresh = (label == 'mono thresh' )
562638 s = format [4 :]
563639 if s :
@@ -576,6 +652,7 @@ def get_vformat(self):
576652 elif self .greybits == - 2 :
577653 convertor = imageop .dither2grey2
578654 self .convertor = convertor
655+ self .optfullsizewindow ()
579656
580657 def get_aformat (self ):
581658 self .reset ()
@@ -597,6 +674,11 @@ def open_video(self):
597674 self .close_video ()
598675 gl .winset (self .window )
599676 x , y = gl .getsize ()
677+ if self .use_24 :
678+ if self .rgb24_size == 2 :
679+ x , y = x / 2 , y / 2
680+ elif self .rgb24_size == 4 :
681+ x , y = x / 4 , y / 4
600682 vout = VFile .VoutFile ().init (self .vfile )
601683 vout .setformat (self .vformat )
602684 vout .setsize (x , y )
0 commit comments