mirror of
https://github.com/mpv-player/mpv
synced 2024-12-25 08:12:17 +00:00
Move vobsub palette->yuv convert code into a common function.
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@25320 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
460de55771
commit
151e8cceec
@ -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 char *start)
|
||||
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, const char *start)
|
||||
{
|
||||
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++;
|
||||
|
27
vobsub.c
27
vobsub.c
@ -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 char *line)
|
||||
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, const char *line)
|
||||
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, const char *line)
|
||||
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 == ',')
|
||||
|
3
vobsub.h
3
vobsub.h
@ -15,6 +15,9 @@ extern int vobsub_get_id_by_index(void *vobhandle, unsigned int index);
|
||||
/// 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);
|
||||
|
Loading…
Reference in New Issue
Block a user