FFmpeg
Loading...
Searching...
No Matches
pixdesc.c
Go to the documentation of this file.
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 */
35static int check_name_equivalence(const char *name, const char *back_name)
36{
37 return back_name && !strcmp(name, back_name);
38}
39
41{
42 int fail = 0;
43 for (int i = 0; i < AV_PIX_FMT_NB; i++) {
44 const char *name = av_get_pix_fmt_name(i);
45 if (!name)
46 continue;
47 if (av_get_pix_fmt(name) != i)
48 fail++;
49 }
50 return fail;
51}
52
54{
55 int fail = 0;
56 for (int i = 0; i < AVCOL_RANGE_NB; i++) {
57 const char *name = av_color_range_name(i);
58 if (!name)
59 continue;
61 if (back < 0 || !check_name_equivalence(name, av_color_range_name(back)))
62 fail++;
63 }
64 return fail;
65}
66
68{
69 int fail = 0;
70 for (int i = 0; i < AVCOL_PRI_NB; i++) {
71 const char *name = av_color_primaries_name(i);
72 if (!name)
73 continue;
76 fail++;
77 }
78 return fail;
79}
80
82{
83 int fail = 0;
84 for (int i = 0; i < AVCOL_TRC_NB; i++) {
85 const char *name = av_color_transfer_name(i);
86 if (!name)
87 continue;
89 if (back < 0 || !check_name_equivalence(name, av_color_transfer_name(back)))
90 fail++;
91 }
92 return fail;
93}
94
96{
97 int fail = 0;
98 for (int i = 0; i < AVCOL_SPC_NB; i++) {
99 const char *name = av_color_space_name(i);
100 if (!name)
101 continue;
102 int back = av_color_space_from_name(name);
103 if (back < 0 || !check_name_equivalence(name, av_color_space_name(back)))
104 fail++;
105 }
106 return fail;
107}
108
110{
111 int fail = 0;
112 for (int i = 0; i < AVCHROMA_LOC_NB; i++) {
113 const char *name = av_chroma_location_name(i);
114 if (!name)
115 continue;
117 if (back < 0 || !check_name_equivalence(name, av_chroma_location_name(back)))
118 fail++;
119 }
120 return fail;
121}
122
124{
125 int fail = 0;
126 for (int i = 0; i < AVALPHA_MODE_NB; i++) {
127 const char *name = av_alpha_mode_name(i);
128 if (!name)
129 continue;
130 int back = av_alpha_mode_from_name(name);
131 if (back < 0 || !check_name_equivalence(name, av_alpha_mode_name(back)))
132 fail++;
133 }
134 return fail;
135}
136
138{
139 int fail = 0;
140 for (int i = AVCHROMA_LOC_UNSPECIFIED + 1; i < AVCHROMA_LOC_NB; i++) {
141 int xpos, ypos;
142 if (av_chroma_location_enum_to_pos(&xpos, &ypos, i) < 0) {
143 fail++;
144 continue;
145 }
146 if ((int)av_chroma_location_pos_to_enum(xpos, ypos) != i)
147 fail++;
148 }
149 return fail;
150}
151
152int main(void)
153{
154 int skip = 0;
155
156 printf("Testing av_get_pix_fmt() / av_get_pix_fmt_name() round-trip\n");
157 printf(" result: %s\n",
158 test_pix_fmt_round_trip() ? "FAIL" : "OK");
159
160 printf("\nTesting av_color_*_name() / av_color_*_from_name() round-trips\n");
161 printf(" av_color_range: %s\n",
162 test_color_range_round_trip() ? "FAIL" : "OK");
163 printf(" av_color_primaries: %s\n",
164 test_color_primaries_round_trip() ? "FAIL" : "OK");
165 printf(" av_color_transfer: %s\n",
166 test_color_transfer_round_trip() ? "FAIL" : "OK");
167 printf(" av_color_space: %s\n",
168 test_color_space_round_trip() ? "FAIL" : "OK");
169 printf(" av_chroma_location: %s\n",
170 test_chroma_location_round_trip() ? "FAIL" : "OK");
171 printf(" av_alpha_mode: %s\n",
172 test_alpha_mode_round_trip() ? "FAIL" : "OK");
173
174 printf("\nTesting av_chroma_location_enum_to_pos / pos_to_enum round-trip\n");
175 printf(" result: %s\n",
176 test_chroma_location_pos_round_trip() ? "FAIL" : "OK");
177
178 printf("\nTesting pixel format descriptors\n");
179 for (int i = 0; i < AV_PIX_FMT_NB * 2; i++) {
181 if (!desc || !desc->name) {
182 skip++;
183 continue;
184 }
185 if (skip) {
186 printf(" %3d unused pixel format values\n", skip);
187 skip = 0;
188 }
189 printf(" pix fmt %s avg_bpp:%d planes:%d\n", desc->name,
192 }
193
194 return 0;
195}
static void BS_FUNC skip(BSCTX *bc, unsigned int n)
Skip n bits in the buffer.
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
__device__ int printf(const char *,...)
#define fail
Definition test.h:479
const char * desc
Definition libsvtav1.c:83
Utility Preprocessor macros.
int av_color_space_from_name(const char *name)
Definition pixdesc.c:3866
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3500
int av_chroma_location_from_name(const char *name)
Definition pixdesc.c:3887
int av_color_transfer_from_name(const char *name)
Definition pixdesc.c:3837
const char * av_color_space_name(enum AVColorSpace space)
Definition pixdesc.c:3860
const char * av_color_range_name(enum AVColorRange range)
Definition pixdesc.c:3776
const char * av_alpha_mode_name(enum AVAlphaMode mode)
Definition pixdesc.c:3925
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition pixdesc.c:3380
int av_get_padded_bits_per_pixel(const AVPixFmtDescriptor *pixdesc)
Return the number of bits per pixel for the pixel format described by pixdesc, including any padding ...
Definition pixdesc.c:3425
enum AVPixelFormat av_get_pix_fmt(const char *name)
Return the pixel format corresponding to name.
Definition pixdesc.c:3392
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition pixdesc.c:3881
int av_color_range_from_name(const char *name)
Definition pixdesc.c:3782
const char * av_color_transfer_name(enum AVColorTransferCharacteristic transfer)
Definition pixdesc.c:3827
enum AVChromaLocation av_chroma_location_pos_to_enum(int xpos, int ypos)
Converts swscale x/y chroma position to AVChromaLocation.
Definition pixdesc.c:3914
const char * av_color_primaries_name(enum AVColorPrimaries primaries)
Definition pixdesc.c:3794
int av_color_primaries_from_name(const char *name)
Definition pixdesc.c:3804
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
int av_chroma_location_enum_to_pos(int *xpos, int *ypos, enum AVChromaLocation pos)
Converts AVChromaLocation to swscale x/y chroma position.
Definition pixdesc.c:3902
enum AVAlphaMode av_alpha_mode_from_name(const char *name)
Definition pixdesc.c:3931
pixel format definitions
@ AVCHROMA_LOC_NB
Not part of ABI.
Definition pixfmt.h:810
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:803
@ AVCOL_RANGE_NB
Not part of ABI.
Definition pixfmt.h:784
@ AVALPHA_MODE_NB
Not part of ABI.
Definition pixfmt.h:820
@ AV_PIX_FMT_NB
number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of...
Definition pixfmt.h:508
@ AVCOL_PRI_NB
Not part of ABI.
Definition pixfmt.h:660
@ AVCOL_TRC_NB
Not part of ABI.
Definition pixfmt.h:694
@ AVCOL_SPC_NB
Not part of ABI.
Definition pixfmt.h:726
const char * name
Definition qsvenc.c:142
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
static int test_color_transfer_round_trip(void)
Definition pixdesc.c:81
static int test_color_space_round_trip(void)
Definition pixdesc.c:95
int main(void)
Definition pixdesc.c:152
static int test_color_primaries_round_trip(void)
Definition pixdesc.c:67
static int test_color_range_round_trip(void)
Definition pixdesc.c:53
static int test_pix_fmt_round_trip(void)
Definition pixdesc.c:40
static int test_chroma_location_pos_round_trip(void)
Definition pixdesc.c:137
static int test_alpha_mode_round_trip(void)
Definition pixdesc.c:123
static int test_chroma_location_round_trip(void)
Definition pixdesc.c:109
static int check_name_equivalence(const char *name, const char *back_name)
Definition pixdesc.c:35