Coverage Report

Created: 2026-02-05 06:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/demux/vobsub.h
Line
Count
Source
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
289
{
25
289
    int i;
26
4.91k
    for( i = 0; i < VIDEO_PALETTE_CLUT_COUNT; i++ )
27
4.62k
    {
28
4.62k
        uint8_t r, g, b, y, u, v;
29
4.62k
        r = (src[i] >> 16) & 0xff;
30
4.62k
        g = (src[i] >> 8) & 0xff;
31
4.62k
        b = (src[i] >> 0) & 0xff;
32
4.62k
        y = (uint8_t) __MIN(abs(r * 2104 + g * 4130 + b * 802 + 4096 + 131072) >> 13, 235);
33
4.62k
        u = (uint8_t) __MIN(abs(r * -1214 + g * -2384 + b * 3598 + 4096 + 1048576) >> 13, 240);
34
4.62k
        v = (uint8_t) __MIN(abs(r * 3598 + g * -3013 + b * -585 + 4096 + 1048576) >> 13, 240);
35
4.62k
        dst[i] = (y&0xff)<<16 | (v&0xff)<<8 | (u&0xff);
36
4.62k
    }
37
289
}
38
39
static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palette )
40
447
{
41
447
    uint32_t palette[VIDEO_PALETTE_CLUT_COUNT];
42
447
    if( sscanf( psz_buf, "palette: "
43
447
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
44
447
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
45
447
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 ", "
46
447
                "%" SCNx32", %" SCNx32 ", %" SCNx32 ", %" SCNx32 "",
47
447
                &palette[0], &palette[1], &palette[2], &palette[3],
48
447
                &palette[4], &palette[5], &palette[6], &palette[7],
49
447
                &palette[8], &palette[9], &palette[10], &palette[11],
50
447
                &palette[12], &palette[13], &palette[14], &palette[15] ) == ARRAY_SIZE(palette) )
51
289
    {
52
289
        vobsub_palette_argb2ayvu( palette, pu_palette );
53
289
        return VLC_SUCCESS;
54
289
    }
55
158
    else
56
158
    {
57
158
        return VLC_EGENERIC;
58
158
    }
59
447
}
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
578
{
65
578
    unsigned w, h;
66
578
    if( sscanf( psz_buf, "size: %ux%u", &w, &h ) == 2 )
67
471
    {
68
471
        *pi_original_frame_width = w;
69
471
        *pi_original_frame_height = h;
70
471
        return VLC_SUCCESS;
71
471
    }
72
107
    else
73
107
    {
74
107
        return VLC_EGENERIC;
75
107
    }
76
578
}
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
601
{
81
601
    char *psz_start;
82
601
    char *psz_buf = (char*)malloc( buf_size + 1);
83
601
    if( unlikely( psz_buf == NULL ) )
84
0
        return;
85
86
601
    memcpy( psz_buf, buf, buf_size );
87
601
    psz_buf[buf_size] = '\0';
88
89
601
    psz_start = strstr( psz_buf, "size:" );
90
601
    if( psz_start &&
91
578
        vobsub_size_parse( psz_start,
92
578
                            &subs->spu.i_original_frame_width,
93
578
                            &subs->spu.i_original_frame_height ) == VLC_SUCCESS )
94
471
    {
95
471
        msg_Dbg( o, "original frame size: %ux%u",
96
471
                    subs->spu.i_original_frame_width,
97
471
                    subs->spu.i_original_frame_height );
98
471
    }
99
130
    else
100
130
    {
101
130
        msg_Warn( o, "reading original frame size failed" );
102
130
    }
103
104
601
    psz_start = strstr( psz_buf, "palette:" );
105
601
    if( psz_start &&
106
447
        vobsub_palette_parse( psz_start, subs->spu.palette ) == VLC_SUCCESS )
107
289
    {
108
289
        subs->spu.b_palette = true;
109
289
        msg_Dbg( o, "vobsub palette read" );
110
289
    }
111
312
    else
112
312
    {
113
312
        msg_Warn( o, "reading original palette failed" );
114
312
    }
115
601
    free( psz_buf );
116
601
}