FFmpeg
Loading...
Searching...
No Matches
spherical.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2016 Vittorio Giovara <vittorio.giovara@gmail.com>
3 *
4 * This file is part of FFmpeg.
5 *
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * FFmpeg 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 GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21#include "avstring.h"
22#include "macros.h"
23#include "mem.h"
24#include "spherical.h"
25
27{
29
30 if (size)
31 *size = spherical ? sizeof(*spherical) : 0;
32
33 if (!spherical)
34 return NULL;
35
37
38 return spherical;
39}
40
42 size_t width, size_t height,
43 size_t *left, size_t *top,
44 size_t *right, size_t *bottom)
45{
46 /* conversion from 0.32 coordinates to pixels */
47 uint64_t orig_width = (uint64_t) width * UINT32_MAX /
48 (UINT32_MAX - map->bound_right - map->bound_left);
49 uint64_t orig_height = (uint64_t) height * UINT32_MAX /
50 (UINT32_MAX - map->bound_bottom - map->bound_top);
51
52 /* add a (UINT32_MAX - 1) to round up integer division */
53 *left = (orig_width * map->bound_left + UINT32_MAX - 1) / UINT32_MAX;
54 *top = (orig_height * map->bound_top + UINT32_MAX - 1) / UINT32_MAX;
55 *right = orig_width - width - *left;
56 *bottom = orig_height - height - *top;
57}
58
59static const char *const spherical_projection_names[] = {
60 [AV_SPHERICAL_EQUIRECTANGULAR] = "equirectangular",
61 [AV_SPHERICAL_CUBEMAP] = "cubemap",
62 [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular",
63 [AV_SPHERICAL_HALF_EQUIRECTANGULAR] = "half equirectangular",
64 [AV_SPHERICAL_RECTILINEAR] = "rectilinear",
65 [AV_SPHERICAL_FISHEYE] = "fisheye",
66 [AV_SPHERICAL_PARAMETRIC_IMMERSIVE] = "parametric immersive",
67};
68
70{
71 if ((unsigned)projection >= FF_ARRAY_ELEMS(spherical_projection_names))
72 return "unknown";
73
74 return spherical_projection_names[projection];
75}
76
78{
79 int i;
80
83 return i;
84 }
85
86 return -1;
87}
static int BS_FUNC left(const BSCTX *bc)
Return the number of the bits left in a buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define NULL
Definition coverity.c:32
int av_strstart(const char *str, const char *pfx, const char **ptr)
Return non-zero if pfx is a prefix of str.
Definition avstring.c:36
AVSphericalMapping * av_spherical_alloc(size_t *size)
Allocate a AVSphericalVideo structure and initialize its fields to default values.
Definition spherical.c:26
int av_spherical_from_name(const char *name)
Get the AVSphericalProjection form a human-readable name.
Definition spherical.c:77
AVSphericalProjection
Projection of the video surface(s) on a sphere.
Definition spherical.h:47
const char * av_spherical_projection_name(enum AVSphericalProjection projection)
Provide a human-readable name of a given AVSphericalProjection.
Definition spherical.c:69
void av_spherical_tile_bounds(const AVSphericalMapping *map, size_t width, size_t height, size_t *left, size_t *top, size_t *right, size_t *bottom)
Convert the bounding fields from an AVSphericalVideo from 0.32 fixed point to pixels.
Definition spherical.c:41
@ AV_SPHERICAL_RECTILINEAR
Video frame displays on a flat, rectangular 2D surface.
Definition spherical.h:78
@ AV_SPHERICAL_EQUIRECTANGULAR
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition spherical.h:52
@ AV_SPHERICAL_EQUIRECTANGULAR_TILE
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection.
Definition spherical.h:68
@ AV_SPHERICAL_CUBEMAP
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
Definition spherical.h:61
@ AV_SPHERICAL_HALF_EQUIRECTANGULAR
Video frame displays as a 180 degree equirectangular projection.
Definition spherical.h:73
@ AV_SPHERICAL_PARAMETRIC_IMMERSIVE
Parametric Immersive projection (Apple).
Definition spherical.h:90
@ AV_SPHERICAL_FISHEYE
Fisheye projection (Apple).
Definition spherical.h:84
const VDPAUPixFmtMap * map
Utility Preprocessor macros.
Memory handling functions.
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
static const char *const spherical_projection_names[]
Definition spherical.c:59
Spherical video.
This structure describes how to handle spherical videos, outlining information about projection,...
Definition spherical.h:100
enum AVSphericalProjection projection
Projection type.
Definition spherical.h:104
#define av_mallocz(s)
#define height
Definition dsp.h:89
#define width
Definition dsp.h:89
int size