[xiph-commits] r3154 - liboggplay/trunk/src/tools

shans at svn.annodex.net shans at svn.annodex.net
Mon Jul 2 15:53:38 PDT 2007


Author: shans
Date: 2007-07-02 15:53:38 -0700 (Mon, 02 Jul 2007)
New Revision: 3154

Modified:
   liboggplay/trunk/src/tools/Makefile.am
   liboggplay/trunk/src/tools/dump-first-frame.c
   liboggplay/trunk/src/tools/glut-player.c
Log:
Added slow, non-mmx based implementation of rgb2yuv to dump-first-frame; it now works.



Modified: liboggplay/trunk/src/tools/Makefile.am
===================================================================
--- liboggplay/trunk/src/tools/Makefile.am	2007-07-02 06:48:07 UTC (rev 3153)
+++ liboggplay/trunk/src/tools/Makefile.am	2007-07-02 22:53:38 UTC (rev 3154)
@@ -44,7 +44,7 @@
 dump_first_frame_LDADD = $(OGGPLAY_LIBS) @IMLIB2_LIBS@
 
 glut_player_SOURCES = glut-player.c
-glut_player_LDADD = $(OGGPLAY_LIBS) @GLUT_LIBS@ 
+glut_player_LDADD = $(OGGPLAY_LIBS) @GLUT_LIBS@
 if MACOS
 # Automake 1.6 doesn't recoginze -framework arguments as libraries
 # so we must pass them through LDFLAGS

Modified: liboggplay/trunk/src/tools/dump-first-frame.c
===================================================================
--- liboggplay/trunk/src/tools/dump-first-frame.c	2007-07-02 06:48:07 UTC (rev 3153)
+++ liboggplay/trunk/src/tools/dump-first-frame.c	2007-07-02 22:53:38 UTC (rev 3154)
@@ -14,8 +14,6 @@
 write_png_file(char *fname, OggPlayRGBChannels *data) {
 
   Imlib_Image *image;
-  int i;
-  int j;
   
   /*
   for (i = 0; i < data->rgb_height; i++) {
@@ -27,15 +25,7 @@
     }
   }*/
   FILE *f = fopen("out.rgb", "wb");
-  for (i = 0; i < data->rgb_height; i++) {
-    for (j = 0; j < data->rgb_width; j++) {
-      char *ptr = data->ptro + i * data->rgb_width * 4 + j * 4;
-      int *iptr = (int *)ptr;
-      fwrite(iptr, 4, 1, f);
-      //*iptr = 0xFF000000 | (((int)(ptr[0])) << 16) | (((int)(ptr[2])) << 8)
-      //    | ptr[3];
-    }
-  }
+  fwrite(data->ptro, data->rgb_width * data->rgb_height, 4, f);
   fclose(f);
   
 
@@ -49,16 +39,63 @@
 
 }
 
+#define CLAMP(v)    ((v) > 255 ? 255 : (v) < 0 ? 0 : (v))
+
+void yuv2rgb(OggPlayYUVChannels * yuv, OggPlayRGBChannels * rgb) {
+
+  unsigned char * ptry = yuv->ptry;
+  unsigned char * ptru = yuv->ptru;
+  unsigned char * ptrv = yuv->ptrv;
+  unsigned char * ptro = rgb->ptro;
+  unsigned char * ptro2;
+  int i, j;
+
+  for (i = 0; i < yuv->y_height; i++) {
+    ptro2 = ptro;
+    for (j = 0; j < yuv->y_width; j += 2) {
+
+      short pr, pg, pb;
+      short r, g, b;
+      
+    //pr = ((128 + (ptrv[j/2] - 128) * 292) >> 8) - 16; /* 1.14 * 256 */
+      pr = (-41344 + ptrv[j/2] * 292) >> 8;
+    //pg = ((128 - (ptru[j/2] - 128) * 101 - (ptrv[j/2] - 128) * 149) >> 8)-16; 
+    //                                /* 0.395 & 0.581 */
+      pg = (28032 - ptru[j/2] * 101 - ptrv[j/2] * 149) >> 8;
+    //pb = ((128 + (ptru[j/2] - 128) * 520) >> 8) - 16; /* 2.032 */
+      pb = (-70528 + ptru[j/2] * 520) >> 8;
+
+      r = ptry[j] + pr;
+      g = ptry[j] + pg;
+      b = ptry[j] + pb;
+
+      *ptro2++ = CLAMP(b);
+      *ptro2++ = CLAMP(g);
+      *ptro2++ = CLAMP(r);
+      *ptro2++ = 255;
+      
+      r = ptry[j + 1] + pr;
+      g = ptry[j + 1] + pg;
+      b = ptry[j + 1] + pb;
+      
+      *ptro2++ = CLAMP(b);
+      *ptro2++ = CLAMP(g);
+      *ptro2++ = CLAMP(r);
+      *ptro2++ = 255;
+    }
+    ptry += yuv->y_width;
+    if (i & 1) {
+      ptru += yuv->uv_width;
+      ptrv += yuv->uv_width;
+    }
+    ptro += rgb->rgb_width * 4;
+  }
+}
+
 void
 dump_video_data (OggPlay * player, int track_num, OggPlayVideoData * video_data,
                    int frame) {
 
-  char              fname[256];
-  FILE            * f;
-  FILE            * g;
-  int               i;
-  unsigned char   * ptr;
-  unsigned char   * ptr2;
   OggPlayYUVChannels  from;
   OggPlayRGBChannels  to;
 
@@ -70,6 +107,10 @@
   oggplay_get_video_uv_size(player, track_num, &(from.uv_width), 
             &(from.uv_height));
 
+  FILE *f = fopen("out.y", "wb");
+  fwrite(from.ptry, from.y_width * from.y_height, 1, f);
+  fclose(f);  
+
   printf("size: %dx%d %dx%d\n", from.y_width, from.y_height, from.uv_width,
       from.uv_height);
 
@@ -77,7 +118,7 @@
   to.rgb_width = from.y_width;
   to.rgb_height = from.y_height;
  
-  oggplay_yuv2rgb(&from, &to);
+  yuv2rgb(&from, &to);
   printf("now %dx%d\n", to.rgb_width, to.rgb_height);
 
   write_png_file("out.png", &to);
@@ -154,9 +195,8 @@
   for (i = 0; i < oggplay_get_num_tracks (player); i++) {
     if (oggplay_get_track_type (player, i) == OGGZ_CONTENT_THEORA) {
       oggplay_set_callback_num_frames (player, i, 1);
-      oggplay_set_track_active(player, i);
-      break;
     }
+    oggplay_set_track_active(player, i);
   }
 
   oggplay_set_data_callback(player, dump_streams_callback, NULL);

Modified: liboggplay/trunk/src/tools/glut-player.c
===================================================================
--- liboggplay/trunk/src/tools/glut-player.c	2007-07-02 06:48:07 UTC (rev 3153)
+++ liboggplay/trunk/src/tools/glut-player.c	2007-07-02 22:53:38 UTC (rev 3154)
@@ -132,7 +132,7 @@
   rgb.rgb_height = texture_height;  
 
   oggplay_yuv2rgb(&yuv, &rgb);
- 
+
 }
 
 static int              snd_fd = -1;



More information about the commits mailing list