demux: libavi: force chunk type check
[vlc.git] / modules / demux / vobsub.h
blob4b9334fc3b974b54439efdcf9943ab6e3f744dd9
1 /*****************************************************************************
2 * vobsub.h: Vobsub support
3 *****************************************************************************
4 * Copyright (C) 2009 VLC authors and VideoLAN
5 * $Id$
7 * Authors: John Stebbins
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 static inline void vobsub_palette_rgb2yuv( uint32_t *pu_palette )
26 int i;
27 for( i = 0; i < 16; i++ )
29 uint8_t r, g, b, y, u, v;
30 r = (pu_palette[i] >> 16) & 0xff;
31 g = (pu_palette[i] >> 8) & 0xff;
32 b = (pu_palette[i] >> 0) & 0xff;
33 y = (uint8_t) __MIN(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);
34 u = (uint8_t) __MIN(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);
35 v = (uint8_t) __MIN(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
36 pu_palette[i] = (y&0xff)<<16 | (v&0xff)<<8 | (u&0xff);
40 static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palette )
42 if( sscanf( psz_buf, "palette: "
43 "%" PRIx32", %" PRIx32 ", %" PRIx32 ", %" PRIx32 ", "
44 "%" PRIx32", %" PRIx32 ", %" PRIx32 ", %" PRIx32 ", "
45 "%" PRIx32", %" PRIx32 ", %" PRIx32 ", %" PRIx32 ", "
46 "%" PRIx32", %" PRIx32 ", %" PRIx32 ", %" PRIx32 "",
47 &pu_palette[0], &pu_palette[1], &pu_palette[2], &pu_palette[3],
48 &pu_palette[4], &pu_palette[5], &pu_palette[6], &pu_palette[7],
49 &pu_palette[8], &pu_palette[9], &pu_palette[10], &pu_palette[11],
50 &pu_palette[12], &pu_palette[13], &pu_palette[14], &pu_palette[15] ) == 16 )
52 vobsub_palette_rgb2yuv( pu_palette );
53 return VLC_SUCCESS;
55 else
57 return VLC_EGENERIC;
61 static inline int vobsub_size_parse( const char *psz_buf,
62 int *pi_original_frame_width,
63 int *pi_original_frame_height )
65 if( sscanf( psz_buf, "size: %dx%d",
66 pi_original_frame_width, pi_original_frame_height ) == 2 )
68 return VLC_SUCCESS;
70 else
72 return VLC_EGENERIC;