[MPlayer-cvslog] r25320 - in trunk: libmpdemux/demux_mkv.c vobsub.c vobsub.h

ulion subversion at mplayerhq.hu
Sat Dec 8 13:15:04 CET 2007


Author: ulion
Date: Sat Dec  8 13:15:03 2007
New Revision: 25320

Log:
Move vobsub palette->yuv convert code into a common function.


Modified:
   trunk/libmpdemux/demux_mkv.c
   trunk/vobsub.c
   trunk/vobsub.h

Modified: trunk/libmpdemux/demux_mkv.c
==============================================================================
--- trunk/libmpdemux/demux_mkv.c	(original)
+++ trunk/libmpdemux/demux_mkv.c	Sat Dec  8 13:15:03 2007
@@ -22,6 +22,7 @@
 #include "mp_msg.h"
 #include "help_mp.h"
 
+#include "vobsub.h"
 #include "subreader.h"
 #include "libvo/sub.h"
 
@@ -305,7 +306,7 @@ vobsub_parse_size (sh_sub_t *sh, const c
 static int
 vobsub_parse_palette (sh_sub_t *sh, const char *start)
 {
-  int i, r, g, b, y, u, v, tmp;
+  int i, tmp;
 
   start += 8;
   while (isspace(*start))
@@ -314,14 +315,7 @@ vobsub_parse_palette (sh_sub_t *sh, cons
     {
       if (sscanf(start, "%06x", &tmp) != 1)
         break;
-      r = tmp >> 16 & 0xff;
-      g = tmp >> 8 & 0xff;
-      b = tmp & 0xff;
-      y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
-      u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
-      v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
-      y = y * 219 / 255 + 16;
-      sh->palette[i] = y << 16 | u << 8 | v;
+      sh->palette[i] = vobsub_palette_to_yuv(tmp);
       start += 6;
       while ((*start == ',') || isspace(*start))
         start++;

Modified: trunk/vobsub.c
==============================================================================
--- trunk/vobsub.c	(original)
+++ trunk/vobsub.c	Sat Dec  8 13:15:03 2007
@@ -13,6 +13,7 @@
 #include <unistd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
+#include <math.h>
 
 #include "config.h"
 #include "version.h"
@@ -802,6 +803,21 @@ vobsub_parse_origin(vobsub_t *vob, const
     return 0;
 }
 
+unsigned int vobsub_palette_to_yuv(unsigned int pal)
+{
+    int r, g, b, y, u, v;
+    // Palette in idx file is not rgb value, it was calculated by wrong forumla.
+    // Here's reversed forumla of the one used to generate palette in idx file.
+    r = pal >> 16 & 0xff;
+    g = pal >> 8 & 0xff;
+    b = pal & 0xff;
+    y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
+    u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
+    v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
+    y = y * 219 / 255 + 16;
+    return y << 16 | u << 8 | v;
+}
+
 static int
 vobsub_parse_palette(vobsub_t *vob, const char *line)
 {
@@ -810,7 +826,7 @@ vobsub_parse_palette(vobsub_t *vob, cons
     n = 0;
     while (1) {
 	const char *p;
-	int r, g, b, y, u, v, tmp;
+	int tmp;
 	while (isspace(*line))
 	    ++line;
 	p = line;
@@ -819,14 +835,7 @@ vobsub_parse_palette(vobsub_t *vob, cons
 	if (p - line != 6)
 	    return -1;
 	tmp = strtoul(line, NULL, 16);
-	r = tmp >> 16 & 0xff;
-	g = tmp >> 8 & 0xff;
-	b = tmp & 0xff;
-	y = av_clip_uint8( 0.1494  * r + 0.6061 * g + 0.2445 * b);
-	u = av_clip_uint8( 0.6066  * r - 0.4322 * g - 0.1744 * b + 128);
-	v = av_clip_uint8(-0.08435 * r - 0.3422 * g + 0.4266 * b + 128);
-	y = y * 219 / 255 + 16;
-	vob->palette[n++] = y << 16 | u << 8 | v;
+	vob->palette[n++] = vobsub_palette_to_yuv(tmp);
 	if (n == 16)
 	    break;
 	if (*p == ',')

Modified: trunk/vobsub.h
==============================================================================
--- trunk/vobsub.h	(original)
+++ trunk/vobsub.h	Sat Dec  8 13:15:03 2007
@@ -15,6 +15,9 @@ extern int vobsub_get_id_by_index(void *
 /// Get index in the valid streams by vobsub id.
 extern int vobsub_get_index_by_id(void *vobhandle, int id);
 
+/// Convert palette value in idx file to yuv.
+unsigned int vobsub_palette_to_yuv(unsigned int pal);
+
 extern void *vobsub_out_open(const char *basename, const unsigned int *palette, unsigned int orig_width, unsigned int orig_height, const char *id, unsigned int index);
 extern void vobsub_out_output(void *me, const unsigned char *packet, int len, double pts);
 extern void vobsub_out_close(void *me);



More information about the MPlayer-cvslog mailing list