summaryrefslogtreecommitdiff
path: root/cad/src/experimental/animations/borders.py
blob: 54e70935ce896248275915d33ac3a2cbd4a5e726 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/python

# Copyright 2006-2007 Nanorex, Inc.  See LICENSE file for details.
import os

# Make up a DVD that tests the borders on a television, to find out
# how big the borders need to be. Start with a black field and a white
# horizontal rectangle, and a text display of the number of border
# pixels as the white rectangle grows horizontally. Then do a vertical
# rectangle. The whole thing should be a ten-second animation maybe.

# Start with black.jpg, a 600x450 black image.

# The outcome of this test, with my television and my DVD player, is
# that a 600x450 graphic should have a border that shrinks it to
# 520x420 in order to keep things visible.

def do(cmd):
    print cmd
    if os.system(cmd) != 0:
        raise Exception

def fillHorizontal(border, filename):
    left = border / 2
    right = 600 - left
    cmd = 'convert'
    cmd += ' -fill white'
    cmd += ' -draw "rectangle %d,250 %d,350"' % (left, right)
    cmd += (' -font courier -pointsize 24 -draw' +
            ' "text 200, 110 \'Border test\'"')
    cmd += (' -font courier -pointsize 24 -draw' +
            ' "text 200, 150 \'%d/600 pixels\'"'
            % (right - left))
    cmd += ' black.jpg ' + filename
    do(cmd)

def fillVertical(border, filename):
    top = border / 2
    bottom = 450 - top
    cmd = 'convert'
    cmd += ' -fill white'
    cmd += ' -draw "rectangle 350,%d 450,%d"' % (top, bottom)
    cmd += (' -font courier -pointsize 24 -draw' +
            ' "rotate 90 text 130, -200 \'%d/450 pixels\'"'
            % (bottom - top))
    cmd += ' black.jpg ' + filename
    do(cmd)

yuv_num = 0

def oneSecond(func, param, yuvname):
    global yuv_num
    func(param, yuvname)
    for j in range(1, 30):
        do('cp %s %s' % (yuvname, 'foo.%06d.yuv' % yuv_num))
        yuv_num += 1

for i in range(0, 100, 10):
    yuvname = 'foo.%06d.yuv' % yuv_num
    yuv_num += 1
    oneSecond(fillHorizontal, i, yuvname)

for i in range(0, 100, 10):
    yuvname = 'foo.%06d.yuv' % yuv_num
    yuv_num += 1
    oneSecond(fillVertical, i, yuvname)

do('mpeg2encode foo.par foo.mpeg')
do('rm -f foo.00*.yuv')
do('ffmpeg -i foo.mpeg -sameq foo.mp4')