Source

pygame / examples_pygame / overlay.py

aholkner 0f3a0f7 


























aholkner 28f5574 
aholkner 0f3a0f7 

























#! /bin/env python

import sys
import pygame

SR= (800,600)
ovl= None

########################################################################
# Simple video player 
def vPlayer( fName ):
    global ovl
    f= open( fName, 'rb' )
    fmt= f.readline().strip()
    res= f.readline().strip()
    col= f.readline().strip()
    if fmt!= "P5":
        print 'Unknown format( len %d ). Exiting...' % len( fmt )
        return
    
    w,h= [ int(x) for x in res.split( ' ' ) ]
    h= ( h* 2 )/ 3
    # Read into strings
    y= f.read( w*h )
    u= []
    v= []
    for i in xrange( 0, h/2 ):
        v.append( f.read( w/2 ))
        u.append( f.read( w/2 ))
    
    u= ''.join(u)
    v= ''.join(v)
    
    # Open overlay with the resolution specified
    ovl= pygame.Overlay(pygame.YV12_OVERLAY, (w,h))
    ovl.set_location(0, 0, w, h)
    
    ovl.display((y,u,v))
    while 1:
        pygame.time.wait(10)
        for ev in pygame.event.get():
            if ev.type in (pygame.KEYDOWN, pygame.QUIT): 
                return


# Test all modules
if __name__== '__main__':
    if len( sys.argv )!= 2:
        print "Usage: play_file <file_pattern>"
    else:
        pygame.init()
        pygame.display.set_mode(SR)
        vPlayer(sys.argv[1])
        pygame.quit()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.