Package VisionEgg :: Module QuickTime |
[frames] | no frames]

# Source Code for Module VisionEgg.QuickTime

      1  # The Vision Egg: QuickTime
      2  #
      3  # Copyright (C) 2001-2003, 2006 Andrew Straw.
      4  # Author: Andrew Straw <astraw@users.sourceforge.net>
      5  # URL: <http://www.visionegg.org/>
      6  #
      7  # Distributed under the terms of the GNU Lesser General Public License
      8  # (LGPL). See LICENSE.TXT that came with this file.
      9
     10  """
     11  QuickTime movies in the Vision Egg.
     12
     13  """
     14
     15  import VisionEgg
     16  import VisionEgg.gl_qt # C implementation of GL/QT interface
     17  import VisionEgg.qtmovie as qtmovie
     18  import VisionEgg.Textures
     19
     20  import numpy.oldnumeric as Numeric
     21  import os
     22
     23  import VisionEgg.GL as gl # get all OpenGL stuff in one namespace
     24
     25  __version__ = VisionEgg.release_name
     26  __author__ = 'Andrew Straw <astraw@users.sourceforge.net>'
     27
     28  #######################################################
     29
     30  new_movie_from_filename = qtmovie.new_movie_from_filename
     31
     32 -class MovieTexture(VisionEgg.Textures.Texture):
     33
     34      __slots__ = (
     35          'movie',
     36          'size',
     37          'scale',
     38          'gl_qt_renderer',
     39          )
     40
     41 -    def __init__(self,
     42                   movie=None,
     43                   texture_size=None, # be default will be big enough for full movie, otherwise 2-tuple
     44                   ):
     45          if not isinstance(movie,qtmovie.Movie):
     46              if isinstance(movie,str) or isinstance(movie,unicode):
     47                  movie = new_movie_from_filename(filename=movie)
     48          self.movie = movie
     49          bounds = self.movie.GetMovieBox()
     50          height = bounds.bottom-bounds.top
     51          width = bounds.right-bounds.left
     52          self.movie.SetMovieBox(qtmovie.Rect(top=0,left=0,bottom=height,right=width))
     53          self.size = (width,height)
     54          self.scale = 1.0
     55
     56 -    def make_half_size(self):
     57          self.size = self.size[0]/2, self.size[1]/2
     58          self.scale = self.scale/2
     59
     60 -    def unload(self):
     61          raise NotImplementedError('')
     62
     63 -    def get_texels_as_image(self):
     64          raise NotImplementedError('')
     65
     66 -    def load(self, texture_object,
     67               build_mipmaps=False,
     68               rescale_original_to_fill_texture_object = False,
     69               internal_format=gl.GL_RGB,
     70               ):
     71          if build_mipmaps:
     72              raise ValueError('cannot build mipmaps for QuickTime movies')
     73          if rescale_original_to_fill_texture_object:
     74              raise NotImplementedError('')
     75          width,height = self.size
     76          tex_shape = VisionEgg.Textures.next_power_of_2(max(width,height))
     77          # fractional coverage
     78          self.buf_lf = 0.0
     79          self.buf_rf = float(width)/tex_shape
     80          self.buf_bf = 0.0
     81          self.buf_tf = float(height)/tex_shape
     82
     83          # absolute (texel units) coverage
     84          self._buf_l = 0
     85          self._buf_r = width
     86          self._buf_b = 0
     87          self._buf_t = height
     88
     89          buffer = Numeric.zeros( (tex_shape,tex_shape), Numeric.UInt8 )
     90          texture_object.put_new_image( buffer,
     91                                        internal_format=gl.GL_RGB,
     92                                        mipmap_level=0 )
     93          self.texture_object = texture_object
     94
     95          self.gl_qt_renderer = VisionEgg.gl_qt.gl_qt_renderer_create(self.movie,tex_shape,self.scale)
     96
     97 -    def update(self):
     98          # only call this when my texture unit is active
     99          VisionEgg.gl_qt.gl_qt_renderer_update(self.gl_qt_renderer)
    100
    101 -    def __del__(self):
    102          VisionEgg.gl_qt.gl_qt_renderer_delete(self.gl_qt_renderer)
    103