mirror of
https://mirror.skon.top/https://github.com/FFmpeg/FFmpeg
synced 2026-04-20 21:00:41 +08:00
tests/fate/libavutil: add FATE test for spherical
Unit test covering all 4 public API functions in libavutil/spherical.c: av_spherical_alloc, av_spherical_projection_name, av_spherical_from_name, and av_spherical_tile_bounds. Tests allocation with and without size output, all 7 projection type name lookups, projection name round-trip verification, out-of-range handling, and tile bounds computation for full-frame, quarter-tile, and centered-tile configurations. Coverage for libavutil/spherical.c: 0.00% -> 100.00% Signed-off-by: marcos ashton <marcosashiglesias@gmail.com>
This commit is contained in:
@@ -301,6 +301,7 @@ TESTPROGS = adler32 \
|
||||
sha512 \
|
||||
side_data_array \
|
||||
softfloat \
|
||||
spherical \
|
||||
stereo3d \
|
||||
tree \
|
||||
twofish \
|
||||
|
||||
107
libavutil/tests/spherical.c
Normal file
107
libavutil/tests/spherical.c
Normal file
@@ -0,0 +1,107 @@
|
||||
/*
|
||||
* This file is part of FFmpeg.
|
||||
*
|
||||
* FFmpeg is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* FFmpeg is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with FFmpeg; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libavutil/mem.h"
|
||||
#include "libavutil/spherical.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
AVSphericalMapping *map;
|
||||
size_t size;
|
||||
|
||||
/* av_spherical_alloc with size output */
|
||||
printf("Testing av_spherical_alloc()\n");
|
||||
map = av_spherical_alloc(&size);
|
||||
if (map) {
|
||||
printf("alloc: OK, size>0=%s, default projection=%d\n",
|
||||
size > 0 ? "yes" : "no", map->projection);
|
||||
av_free(map);
|
||||
} else {
|
||||
printf("alloc: FAIL\n");
|
||||
}
|
||||
|
||||
/* av_spherical_alloc without size */
|
||||
map = av_spherical_alloc(NULL);
|
||||
printf("alloc (no size): %s\n", map ? "OK" : "FAIL");
|
||||
av_free(map);
|
||||
|
||||
/* av_spherical_projection_name - all valid projections */
|
||||
printf("\nTesting av_spherical_projection_name()\n");
|
||||
for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++)
|
||||
printf("projection %d: %s\n", i, av_spherical_projection_name(i));
|
||||
printf("out of range: %s\n", av_spherical_projection_name(100));
|
||||
|
||||
/* av_spherical_from_name - all valid names */
|
||||
printf("\nTesting av_spherical_from_name()\n");
|
||||
for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++) {
|
||||
const char *name = av_spherical_projection_name(i);
|
||||
printf("%s: %d\n", name, av_spherical_from_name(name));
|
||||
}
|
||||
printf("nonexistent: %d\n", av_spherical_from_name("nonexistent"));
|
||||
|
||||
/* projection name round-trip */
|
||||
printf("\nTesting projection name round-trip\n");
|
||||
for (int i = 0; i <= AV_SPHERICAL_PARAMETRIC_IMMERSIVE; i++) {
|
||||
const char *name = av_spherical_projection_name(i);
|
||||
int rt = av_spherical_from_name(name);
|
||||
printf("roundtrip %d (%s): %s\n", i, name, rt == i ? "OK" : "FAIL");
|
||||
}
|
||||
|
||||
/* av_spherical_tile_bounds - no bounds (full frame) */
|
||||
printf("\nTesting av_spherical_tile_bounds()\n");
|
||||
map = av_spherical_alloc(NULL);
|
||||
if (map) {
|
||||
size_t left, top, right, bottom;
|
||||
|
||||
map->projection = AV_SPHERICAL_EQUIRECTANGULAR_TILE;
|
||||
printf("projection: %s\n",
|
||||
av_spherical_projection_name(map->projection));
|
||||
|
||||
map->bound_left = 0;
|
||||
map->bound_top = 0;
|
||||
map->bound_right = 0;
|
||||
map->bound_bottom = 0;
|
||||
av_spherical_tile_bounds(map, 1920, 1080, &left, &top, &right, &bottom);
|
||||
printf("full frame: left=%zu top=%zu right=%zu bottom=%zu\n",
|
||||
left, top, right, bottom);
|
||||
|
||||
/* quarter tile at top-left (each bound is 0.32 fixed point) */
|
||||
map->bound_left = 0;
|
||||
map->bound_top = 0;
|
||||
map->bound_right = UINT32_MAX / 2;
|
||||
map->bound_bottom = UINT32_MAX / 2;
|
||||
av_spherical_tile_bounds(map, 960, 540, &left, &top, &right, &bottom);
|
||||
printf("quarter top-left: left=%zu top=%zu right=%zu bottom=%zu\n",
|
||||
left, top, right, bottom);
|
||||
|
||||
/* centered tile with equal margins */
|
||||
map->bound_left = UINT32_MAX / 4;
|
||||
map->bound_top = UINT32_MAX / 4;
|
||||
map->bound_right = UINT32_MAX / 4;
|
||||
map->bound_bottom = UINT32_MAX / 4;
|
||||
av_spherical_tile_bounds(map, 960, 540, &left, &top, &right, &bottom);
|
||||
printf("centered: left=%zu top=%zu right=%zu bottom=%zu\n",
|
||||
left, top, right, bottom);
|
||||
|
||||
av_free(map);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -156,6 +156,10 @@ FATE_LIBAVUTIL += fate-side_data_array
|
||||
fate-side_data_array: libavutil/tests/side_data_array$(EXESUF)
|
||||
fate-side_data_array: CMD = run libavutil/tests/side_data_array$(EXESUF)
|
||||
|
||||
FATE_LIBAVUTIL += fate-spherical
|
||||
fate-spherical: libavutil/tests/spherical$(EXESUF)
|
||||
fate-spherical: CMD = run libavutil/tests/spherical$(EXESUF)
|
||||
|
||||
FATE_LIBAVUTIL += fate-stereo3d
|
||||
fate-stereo3d: libavutil/tests/stereo3d$(EXESUF)
|
||||
fate-stereo3d: CMD = run libavutil/tests/stereo3d$(EXESUF)
|
||||
|
||||
38
tests/ref/fate/spherical
Normal file
38
tests/ref/fate/spherical
Normal file
@@ -0,0 +1,38 @@
|
||||
Testing av_spherical_alloc()
|
||||
alloc: OK, size>0=yes, default projection=4
|
||||
alloc (no size): OK
|
||||
|
||||
Testing av_spherical_projection_name()
|
||||
projection 0: equirectangular
|
||||
projection 1: cubemap
|
||||
projection 2: tiled equirectangular
|
||||
projection 3: half equirectangular
|
||||
projection 4: rectilinear
|
||||
projection 5: fisheye
|
||||
projection 6: parametric immersive
|
||||
out of range: unknown
|
||||
|
||||
Testing av_spherical_from_name()
|
||||
equirectangular: 0
|
||||
cubemap: 1
|
||||
tiled equirectangular: 2
|
||||
half equirectangular: 3
|
||||
rectilinear: 4
|
||||
fisheye: 5
|
||||
parametric immersive: 6
|
||||
nonexistent: -1
|
||||
|
||||
Testing projection name round-trip
|
||||
roundtrip 0 (equirectangular): OK
|
||||
roundtrip 1 (cubemap): OK
|
||||
roundtrip 2 (tiled equirectangular): OK
|
||||
roundtrip 3 (half equirectangular): OK
|
||||
roundtrip 4 (rectilinear): OK
|
||||
roundtrip 5 (fisheye): OK
|
||||
roundtrip 6 (parametric immersive): OK
|
||||
|
||||
Testing av_spherical_tile_bounds()
|
||||
projection: tiled equirectangular
|
||||
full frame: left=0 top=0 right=0 bottom=0
|
||||
quarter top-left: left=0 top=0 right=959 bottom=539
|
||||
centered: left=480 top=270 right=479 bottom=269
|
||||
Reference in New Issue
Block a user