Coverage Report

Created: 2025-08-25 07:17

/src/vlc/modules/demux/vobsub.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * vobsub.h: Vobsub support
3
 *****************************************************************************
4
 * Copyright (C) 2009 VLC authors and VideoLAN
5
 *
6
 * Authors: John Stebbins
7
 *
8
 * This program is free software; you can redistribute it and/or modify it
9
 * under the terms of the GNU Lesser General Public License as published by
10
 * the Free Software Foundation; either version 2.1 of the License, or
11
 * (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
 * GNU Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public License
19
 * along with this program; if not, write to the Free Software Foundation,
20
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21
 *****************************************************************************/
22
23
static inline void vobsub_palette_argb2ayvu( const uint32_t *src, uint32_t *dst )
24
0
{
25
0
    int i;
26
0
    for( i = 0; i < VIDEO_PALETTE_CLUT_COUNT; i++ )
27
0
    {
28
0
        uint8_t r, g, b, y, u, v;
29
0
        r = (src[i] >> 16) & 0xff;
30
0
        g = (src[i] >> 8) & 0xff;
31
0
        b = (src[i] >> 0) & 0xff;
32
0
        y = (uint8_t) __MIN(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);
33
0
        u = (uint8_t) __MIN(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);
34
0
        v = (uint8_t) __MIN(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
35
0
        dst[i] = (y&0xff)<<16 | (v&0xff)<<8 | (u&0xff);
36
0
    }
37
0
}
38
39
static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palette )
40
0
{
41
0
    uint32_t palette[VIDEO_PALETTE_CLUT_COUNT];
42
0
    if( sscanf( psz_buf, "palette: "
43
0
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
44
0
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
45
0
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
46
0
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 "",
47
0
                &palette[0], &palette[1], &palette[2], &palette[3],
48
0
                &palette[4], &palette[5], &palette[6], &palette[7],
49
0
                &palette[8], &palette[9], &palette[10], &palette[11],
50
0
                &palette[12], &palette[13], &palette[14], &palette[15] ) == ARRAY_SIZE(palette) )
51
0
    {
52
0
        vobsub_palette_argb2ayvu( palette, pu_palette );
53
0
        return VLC_SUCCESS;
54
0
    }
55
0
    else
56
0
    {
57
0
        return VLC_EGENERIC;
58
0
    }
59
0
}
60
61
static inline int vobsub_size_parse( const char *psz_buf,
62
                                     unsigned *pi_original_frame_width,
63
                                     unsigned *pi_original_frame_height )
64
0
{
65
0
    unsigned w, h;
66
0
    if( sscanf( psz_buf, "size: %ux%u", &w, &h ) == 2 )
67
0
    {
68
0
        *pi_original_frame_width = w;
69
0
        *pi_original_frame_height = h;
70
0
        return VLC_SUCCESS;
71
0
    }
72
0
    else
73
0
    {
74
0
        return VLC_EGENERIC;
75
0
    }
76
0
}
77
78
static inline void vobsub_extra_parse(vlc_object_t *o, subs_format_t *subs,
79
                                      const uint8_t *buf, size_t buf_size)
80
0
{
81
0
    char *psz_start;
82
0
    char *psz_buf = (char*)malloc( buf_size + 1);
83
0
    if( unlikely( psz_buf == NULL ) )
84
0
        return;
85
86
0
    memcpy( psz_buf, buf, buf_size );
87
0
    psz_buf[buf_size] = '\0';
88
89
0
    psz_start = strstr( psz_buf, "size:" );
90
0
    if( psz_start &&
91
0
        vobsub_size_parse( psz_start,
92
0
                            &subs->spu.i_original_frame_width,
93
0
                            &subs->spu.i_original_frame_height ) == VLC_SUCCESS )
94
0
    {
95
0
        msg_Dbg( o, "original frame size: %ux%u",
96
0
                    subs->spu.i_original_frame_width,
97
0
                    subs->spu.i_original_frame_height );
98
0
    }
99
0
    else
100
0
    {
101
0
        msg_Warn( o, "reading original frame size failed" );
102
0
    }
103
104
0
    psz_start = strstr( psz_buf, "palette:" );
105
0
    if( psz_start &&
106
0
        vobsub_palette_parse( psz_start, subs->spu.palette ) == VLC_SUCCESS )
107
0
    {
108
0
        subs->spu.b_palette = true;
109
0
        msg_Dbg( o, "vobsub palette read" );
110
0
    }
111
0
    else
112
0
    {
113
0
        msg_Warn( o, "reading original palette failed" );
114
0
    }
115
0
    free( psz_buf );
116
0
}