FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "mem.h"
22 #include "spherical.h"
23 
25 {
26  AVSphericalMapping *spherical = av_mallocz(sizeof(AVSphericalMapping));
27  if (!spherical)
28  return NULL;
29 
30  if (size)
31  *size = sizeof(*spherical);
32 
33  return spherical;
34 }
35 
37  size_t width, size_t height,
38  size_t *left, size_t *top,
39  size_t *right, size_t *bottom)
40 {
41  /* conversion from 0.32 coordinates to pixels */
42  uint64_t orig_width = (uint64_t) width * UINT32_MAX /
43  (UINT32_MAX - map->bound_right - map->bound_left);
44  uint64_t orig_height = (uint64_t) height * UINT32_MAX /
45  (UINT32_MAX - map->bound_bottom - map->bound_top);
46 
47  /* add a (UINT32_MAX - 1) to round up integer division */
48  *left = (orig_width * map->bound_left + UINT32_MAX - 1) / UINT32_MAX;
49  *top = (orig_height * map->bound_top + UINT32_MAX - 1) / UINT32_MAX;
50  *right = orig_width - width - *left;
51  *bottom = orig_height - height - *top;
52 }
53 
54 static const char *spherical_projection_names[] = {
55  [AV_SPHERICAL_EQUIRECTANGULAR] = "equirectangular",
56  [AV_SPHERICAL_CUBEMAP] = "cubemap",
57  [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular",
58 };
59 
61 {
62  if ((unsigned)projection >= FF_ARRAY_ELEMS(spherical_projection_names))
63  return "unknown";
64 
65  return spherical_projection_names[projection];
66 }
67 
68 int av_spherical_from_name(const char *name)
69 {
70  int i;
71 
72  for (i = 0; i < FF_ARRAY_ELEMS(spherical_projection_names); i++) {
73  size_t len = strlen(spherical_projection_names[i]);
74  if (!strncmp(spherical_projection_names[i], name, len))
75  return i;
76  }
77 
78  return -1;
79 }
AVSphericalMapping * av_spherical_alloc(size_t *size)
Allocate a AVSphericalVideo structure and initialize its fields to default values.
Definition: spherical.c:24
#define NULL
Definition: coverity.c:32
Memory handling functions.
Video represents a portion of a sphere mapped on a flat surface using equirectangular projection...
Definition: spherical.h:72
Video represents a sphere mapped on a flat surface using equirectangular projection.
Definition: spherical.h:56
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:222
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:36
#define height
ptrdiff_t size
Definition: opengl_enc.c:101
uint16_t width
Definition: gdv.c:47
uint32_t bound_bottom
Distance from the bottom edge.
Definition: spherical.h:170
Video frame is split into 6 faces of a cube, and arranged on a 3x2 layout.
Definition: spherical.h:65
Spherical video.
uint32_t bound_right
Distance from the right edge.
Definition: spherical.h:169
int av_spherical_from_name(const char *name)
Get the AVSphericalProjection form a human-readable name.
Definition: spherical.c:68
#define FF_ARRAY_ELEMS(a)
AVSphericalProjection
Projection of the video surface(s) on a sphere.
Definition: spherical.h:51
const VDPAUPixFmtMap * map
This structure describes how to handle spherical videos, outlining information about projection...
Definition: spherical.h:82
uint32_t bound_top
Distance from the top edge.
Definition: spherical.h:168
static const char * spherical_projection_names[]
Definition: spherical.c:54
int len
uint32_t bound_left
Distance from the left edge.
Definition: spherical.h:167
const char * av_spherical_projection_name(enum AVSphericalProjection projection)
Provide a human-readable name of a given AVSphericalProjection.
Definition: spherical.c:60
const char * name
Definition: opengl_enc.c:103