| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * This file is part of FFmpeg. | ||
| 3 | * | ||
| 4 | * FFmpeg is free software; you can redistribute it and/or | ||
| 5 | * modify it under the terms of the GNU Lesser General Public | ||
| 6 | * License as published by the Free Software Foundation; either | ||
| 7 | * version 2.1 of the License, or (at your option) any later version. | ||
| 8 | * | ||
| 9 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 12 | * Lesser General Public License for more details. | ||
| 13 | * | ||
| 14 | * You should have received a copy of the GNU Lesser General Public | ||
| 15 | * License along with FFmpeg; if not, write to the Free Software | ||
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 17 | */ | ||
| 18 | |||
| 19 | #include <stdio.h> | ||
| 20 | |||
| 21 | #include "libavutil/mem.h" | ||
| 22 | #include "libavutil/spherical.h" | ||
| 23 | |||
| 24 | 1 | int main(void) | |
| 25 | { | ||
| 26 | AVSphericalMapping *map; | ||
| 27 | size_t size; | ||
| 28 | |||
| 29 | /* av_spherical_alloc with size output */ | ||
| 30 | 1 | printf("Testing av_spherical_alloc()\n"); | |
| 31 | 1 | map = av_spherical_alloc(&size); | |
| 32 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (map) { |
| 33 | 1 | printf("alloc: OK, size>0=%s, default projection=%d\n", | |
| 34 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | size > 0 ? "yes" : "no", map->projection); |
| 35 | 1 | av_free(map); | |
| 36 | } else { | ||
| 37 | ✗ | printf("alloc: FAIL\n"); | |
| 38 | } | ||
| 39 | |||
| 40 | /* av_spherical_alloc without size */ | ||
| 41 | 1 | map = av_spherical_alloc(NULL); | |
| 42 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | printf("alloc (no size): %s\n", map ? "OK" : "FAIL"); |
| 43 | 1 | av_free(map); | |
| 44 | |||
| 45 | /* av_spherical_projection_name - all valid projections */ | ||
| 46 | 1 | printf("\nTesting av_spherical_projection_name()\n"); | |
| 47 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++) |
| 48 | 7 | printf("projection %d: %s\n", i, av_spherical_projection_name(i)); | |
| 49 | 1 | printf("out of range: %s\n", av_spherical_projection_name(100)); | |
| 50 | |||
| 51 | /* av_spherical_from_name - all valid names */ | ||
| 52 | 1 | printf("\nTesting av_spherical_from_name()\n"); | |
| 53 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++) { |
| 54 | 7 | const char *name = av_spherical_projection_name(i); | |
| 55 | 7 | printf("%s: %d\n", name, av_spherical_from_name(name)); | |
| 56 | } | ||
| 57 | 1 | printf("nonexistent: %d\n", av_spherical_from_name("nonexistent")); | |
| 58 | |||
| 59 | /* projection name round-trip */ | ||
| 60 | 1 | printf("\nTesting projection name round-trip\n"); | |
| 61 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++) { |
| 62 | 7 | const char *name = av_spherical_projection_name(i); | |
| 63 | 7 | int rt = av_spherical_from_name(name); | |
| 64 |
1/2✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
|
7 | printf("roundtrip %d (%s): %s\n", i, name, rt == i ? "OK" : "FAIL"); |
| 65 | } | ||
| 66 | |||
| 67 | /* av_spherical_tile_bounds - no bounds (full frame) */ | ||
| 68 | 1 | printf("\nTesting av_spherical_tile_bounds()\n"); | |
| 69 | 1 | map = av_spherical_alloc(NULL); | |
| 70 |
1/2✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
|
1 | if (map) { |
| 71 | size_t left, top, right, bottom; | ||
| 72 | |||
| 73 | 1 | map->projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE; | |
| 74 | 1 | printf("projection: %s\n", | |
| 75 | av_spherical_projection_name(map->projection)); | ||
| 76 | |||
| 77 | 1 | map->bound_left = 0; | |
| 78 | 1 | map->bound_top = 0; | |
| 79 | 1 | map->bound_right = 0; | |
| 80 | 1 | map->bound_bottom = 0; | |
| 81 | 1 | av_spherical_tile_bounds(map, 1920, 1080, &left, &top, &right, &bottom); | |
| 82 | 1 | printf("full frame: left=%zu top=%zu right=%zu bottom=%zu\n", | |
| 83 | left, top, right, bottom); | ||
| 84 | |||
| 85 | /* quarter tile at top-left (each bound is 0.32 fixed point) */ | ||
| 86 | 1 | map->bound_left = 0; | |
| 87 | 1 | map->bound_top = 0; | |
| 88 | 1 | map->bound_right = UINT32_MAX / 2; | |
| 89 | 1 | map->bound_bottom = UINT32_MAX / 2; | |
| 90 | 1 | av_spherical_tile_bounds(map, 960, 540, &left, &top, &right, &bottom); | |
| 91 | 1 | printf("quarter top-left: left=%zu top=%zu right=%zu bottom=%zu\n", | |
| 92 | left, top, right, bottom); | ||
| 93 | |||
| 94 | /* centered tile with equal margins */ | ||
| 95 | 1 | map->bound_left = UINT32_MAX / 4; | |
| 96 | 1 | map->bound_top = UINT32_MAX / 4; | |
| 97 | 1 | map->bound_right = UINT32_MAX / 4; | |
| 98 | 1 | map->bound_bottom = UINT32_MAX / 4; | |
| 99 | 1 | av_spherical_tile_bounds(map, 960, 540, &left, &top, &right, &bottom); | |
| 100 | 1 | printf("centered: left=%zu top=%zu right=%zu bottom=%zu\n", | |
| 101 | left, top, right, bottom); | ||
| 102 | |||
| 103 | 1 | av_free(map); | |
| 104 | } | ||
| 105 | |||
| 106 | 1 | return 0; | |
| 107 | } | ||
| 108 |