| Line | Branch | Exec | Source |
|---|---|---|---|
| 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 | |||
| 26 | 13 | AVSphericalMapping *av_spherical_alloc(size_t *size) | |
| 27 | { | ||
| 28 | 13 | AVSphericalMapping *spherical = av_mallocz(sizeof(AVSphericalMapping)); | |
| 29 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
|
13 | if (!spherical) |
| 30 | ✗ | return NULL; | |
| 31 | |||
| 32 | 13 | spherical->projection = AV_SPHERICAL_RECTILINEAR; | |
| 33 | |||
| 34 |
2/2✓ Branch 0 taken 11 times.
✓ Branch 1 taken 2 times.
|
13 | if (size) |
| 35 | 11 | *size = sizeof(*spherical); | |
| 36 | |||
| 37 | 13 | return spherical; | |
| 38 | } | ||
| 39 | |||
| 40 | 18 | void av_spherical_tile_bounds(const AVSphericalMapping *map, | |
| 41 | size_t width, size_t height, | ||
| 42 | size_t *left, size_t *top, | ||
| 43 | size_t *right, size_t *bottom) | ||
| 44 | { | ||
| 45 | /* conversion from 0.32 coordinates to pixels */ | ||
| 46 | 18 | uint64_t orig_width = (uint64_t) width * UINT32_MAX / | |
| 47 | 18 | (UINT32_MAX - map->bound_right - map->bound_left); | |
| 48 | 18 | uint64_t orig_height = (uint64_t) height * UINT32_MAX / | |
| 49 | 18 | (UINT32_MAX - map->bound_bottom - map->bound_top); | |
| 50 | |||
| 51 | /* add a (UINT32_MAX - 1) to round up integer division */ | ||
| 52 | 18 | *left = (orig_width * map->bound_left + UINT32_MAX - 1) / UINT32_MAX; | |
| 53 | 18 | *top = (orig_height * map->bound_top + UINT32_MAX - 1) / UINT32_MAX; | |
| 54 | 18 | *right = orig_width - width - *left; | |
| 55 | 18 | *bottom = orig_height - height - *top; | |
| 56 | 18 | } | |
| 57 | |||
| 58 | static const char *const spherical_projection_names[] = { | ||
| 59 | [AV_SPHERICAL_EQUIRECTANGULAR] = "equirectangular", | ||
| 60 | [AV_SPHERICAL_CUBEMAP] = "cubemap", | ||
| 61 | [AV_SPHERICAL_EQUIRECTANGULAR_TILE] = "tiled equirectangular", | ||
| 62 | [AV_SPHERICAL_HALF_EQUIRECTANGULAR] = "half equirectangular", | ||
| 63 | [AV_SPHERICAL_RECTILINEAR] = "rectilinear", | ||
| 64 | [AV_SPHERICAL_FISHEYE] = "fisheye", | ||
| 65 | [AV_SPHERICAL_PARAMETRIC_IMMERSIVE] = "parametric immersive", | ||
| 66 | }; | ||
| 67 | |||
| 68 | 45 | const char *av_spherical_projection_name(enum AVSphericalProjection projection) | |
| 69 | { | ||
| 70 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 44 times.
|
45 | if ((unsigned)projection >= FF_ARRAY_ELEMS(spherical_projection_names)) |
| 71 | 1 | return "unknown"; | |
| 72 | |||
| 73 | 44 | return spherical_projection_names[projection]; | |
| 74 | } | ||
| 75 | |||
| 76 | 15 | int av_spherical_from_name(const char *name) | |
| 77 | { | ||
| 78 | int i; | ||
| 79 | |||
| 80 |
2/2✓ Branch 0 taken 63 times.
✓ Branch 1 taken 1 times.
|
64 | for (i = 0; i < FF_ARRAY_ELEMS(spherical_projection_names); i++) { |
| 81 |
2/2✓ Branch 1 taken 14 times.
✓ Branch 2 taken 49 times.
|
63 | if (av_strstart(name, spherical_projection_names[i], NULL)) |
| 82 | 14 | return i; | |
| 83 | } | ||
| 84 | |||
| 85 | 1 | return -1; | |
| 86 | } | ||
| 87 |