Coverage Report

Created: 2026-07-12 08:57

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