Mercurial > hg > pydct
changeset 3:b5e69130d7e9
4x4 speedup
author | Peter Meerwald <pmeerw@cosy.sbg.ac.at> |
---|---|
date | Fri, 16 May 2008 17:39:31 +0200 |
parents | 5bac33d0dad6 |
children | dd4db26f874e |
files | pydct/t4x4.py |
diffstat | 1 files changed, 26 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/pydct/t4x4.py Wed May 07 00:02:48 2008 +0200 +++ b/pydct/t4x4.py Fri May 16 17:39:31 2008 +0200 @@ -1,39 +1,41 @@ import numpy +_fc = numpy.array( + [[ 1, 1, 1, 1], + [ 2, 1, -1, -2], + [ 1, -1, -1, 1], + [ 1, -2, 2, -1]], numpy.float) +_fc = _fct.T +_fe = numpy.array( + [[0.25, 0.15811388, 0.25, 0.15811388], + [0.15811388, 0.1, 0.15811388, 0.1], + [0.25, 0.15811388, 0.25, 0.15811388], + [0.15811388, 0.1, 0.15811388, 0.1]], numpy.float) + +_ic = numpy.array( + [[1, 1, 1, 0.5], + [1, 0.5, -1, -1], + [1, -0.5, -1, 1], + [1, -1, 1, -0.5]], numpy.float) +_ict = _iec.T +_ie = numpy.array( + [[0.25, 0.31622777, 0.25, 0.31622777], + [0.31622777, 0.4, 0.31622777, 0.4], + [0.25, 0.31622777, 0.25, 0.31622777], + [0.31622777, 0.4, 0.31622777, 0.4]], numpy.float) + def fdct4x4(b): ''' Compute the approximate 4x4 DCT coefficients of an array as defined by H.264/AVC. ''' - c, e = \ - numpy.array( - [[ 1, 1, 1, 1], - [ 2, 1, -1, -2], - [ 1, -1, -1, 1], - [ 1, -2, 2, -1]], numpy.float), \ - numpy.array( - [[0.25, 0.15811388, 0.25, 0.15811388], - [0.15811388, 0.1, 0.15811388, 0.1], - [0.25, 0.15811388, 0.25, 0.15811388], - [0.15811388, 0.1, 0.15811388, 0.1]], numpy.float) - return numpy.dot(c, numpy.dot(b, numpy.transpose(c))) * e + return numpy.dot(_fc, numpy.dot(b, _fct)) * _fe def idct4x4(b): ''' Compute the inverse 4x4 DCT of the array. ''' - c, e = \ - numpy.array( - [[1, 1, 1, 0.5], - [1, 0.5, -1, -1], - [1, -0.5, -1, 1], - [1, -1, 1, -0.5]], numpy.float), \ - numpy.array( - [[0.25, 0.31622777, 0.25, 0.31622777], - [0.31622777, 0.4, 0.31622777, 0.4], - [0.25, 0.31622777, 0.25, 0.31622777], - [0.31622777, 0.4, 0.31622777, 0.4]], numpy.float) - return numpy.dot(c, numpy.dot(b*e, numpy.transpose(c))) + return numpy.dot(_ic, numpy.dot(b*_ie, _ict))