Coverage Report

Created: 2025-07-11 06:16

/src/vlc/src/misc/viewpoint.c
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * viewpoint.c: viewpoint helpers for conversions and transformations
3
 *****************************************************************************
4
 * Copyright (C) 2019 VLC authors and VideoLAN
5
 *
6
 * Authors: Alexandre Janniaux <ajanni@videolabs.io>
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
#ifdef HAVE_CONFIG_H
24
# include "config.h"
25
#endif
26
27
#include <vlc_viewpoint.h>
28
#include <vlc_es.h>
29
30
void vlc_viewpoint_to_4x4( const vlc_viewpoint_t *vp, float *m )
31
0
{
32
0
    float yaw   = -vp->yaw   * (float)M_PI / 180.f;
33
0
    float pitch = -vp->pitch * (float)M_PI / 180.f;
34
0
    float roll  = -vp->roll  * (float)M_PI / 180.f;
35
36
0
    float s, c;
37
38
0
    s = sinf(pitch);
39
0
    c = cosf(pitch);
40
0
    const float x_rot[4][4] = {
41
0
        { 1.f,    0.f,    0.f,    0.f },
42
0
        { 0.f,    c,      -s,      0.f },
43
0
        { 0.f,    s,      c,      0.f },
44
0
        { 0.f,    0.f,    0.f,    1.f } };
45
46
0
    s = sinf(yaw);
47
0
    c = cosf(yaw);
48
0
    const float y_rot[4][4] = {
49
0
        { c,      0.f,    s,     0.f },
50
0
        { 0.f,    1.f,    0.f,    0.f },
51
0
        { -s,      0.f,    c,      0.f },
52
0
        { 0.f,    0.f,    0.f,    1.f } };
53
54
0
    s = sinf(roll);
55
0
    c = cosf(roll);
56
0
    const float z_rot[4][4] = {
57
0
        { c,      s,      0.f,    0.f },
58
0
        { -s,     c,      0.f,    0.f },
59
0
        { 0.f,    0.f,    1.f,    0.f },
60
0
        { 0.f,    0.f,    0.f,    1.f } };
61
62
    /**
63
     * Column-major matrix multiplication mathematically equal to
64
     * z_rot * x_rot * y_rot
65
     */
66
0
    memset(m, 0, 16 * sizeof(float));
67
0
    for (int i=0; i<4; ++i)
68
0
        for (int j=0; j<4; ++j)
69
0
            for (int k=0; k<4; ++k)
70
0
                for (int l=0; l<4; ++l)
71
0
                    m[4*i+l] += y_rot[i][j] * x_rot[j][k] * z_rot[k][l];
72
0
}
73
74
void vlc_viewpoint_from_orientation(vlc_viewpoint_t *vp,
75
                                    video_orientation_t orient)
76
0
{
77
0
    switch(orient)
78
0
    {
79
0
        default:
80
0
        case ORIENT_NORMAL:
81
0
        case ORIENT_HFLIPPED:
82
0
            vlc_viewpoint_from_euler(vp, 0.f, 0.f, 0.f);
83
0
            break;
84
85
0
        case ORIENT_ROTATED_90:
86
0
        case ORIENT_ANTI_TRANSPOSED:
87
0
            vlc_viewpoint_from_euler(vp, 0.f, 0.f, -90.f);
88
0
            break;
89
90
0
        case ORIENT_ROTATED_180:
91
0
        case ORIENT_VFLIPPED:
92
0
            vlc_viewpoint_from_euler(vp, 0.f, 0.f, -180.f);
93
0
            break;
94
0
        case ORIENT_ROTATED_270:
95
0
        case ORIENT_TRANSPOSED:
96
0
            vlc_viewpoint_from_euler(vp, 0.f, 0.f, -270.f);
97
0
            break;
98
0
    }
99
0
}
100
101
void vlc_viewpoint_from_euler(vlc_viewpoint_t *vp,
102
                              float yaw, float pitch, float roll)
103
0
{
104
0
    vp->yaw   = yaw;
105
0
    vp->pitch = pitch;
106
0
    vp->roll  = roll;
107
0
}
108
109
void vlc_viewpoint_to_euler(const vlc_viewpoint_t *vp,
110
                            float *yaw, float *pitch, float *roll)
111
0
{
112
0
    *yaw   = vp->yaw;
113
0
    *pitch = vp->pitch;
114
0
    *roll  = vp->roll;
115
0
}