# HG changeset patch # User ulion # Date 1197116103 0 # Node ID a6a49a7a4be0b5d9bea396462ffa275ba2527486 # Parent c48b33da31d32bba2f279705c137e618623e2f6f Move vobsub palette->yuv convert code into a common function. diff -r c48b33da31d3 -r a6a49a7a4be0 libmpdemux/demux_mkv.c --- a/libmpdemux/demux_mkv.c Sat Dec 08 04:29:11 2007 +0000 +++ b/libmpdemux/demux_mkv.c Sat Dec 08 12:15:03 2007 +0000 @@ -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 @@ 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 @@ { 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++; diff -r c48b33da31d3 -r a6a49a7a4be0 vobsub.c --- a/vobsub.c Sat Dec 08 04:29:11 2007 +0000 +++ b/vobsub.c Sat Dec 08 12:15:03 2007 +0000 @@ -13,6 +13,7 @@ #include #include #include +#include #include "config.h" #include "version.h" @@ -802,6 +803,21 @@ 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 @@ 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 @@ 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 == ',') diff -r c48b33da31d3 -r a6a49a7a4be0 vobsub.h --- a/vobsub.h Sat Dec 08 04:29:11 2007 +0000 +++ b/vobsub.h Sat Dec 08 12:15:03 2007 +0000 @@ -15,6 +15,9 @@ /// 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);