FFmpeg
pixdesc_query.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Clément Bœsch <u pkh me>
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 <stdlib.h>
22 
23 #include "libavutil/mem.h"
25 
26 static const struct {
27  const char *class;
29 } query_tab[] = {
30  {"is16BPS", is16BPS},
31  {"isNBPS", isNBPS},
32  {"isBE", isBE},
33  {"isYUV", isYUV},
34  {"isPlanarYUV", isPlanarYUV},
35  {"isSemiPlanarYUV", isSemiPlanarYUV},
36  {"isRGB", isRGB},
37  {"Gray", isGray},
38  {"RGBinInt", isRGBinInt},
39  {"BGRinInt", isBGRinInt},
40  {"Bayer", isBayer},
41  {"AnyRGB", isAnyRGB},
42  {"ALPHA", isALPHA},
43  {"Packed", isPacked},
44  {"Planar", isPlanar},
45  {"PackedRGB", isPackedRGB},
46  {"PlanarRGB", isPlanarRGB},
47  {"usePal", usePal},
48  {"DataInHighBits", isDataInHighBits},
49  {"SwappedChroma", isSwappedChroma},
50 };
51 
52 static int cmp_str(const void *a, const void *b)
53 {
54  const char *s1 = *(const char **)a;
55  const char *s2 = *(const char **)b;
56  return strcmp(s1, s2);
57 }
58 
59 int main(void)
60 {
61  int i, j;
62 
63  for (i = 0; i < FF_ARRAY_ELEMS(query_tab); i++) {
64  const char **pix_fmts = NULL;
65  int nb_pix_fmts = 0;
66  const AVPixFmtDescriptor *pix_desc = NULL;
67 
68  while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
70  if (query_tab[i].cond(pix_fmt)) {
71  const char *pix_name = pix_desc->name;
72  if (pix_fmt == AV_PIX_FMT_RGB32) pix_name = "rgb32";
73  else if (pix_fmt == AV_PIX_FMT_RGB32_1) pix_name = "rgb32_1";
74  else if (pix_fmt == AV_PIX_FMT_BGR32) pix_name = "bgr32";
75  else if (pix_fmt == AV_PIX_FMT_BGR32_1) pix_name = "bgr32_1";
76 
77  av_dynarray_add(&pix_fmts, &nb_pix_fmts, (void *)pix_name);
78  }
79  }
80 
81  if (pix_fmts) {
82  qsort(pix_fmts, nb_pix_fmts, sizeof(*pix_fmts), cmp_str);
83 
84  printf("%s:\n", query_tab[i].class);
85  for (j = 0; j < nb_pix_fmts; j++)
86  printf(" %s\n", pix_fmts[j]);
87  printf("\n");
88 
90  }
91  }
92  return 0;
93 }
isBayer
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:809
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
isPlanarRGB
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:870
isRGB
static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:747
isPacked
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:847
AV_PIX_FMT_BGR32
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:381
AVPixFmtDescriptor::name
const char * name
Definition: pixdesc.h:70
b
#define b
Definition: input.c:34
av_pix_fmt_desc_next
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2669
isGray
#define isGray(x)
Definition: swscale.c:40
AV_PIX_FMT_RGB32_1
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:380
is16BPS
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:694
isNBPS
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:708
FF_ARRAY_ELEMS
#define FF_ARRAY_ELEMS(a)
Definition: sinewin_tablegen.c:29
s1
#define s1
Definition: regdef.h:38
pix_fmts
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:296
pix_fmt
static enum AVPixelFormat pix_fmt
Definition: demuxing_decoding.c:41
AV_PIX_FMT_BGR32_1
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:382
query_tab
static const struct @323 query_tab[]
isSemiPlanarYUV
static av_always_inline int isSemiPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:740
NULL
#define NULL
Definition: coverity.c:32
isDataInHighBits
static av_always_inline int isDataInHighBits(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:896
s2
#define s2
Definition: regdef.h:39
isBE
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:715
av_dynarray_add
void av_dynarray_add(void *tab_ptr, int *nb_ptr, void *elem)
Add the pointer to an element to a dynamic array.
Definition: mem.c:337
usePal
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:878
isAnyRGB
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:823
isYUV
static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:722
printf
printf("static const uint8_t my_array[100] = {\n")
cmp_str
static int cmp_str(const void *a, const void *b)
Definition: pixdesc_query.c:52
AV_PIX_FMT_RGB32
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:379
a
The reader does not expect b to be semantically here and if the code is changed by maybe adding a a division or other the signedness will almost certainly be mistaken To avoid this confusion a new type was SUINT is the C unsigned type but it holds a signed int to use the same example SUINT a
Definition: undefined.txt:41
isBGRinInt
static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:787
isSwappedChroma
static av_always_inline int isSwappedChroma(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:915
av_pix_fmt_desc_get_id
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2681
isALPHA
#define isALPHA(x)
Definition: swscale.c:51
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
swscale_internal.h
isPackedRGB
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:863
isPlanarYUV
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
Definition: vf_dnn_processing.c:155
mem.h
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
av_free
#define av_free(p)
Definition: tableprint_vlc.h:33
main
int main(void)
Definition: pixdesc_query.c:59
isRGBinInt
static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:765
isPlanar
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Definition: swscale_internal.h:856
int
int
Definition: ffmpeg_filter.c:153
cond
int(* cond)(enum AVPixelFormat pix_fmt)
Definition: pixdesc_query.c:28