[pypy-commit] extradoc extradoc: let the image class choose interpolation method, making multiple magnify() implemenattions unnecessery
hakanardo
noreply at buildbot.pypy.org
Tue Jun 21 20:15:37 CEST 2011
Author: Hakan Ardo <hakan at debian.org>
Branch: extradoc
Changeset: r3769:a7888203159e
Date: 2011-06-21 19:50 +0200
http://bitbucket.org/pypy/extradoc/changeset/a7888203159e/
Log: let the image class choose interpolation method, making multiple
magnify() implemenattions unnecessery
diff --git a/talk/iwtc11/benchmarks/image/magnify.py b/talk/iwtc11/benchmarks/image/magnify.py
--- a/talk/iwtc11/benchmarks/image/magnify.py
+++ b/talk/iwtc11/benchmarks/image/magnify.py
@@ -1,5 +1,9 @@
from plain import Image
-from math import atan2, sqrt, sin, cos, ceil, floor
+from math import atan2, sqrt, sin, cos, ceil, floor
+
+class NNImage(Image):
+ def __getitem__(self, (x, y)):
+ return Image.__getitem__(self, (int(x + 0.5), int(y + 0.5)))
class BilinImage(Image):
def __getitem__(self, (x, y)):
@@ -27,23 +31,6 @@
if r < maxr:
nr = r*r / maxr
nx, ny = nr*cos(a), nr*sin(a)
- out[x,y] = img[int(nx) + img.width/2, int(ny) + img.height/2]
- else:
- out[x,y] = img[x,y]
- return out
-
-def magnify_bilin(img):
- out = Image(img.width, img.height, typecode='B')
- out.data[:] = img.data
- maxr = img.height/3
- for y in xrange(img.height/2 - maxr, img.height/2 + maxr):
- for x in xrange(img.width/2 - maxr, img.width/2 + maxr):
- dx, dy = x - img.width/2, y - img.height/2
- a = atan2(dy, dx)
- r = sqrt(dx ** 2 + dy ** 2)
- if r < maxr:
- nr = r*r / maxr
- nx, ny = nr*cos(a), nr*sin(a)
out[x,y] = min(int(img[nx + img.width/2, ny + img.height/2]), 255)
else:
out[x,y] = img[x,y]
@@ -53,11 +40,21 @@
from io import mplayer, view
import sys
from time import time
+ from optparse import OptionParser
- if len(sys.argv) > 1:
- fn = sys.argv[1]
+ parser = OptionParser()
+ parser.add_option('-b', dest='bilin', action="store_true",
+ help="enable bilinear interpolation")
+ options, args = parser.parse_args()
+
+ if len(args) > 0:
+ fn = args[0]
else:
fn = 'test.avi -vf scale=640:480 -benchmark'
+ if options.bilin:
+ MyImage=BilinImage
+ else:
+ MyImage=NNImage
sys.setcheckinterval(2**30)
try:
@@ -67,9 +64,8 @@
pass
start = start0 = time()
- for fcnt, img in enumerate(mplayer(BilinImage, fn)):
- #view(magnify(img))
- view(magnify_bilin(img))
+ for fcnt, img in enumerate(mplayer(MyImage, fn)):
+ view(magnify(img))
print 1.0 / (time() - start), 'fps, ', (fcnt-2) / (time() - start0), 'average fps'
start = time()
if fcnt==2:
More information about the pypy-commit
mailing list