Author: ArcRiley
Date: 2007-07-07 09:42:48 -0400 (Sat, 07 Jul 2007)
New Revision: 404

Added:
   trunk/pysoy/src/textures/_tables4YUV.pxi
Modified:
   trunk/pysoy/src/textures/Video.pxi
   trunk/pysoy/src/textures/soy.textures.pyx
Log:
this boosts YUV420->RGB8 conversion time by 50%


Modified: trunk/pysoy/src/textures/Video.pxi
===================================================================
--- trunk/pysoy/src/textures/Video.pxi  2007-07-07 12:34:37 UTC (rev 403)
+++ trunk/pysoy/src/textures/Video.pxi  2007-07-07 13:42:48 UTC (rev 404)
@@ -17,6 +17,7 @@
 #
 # $Id$
 
+
 cdef class Video (Texture) :
   '''PySoy textures.Video Class
 
@@ -87,8 +88,8 @@
         # yl/yc = yuv l/c offsets
         #
         # This can and should be optimized further
-        #gettimeofday(&_tv, NULL)
-        #_start = _tv.tv_sec + ( <double> _tv.tv_usec / 1000000.0 )
+        gettimeofday(&_tv, NULL)
+        _start = _tv.tv_sec + ( <double> _tv.tv_usec / 1000000.0 )
         _cx = self._info.frame_width 
         _cy = self._info.frame_height
         for y from 0 <= y < _cy :
@@ -98,29 +99,28 @@
           for x from 0 <= x < _cx :
             _tx = (_ty + x) * 3
             _py = _yuv.y[_yl + x]
-            _pu = _yuv.u[_yc + (x/2)] - 128
-            _pv = _yuv.v[_yc + (x/2)] - 128
-            _pr = <int> (_py + ((<float> 1.402) * _pv))
+            _pu = _yuv.u[_yc + (x/2)]
+            _pv = _yuv.v[_yc + (x/2)]
+            _pr = _py + _tableRV[_pv]
+            _pg = _py - _tableGV[_pv] - _tableGU[_pu]
+            _pb = _py + _tableBU[_pu]
             if _pr < 0 : 
               _pr = 0
+            if _pg < 0 : 
+              _pg = 0
+            if _pb < 0 : 
+              _pb = 0
             if _pr > 255 : 
               _pr = 255
-            self._texels[_tx  ] = _pr
-            _pg = <int> (_py - ((<float> 0.714) * _pv) \
-                             - ((<float> 0.344) * _pu))
-            if _pg < 0 : 
-              _pg = 0
             if _pg > 255 : 
               _pg = 255
-            self._texels[_tx+1] = _pg
-            _pb = <int> (_py + ((<float> 1.772) * _pu))
-            if _pb < 0 : 
-              _pb = 0
             if _pb > 255 : 
               _pb = 255
+            self._texels[_tx  ] = _pr
+            self._texels[_tx+1] = _pg
             self._texels[_tx+2] = _pb
-        #gettimeofday(&_tv, NULL)
-        #stdio.printf('%f\n', (_tv.tv_sec + ( <double> _tv.tv_usec / 1000000.0 
))- _start)
+        gettimeofday(&_tv, NULL)
+        stdio.printf('%f\n', (_tv.tv_sec + ( <double> _tv.tv_usec / 1000000.0 
))- _start)
         self._update = 1
     return 1
 

Copied: trunk/pysoy/src/textures/_tables4YUV.pxi (from rev 403, 
trunk/pysoy/src/textures/Video.pxi)
===================================================================
--- trunk/pysoy/src/textures/_tables4YUV.pxi                            (rev 0)
+++ trunk/pysoy/src/textures/_tables4YUV.pxi    2007-07-07 13:42:48 UTC (rev 
404)
@@ -0,0 +1,39 @@
+# PySoy's tables for YUV
+#
+# Copyright (C) 2007 Team PySoy
+#
+#  This program is free software; you can redistribute it and/or modify
+#  it under the terms of the GNU General Public License as published by
+#  the Free Software Foundation; either version 3 of the License, or
+#  (at your option) any later version.
+#
+#  This program is distributed in the hope that it will be useful,
+#  but WITHOUT ANY WARRANTY; without even the implied warranty of
+#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#  GNU General Public License for more details.
+#
+#  You should have received a copy of the GNU General Public License
+#  along with this program; if not, see http://www.gnu.org/licenses
+#
+# $Id$
+
+
+# Lookup table globals
+#
+# These tables speed up YUV->RGB conversion by moving the floating point math
+# from the per-frame/per-pixel loop to a one-shot run on module load.
+#
+cdef int i
+cdef int _tableRV[256]
+cdef int _tableGV[256]
+cdef int _tableGU[256]
+cdef int _tableBU[256]
+
+for i from 0 <= i < 256 :
+  _tableRV[i] = <int> ((<float> 1.402) * (i - 128.0))
+for i from 0 <= i < 256 :
+  _tableGV[i] = <int> ((<float> 0.714) * (i - 128.0))
+for i from 0 <= i < 256 :
+  _tableGU[i] = <int> ((<float> 0.344) * (i - 128.0))
+for i from 0 <= i < 256 :
+  _tableBU[i] = <int> ((<float> 1.772) * (i - 128.0))

Modified: trunk/pysoy/src/textures/soy.textures.pyx
===================================================================
--- trunk/pysoy/src/textures/soy.textures.pyx   2007-07-07 12:34:37 UTC (rev 
403)
+++ trunk/pysoy/src/textures/soy.textures.pyx   2007-07-07 13:42:48 UTC (rev 
404)
@@ -23,6 +23,7 @@
               'by '+'$Author$'[9:-2]
 __version__ = 'Trunk (r'+'$Rev$'[6:-2]+')'
 
+include "_tables4YUV.pxi"
 include "Texture.pxi"
 include "Image.pxi"
 include "Video.pxi"

_______________________________________________
PySoy-SVN mailing list
[email protected]
http://www.pysoy.org/mailman/listinfo/pysoy-svn

Reply via email to