[xiph-commits] r16619 - trunk/theora/examples

gmaxwell at svn.xiph.org gmaxwell at svn.xiph.org
Tue Oct 6 22:30:47 PDT 2009


Author: gmaxwell
Date: 2009-10-06 22:30:46 -0700 (Tue, 06 Oct 2009)
New Revision: 16619

Modified:
   trunk/theora/examples/player_example.c
Log:
player_example.c: Eliminate floats from initialization; switch to more accurate coefficients and use all available precision (doesn't matter, but why not?)

Modified: trunk/theora/examples/player_example.c
===================================================================
--- trunk/theora/examples/player_example.c	2009-10-05 21:06:00 UTC (rev 16618)
+++ trunk/theora/examples/player_example.c	2009-10-07 05:30:46 UTC (rev 16619)
@@ -116,7 +116,20 @@
 static int lu_GU[256];
 static int lu_GV[256];
 static int lu_B[256];
+#define OC_CLAMP255(_x)     ((unsigned char)((((_x)<0)-1)&((_x)|-((_x)>255))))
 
+static void init_yuv2rgb() {
+  int i;
+  for(i=0;i<256;i++)
+  {
+    lu_Y[i]  =  2441889*(i- 16) + 1048576;
+    lu_R[i]  =  3347111*(i-128);
+    lu_GV[i] = -1704917*(i-128);
+    lu_GU[i] =  -821585*(i-128);
+    lu_B[i]  =  4230442*(i-128);
+  }
+}
+
 /* single frame video buffering */
 int          videobuf_ready=0;
 ogg_int64_t  videobuf_granulepos=-1;
@@ -166,17 +179,6 @@
 int          audiofd=-1;
 ogg_int64_t  audiofd_timer_calibrate=-1;
 
-static void init_yuv2rgb() {
-  int i;
-  for(i=0;i<256;i++)
-  {
-    lu_Y[i]  = (int)(  1.1644*(i- 16)*32768.0+0.5)+(1<<14);
-    lu_R[i]  = (int)(   1.596*(i-128)*32768.0+0.5);
-    lu_GU[i] = (int)(-0.39176*(i-128)*32768.0+0.5); 
-    lu_GV[i] = (int)(-0.81297*(i-128)*32768.0+0.5);
-    lu_B[i]  = (int)(  2.0172*(i-128)*32768.0+0.5);
-  }
-}
 
 static void open_audio(){
   audio_buf_info info;
@@ -414,12 +416,12 @@
       for (j=0;j<screen->w;j++) {
         int r, g, b;
         int y = lu_Y[in_y[j]];
-        b=(y + lu_B[in_u[j]])>>15;
-        out[j*4]     = ((b) > 255 ? 255 : (b) < 0 ? 0 : (b));
-        g=(y + lu_GV[in_v[j]] + lu_GU[in_u[j]])>>15;
-        out[j*4+1]   = ((g) > 255 ? 255 : (g) < 0 ? 0 : (g));
-        r=(y + lu_R[in_v[j]])>>15;
-        out[j*4+2]   = ((r) > 255 ? 255 : (r) < 0 ? 0 : (r));
+        b=(y + lu_B[in_u[j]])>>21;
+        out[j*4]     = OC_CLAMP255(b);
+        g=(y + lu_GV[in_v[j]] + lu_GU[in_u[j]])>>21;
+        out[j*4+1]   = OC_CLAMP255(g);
+        r=(y + lu_R[in_v[j]])>>21;
+        out[j*4+2]   = OC_CLAMP255(r);
       }  
       output=SDL_CreateRGBSurfaceFrom(RGBbuffer,screen->w,screen->h,32,4*screen->w,0,0,0,0);
       SDL_BlitSurface(output,NULL,screen,NULL);



More information about the commits mailing list