Author: ArcRiley
Date: 2007-07-07 05:46:39 -0400 (Sat, 07 Jul 2007)
New Revision: 398

Modified:
   trunk/pysoy/src/textures/Video.pxi
Log:
Ticket #273 : Video is now in color!  Color conversion code could be optimized  


Modified: trunk/pysoy/src/textures/Video.pxi
===================================================================
--- trunk/pysoy/src/textures/Video.pxi  2007-07-07 08:18:41 UTC (rev 397)
+++ trunk/pysoy/src/textures/Video.pxi  2007-07-07 09:46:39 UTC (rev 398)
@@ -23,7 +23,8 @@
      Renders an Ogg Theora stream to a texture
   '''
   cdef int _load(self, void *data) :
-    cdef int x, y
+    cdef int x, y, _cx, _cy, _tx, _ty, _yl, _yc
+    cdef float _py, _pu, _pv, _pr, _pg, _pb
     cdef ogg.ogg_page   *_page
     cdef ogg.yuv_buffer  _yuv
     cdef ogg.ogg_packet  _packet
@@ -58,7 +59,7 @@
             self._stage = -1
             return 0
         if ogg.ogg_page_pageno(_page) == 0 :
-          self._resize(1, self._squareup(self._info.frame_width),
+          self._resize(3, self._squareup(self._info.frame_width),
                           self._squareup(self._info.frame_height), 1)
           self._scaleX = <float> self._info.frame_width  / <float> self._width
           self._scaleY = <float> self._info.frame_height / <float> self._height
@@ -75,10 +76,36 @@
         ogg.theora_decode_packetin(&self._decode, &_packet)
         # _time=theora_granule_time(&self._decode, self._decode.granulepos)
         ogg.theora_decode_YUVout(&self._decode, &_yuv)
-        for y from 0 <= y < self._info.frame_height :
-          for x from 0 <= x < self._info.frame_width :
-            self._texels[((self._info.frame_height-y)*self._width)+x] = \
-              _yuv.y[(_yuv.y_stride*y)+x]
+        #
+        # cx/cy = chroma x/y due to 4:2:0
+        # tx/ty = texels x/y offset
+        # yl/yc = yuv l/c offsets
+        #
+        # This can and should be optimized further
+        _cx = self._info.frame_width 
+        _cy = self._info.frame_height
+        for y from 0 <= y < _cy :
+          _ty = (self._info.frame_height - y) * self._width
+          _yl = y * _yuv.y_stride
+          _yc = (y/2) * _yuv.uv_stride
+          for x from 0 <= x < _cx :
+            _tx = (_ty + x) * 3
+            _py = _yuv.y[_yl + x]
+            _pu = _yuv.u[_yc + (x/2)]
+            _pv = _yuv.v[_yc + (x/2)]
+            _pr = _py + ((<float> 1.370705) * (_pv-128))
+            _pg = _py - ((<float> 0.698001) * (_pv-128)) \
+                      - ((<float> 0.337633) * (_pu-128))
+            _pb = _py + ((<float> 1.732446) * (_pu-128))
+            if _pr < 0 : _pr = 0
+            if _pg < 0 : _pg = 0
+            if _pb < 0 : _pb = 0
+            if _pr > 255 : _pr = 255
+            if _pg > 255 : _pg = 255
+            if _pb > 255 : _pb = 255
+            self._texels[_tx  ] = <gl.GLubyte> _pr
+            self._texels[_tx+1] = <gl.GLubyte> _pg
+            self._texels[_tx+2] = <gl.GLubyte> _pb
         self._update = 1
     return 1
 

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

Reply via email to