Coverage Report

Created: 2025-07-18 07:04

/src/vlc/modules/codec/ttml/imageupdater.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * imageupdater.h : TTML image to SPU updater
3
 *****************************************************************************
4
 * Copyright © 2018 Videolabs, VideoLAN and VLC authors
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 *****************************************************************************/
19
#include <vlc_subpicture.h>
20
21
typedef struct ttml_image_updater_region_t ttml_image_updater_region_t;
22
23
struct ttml_image_updater_region_t
24
{
25
    struct
26
    {
27
        float x;
28
        float y;
29
    } origin, extent;
30
    int i_flags;
31
    picture_t *p_pic;
32
    ttml_image_updater_region_t *p_next;
33
};
34
35
enum ttml_image_updater_region_flags_e
36
{
37
    ORIGIN_X_IS_RATIO      = 1 << 0,
38
    ORIGIN_Y_IS_RATIO      = 1 << 1,
39
    EXTENT_X_IS_RATIO      = 1 << 2,
40
    EXTENT_Y_IS_RATIO      = 1 << 3,
41
};
42
43
static void TTML_ImageUpdaterRegionDelete(ttml_image_updater_region_t *p_updtregion)
44
0
{
45
0
    if (p_updtregion->p_pic)
46
0
        picture_Release(p_updtregion->p_pic);
47
0
    free(p_updtregion);
48
0
}
49
50
static ttml_image_updater_region_t *TTML_ImageUpdaterRegionNew(picture_t *p_pic)
51
0
{
52
0
    ttml_image_updater_region_t *p_region = calloc(1, sizeof(*p_region));
53
0
    if(p_region)
54
0
        p_region->p_pic = p_pic;
55
0
    return p_region;
56
0
}
57
58
/*
59
 * UPDATER
60
*/
61
62
typedef struct
63
{
64
    ttml_image_updater_region_t *p_regions;
65
    ttml_image_updater_region_t **pp_append;
66
67
} ttml_image_updater_sys_t;
68
69
static void TTML_ImageSpuAppendRegion(ttml_image_updater_sys_t *p_sys,
70
                                      ttml_image_updater_region_t *p_new)
71
0
{
72
0
    *p_sys->pp_append = p_new;
73
0
    p_sys->pp_append = &p_new->p_next;
74
0
}
75
76
static void TTML_ImageSpuUpdate(subpicture_t *p_spu,
77
                                const struct vlc_spu_updater_configuration *cfg)
78
0
{
79
0
    ttml_image_updater_sys_t *p_sys = p_spu->updater.sys;
80
0
    const video_format_t *p_fmt_dst = cfg->video_dst;
81
82
0
    if (p_fmt_dst->i_visible_width  == cfg->prev_dst->i_visible_width &&
83
0
        p_fmt_dst->i_visible_height == cfg->prev_dst->i_visible_height)
84
0
        return;
85
86
0
    vlc_spu_regions_Clear( &p_spu->regions );
87
88
    /* !WARN: SMPTE-TT image profile requires no scaling, and even it
89
              would, it does not store the necessary original pic size */
90
91
0
    for(ttml_image_updater_region_t *p_updtregion = p_sys->p_regions;
92
0
                                     p_updtregion; p_updtregion = p_updtregion->p_next)
93
0
    {
94
0
        subpicture_region_t *r = subpicture_region_ForPicture(p_updtregion->p_pic);
95
0
        if (unlikely(r == NULL))
96
0
            return;
97
98
0
        r->b_absolute = true; r->b_in_window = false;
99
0
        r->i_align = SUBPICTURE_ALIGN_LEFT|SUBPICTURE_ALIGN_TOP;
100
101
0
        if( p_updtregion->i_flags & ORIGIN_X_IS_RATIO )
102
0
            r->i_x = p_updtregion->origin.x * p_fmt_dst->i_visible_width;
103
0
        else
104
0
            r->i_x = p_updtregion->origin.x;
105
106
0
        if( p_updtregion->i_flags & ORIGIN_Y_IS_RATIO )
107
0
            r->i_y = p_updtregion->origin.y * p_fmt_dst->i_visible_height;
108
0
        else
109
0
            r->i_y = p_updtregion->origin.y;
110
111
0
        vlc_spu_regions_push(&p_spu->regions, r);
112
0
    }
113
0
}
114
115
static void TTML_ImageSpuDestroy(subpicture_t *p_spu)
116
0
{
117
0
    ttml_image_updater_sys_t *p_sys = p_spu->updater.sys;
118
0
    while(p_sys->p_regions)
119
0
    {
120
0
        ttml_image_updater_region_t *p_next = p_sys->p_regions->p_next;
121
0
        TTML_ImageUpdaterRegionDelete(p_sys->p_regions);
122
0
        p_sys->p_regions = p_next;
123
0
    }
124
0
    free(p_sys);
125
0
}
126
127
static inline subpicture_t *decoder_NewTTML_ImageSpu(decoder_t *p_dec)
128
0
{
129
0
    ttml_image_updater_sys_t *p_sys = calloc(1, sizeof(*p_sys));
130
0
    if(!p_sys)
131
0
        return NULL;
132
133
0
    static const struct vlc_spu_updater_ops spu_ops =
134
0
    {
135
0
        .update   = TTML_ImageSpuUpdate,
136
0
        .destroy  = TTML_ImageSpuDestroy,
137
0
    };
138
139
0
    subpicture_updater_t updater = {
140
0
        .sys = p_sys,
141
0
        .ops = &spu_ops,
142
0
    };
143
0
    p_sys->p_regions = NULL;
144
0
    p_sys->pp_append = &p_sys->p_regions;
145
0
    subpicture_t *p_spu = decoder_NewSubpicture(p_dec, &updater);
146
0
    if (!p_spu)
147
0
        free(p_sys);
148
0
    return p_spu;
149
0
}