| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * pixel format descriptor | ||
| 3 | * Copyright (c) 2009 Michael Niedermayer <michaelni@gmx.at> | ||
| 4 | * | ||
| 5 | * This file is part of FFmpeg. | ||
| 6 | * | ||
| 7 | * FFmpeg is free software; you can redistribute it and/or | ||
| 8 | * modify it under the terms of the GNU Lesser General Public | ||
| 9 | * License as published by the Free Software Foundation; either | ||
| 10 | * version 2.1 of the License, or (at your option) any later version. | ||
| 11 | * | ||
| 12 | * FFmpeg is distributed in the hope that it will be useful, | ||
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
| 15 | * Lesser General Public License for more details. | ||
| 16 | * | ||
| 17 | * You should have received a copy of the GNU Lesser General Public | ||
| 18 | * License along with FFmpeg; if not, write to the Free Software | ||
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
| 20 | */ | ||
| 21 | |||
| 22 | #include <stdio.h> | ||
| 23 | #include <string.h> | ||
| 24 | |||
| 25 | #include "libavutil/macros.h" | ||
| 26 | #include "libavutil/pixdesc.h" | ||
| 27 | #include "libavutil/pixfmt.h" | ||
| 28 | |||
| 29 | /* | ||
| 30 | * from_name() may legitimately map to a different index when two enum | ||
| 31 | * values share the same name string (e.g. AVCOL_PRI_RESERVED0 and | ||
| 32 | * AVCOL_PRI_RESERVED both use "reserved"). Accept that as long as | ||
| 33 | * name(back) equals name(i). | ||
| 34 | */ | ||
| 35 | 64 | static int check_name_equivalence(const char *name, const char *back_name) | |
| 36 | { | ||
| 37 |
2/4✓ Branch 0 taken 64 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 64 times.
✗ Branch 3 not taken.
|
64 | return back_name && !strcmp(name, back_name); |
| 38 | } | ||
| 39 | |||
| 40 | 1 | static int test_pix_fmt_round_trip(void) | |
| 41 | { | ||
| 42 | 1 | int fail = 0; | |
| 43 |
2/2✓ Branch 0 taken 268 times.
✓ Branch 1 taken 1 times.
|
269 | for (int i = 0; i < AV_PIX_FMT_NB; i++) { |
| 44 | 268 | const char *name = av_get_pix_fmt_name(i); | |
| 45 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 268 times.
|
268 | if (!name) |
| 46 | ✗ | continue; | |
| 47 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 268 times.
|
268 | if (av_get_pix_fmt(name) != i) |
| 48 | ✗ | fail++; | |
| 49 | } | ||
| 50 | 1 | return fail; | |
| 51 | } | ||
| 52 | |||
| 53 | 1 | static int test_color_range_round_trip(void) | |
| 54 | { | ||
| 55 | 1 | int fail = 0; | |
| 56 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (int i = 0; i < AVCOL_RANGE_NB; i++) { |
| 57 | 3 | const char *name = av_color_range_name(i); | |
| 58 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!name) |
| 59 | ✗ | continue; | |
| 60 | 3 | int back = av_color_range_from_name(name); | |
| 61 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | if (back < 0 || !check_name_equivalence(name, av_color_range_name(back))) |
| 62 | ✗ | fail++; | |
| 63 | } | ||
| 64 | 1 | return fail; | |
| 65 | } | ||
| 66 | |||
| 67 | 1 | static int test_color_primaries_round_trip(void) | |
| 68 | { | ||
| 69 | 1 | int fail = 0; | |
| 70 |
2/2✓ Branch 0 taken 23 times.
✓ Branch 1 taken 1 times.
|
24 | for (int i = 0; i < AVCOL_PRI_NB; i++) { |
| 71 | 23 | const char *name = av_color_primaries_name(i); | |
| 72 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 14 times.
|
23 | if (!name) |
| 73 | 9 | continue; | |
| 74 | 14 | int back = av_color_primaries_from_name(name); | |
| 75 |
2/4✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 14 times.
|
14 | if (back < 0 || !check_name_equivalence(name, av_color_primaries_name(back))) |
| 76 | ✗ | fail++; | |
| 77 | } | ||
| 78 | 1 | return fail; | |
| 79 | } | ||
| 80 | |||
| 81 | 1 | static int test_color_transfer_round_trip(void) | |
| 82 | { | ||
| 83 | 1 | int fail = 0; | |
| 84 |
2/2✓ Branch 0 taken 19 times.
✓ Branch 1 taken 1 times.
|
20 | for (int i = 0; i < AVCOL_TRC_NB; i++) { |
| 85 | 19 | const char *name = av_color_transfer_name(i); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 19 times.
|
19 | if (!name) |
| 87 | ✗ | continue; | |
| 88 | 19 | int back = av_color_transfer_from_name(name); | |
| 89 |
2/4✓ Branch 0 taken 19 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 19 times.
|
19 | if (back < 0 || !check_name_equivalence(name, av_color_transfer_name(back))) |
| 90 | ✗ | fail++; | |
| 91 | } | ||
| 92 | 1 | return fail; | |
| 93 | } | ||
| 94 | |||
| 95 | 1 | static int test_color_space_round_trip(void) | |
| 96 | { | ||
| 97 | 1 | int fail = 0; | |
| 98 |
2/2✓ Branch 0 taken 18 times.
✓ Branch 1 taken 1 times.
|
19 | for (int i = 0; i < AVCOL_SPC_NB; i++) { |
| 99 | 18 | const char *name = av_color_space_name(i); | |
| 100 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 18 times.
|
18 | if (!name) |
| 101 | ✗ | continue; | |
| 102 | 18 | int back = av_color_space_from_name(name); | |
| 103 |
2/4✓ Branch 0 taken 18 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18 times.
|
18 | if (back < 0 || !check_name_equivalence(name, av_color_space_name(back))) |
| 104 | ✗ | fail++; | |
| 105 | } | ||
| 106 | 1 | return fail; | |
| 107 | } | ||
| 108 | |||
| 109 | 1 | static int test_chroma_location_round_trip(void) | |
| 110 | { | ||
| 111 | 1 | int fail = 0; | |
| 112 |
2/2✓ Branch 0 taken 7 times.
✓ Branch 1 taken 1 times.
|
8 | for (int i = 0; i < AVCHROMA_LOC_NB; i++) { |
| 113 | 7 | const char *name = av_chroma_location_name(i); | |
| 114 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
|
7 | if (!name) |
| 115 | ✗ | continue; | |
| 116 | 7 | int back = av_chroma_location_from_name(name); | |
| 117 |
2/4✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 7 times.
|
7 | if (back < 0 || !check_name_equivalence(name, av_chroma_location_name(back))) |
| 118 | ✗ | fail++; | |
| 119 | } | ||
| 120 | 1 | return fail; | |
| 121 | } | ||
| 122 | |||
| 123 | 1 | static int test_alpha_mode_round_trip(void) | |
| 124 | { | ||
| 125 | 1 | int fail = 0; | |
| 126 |
2/2✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
|
4 | for (int i = 0; i < AVALPHA_MODE_NB; i++) { |
| 127 | 3 | const char *name = av_alpha_mode_name(i); | |
| 128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (!name) |
| 129 | ✗ | continue; | |
| 130 | 3 | int back = av_alpha_mode_from_name(name); | |
| 131 |
2/4✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3 times.
|
3 | if (back < 0 || !check_name_equivalence(name, av_alpha_mode_name(back))) |
| 132 | ✗ | fail++; | |
| 133 | } | ||
| 134 | 1 | return fail; | |
| 135 | } | ||
| 136 | |||
| 137 | 1 | static int test_chroma_location_pos_round_trip(void) | |
| 138 | { | ||
| 139 | 1 | int fail = 0; | |
| 140 |
2/2✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
|
7 | for (int i = AVCHROMA_LOC_UNSPECIFIED + 1; i < AVCHROMA_LOC_NB; i++) { |
| 141 | int xpos, ypos; | ||
| 142 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if (av_chroma_location_enum_to_pos(&xpos, &ypos, i) < 0) { |
| 143 | ✗ | fail++; | |
| 144 | ✗ | continue; | |
| 145 | } | ||
| 146 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
|
6 | if ((int)av_chroma_location_pos_to_enum(xpos, ypos) != i) |
| 147 | ✗ | fail++; | |
| 148 | } | ||
| 149 | 1 | return fail; | |
| 150 | } | ||
| 151 | |||
| 152 | 1 | int main(void) | |
| 153 | { | ||
| 154 | 1 | int skip = 0; | |
| 155 | |||
| 156 | 1 | printf("Testing av_get_pix_fmt() / av_get_pix_fmt_name() round-trip\n"); | |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" result: %s\n", |
| 158 | 1 | test_pix_fmt_round_trip() ? "FAIL" : "OK"); | |
| 159 | |||
| 160 | 1 | printf("\nTesting av_color_*_name() / av_color_*_from_name() round-trips\n"); | |
| 161 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_color_range: %s\n", |
| 162 | 1 | test_color_range_round_trip() ? "FAIL" : "OK"); | |
| 163 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_color_primaries: %s\n", |
| 164 | 1 | test_color_primaries_round_trip() ? "FAIL" : "OK"); | |
| 165 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_color_transfer: %s\n", |
| 166 | 1 | test_color_transfer_round_trip() ? "FAIL" : "OK"); | |
| 167 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_color_space: %s\n", |
| 168 | 1 | test_color_space_round_trip() ? "FAIL" : "OK"); | |
| 169 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_chroma_location: %s\n", |
| 170 | 1 | test_chroma_location_round_trip() ? "FAIL" : "OK"); | |
| 171 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" av_alpha_mode: %s\n", |
| 172 | 1 | test_alpha_mode_round_trip() ? "FAIL" : "OK"); | |
| 173 | |||
| 174 | 1 | printf("\nTesting av_chroma_location_enum_to_pos / pos_to_enum round-trip\n"); | |
| 175 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | printf(" result: %s\n", |
| 176 | 1 | test_chroma_location_pos_round_trip() ? "FAIL" : "OK"); | |
| 177 | |||
| 178 | 1 | printf("\nTesting pixel format descriptors\n"); | |
| 179 |
2/2✓ Branch 0 taken 536 times.
✓ Branch 1 taken 1 times.
|
537 | for (int i = 0; i < AV_PIX_FMT_NB * 2; i++) { |
| 180 | 536 | const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i); | |
| 181 |
3/4✓ Branch 0 taken 268 times.
✓ Branch 1 taken 268 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 268 times.
|
536 | if (!desc || !desc->name) { |
| 182 | 268 | skip++; | |
| 183 | 268 | continue; | |
| 184 | } | ||
| 185 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 268 times.
|
268 | if (skip) { |
| 186 | ✗ | printf(" %3d unused pixel format values\n", skip); | |
| 187 | ✗ | skip = 0; | |
| 188 | } | ||
| 189 | 268 | printf(" pix fmt %s avg_bpp:%d planes:%d\n", desc->name, | |
| 190 | av_get_padded_bits_per_pixel(desc), | ||
| 191 | av_pix_fmt_count_planes(i)); | ||
| 192 | } | ||
| 193 | |||
| 194 | 1 | return 0; | |
| 195 | } | ||
| 196 |