FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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  {"isRGB", isRGB},
36  {"Gray", isGray},
37  {"RGBinInt", isRGBinInt},
38  {"BGRinInt", isBGRinInt},
39  {"Bayer", isBayer},
40  {"AnyRGB", isAnyRGB},
41  {"ALPHA", isALPHA},
42  {"Packed", isPacked},
43  {"Planar", isPlanar},
44  {"PackedRGB", isPackedRGB},
45  {"PlanarRGB", isPlanarRGB},
46  {"usePal", usePal},
47 };
48 
49 static int cmp_str(const void *a, const void *b)
50 {
51  const char *s1 = *(const char **)a;
52  const char *s2 = *(const char **)b;
53  return strcmp(s1, s2);
54 }
55 
56 int main(void)
57 {
58  int i, j;
59 
60  for (i = 0; i < FF_ARRAY_ELEMS(query_tab); i++) {
61  const char **pix_fmts = NULL;
62  int nb_pix_fmts = 0;
63  const AVPixFmtDescriptor *pix_desc = NULL;
64 
65  while ((pix_desc = av_pix_fmt_desc_next(pix_desc))) {
67  if (query_tab[i].cond(pix_fmt)) {
68  const char *pix_name = pix_desc->name;
69  if (pix_fmt == AV_PIX_FMT_RGB32) pix_name = "rgb32";
70  else if (pix_fmt == AV_PIX_FMT_RGB32_1) pix_name = "rgb32_1";
71  else if (pix_fmt == AV_PIX_FMT_BGR32) pix_name = "bgr32";
72  else if (pix_fmt == AV_PIX_FMT_BGR32_1) pix_name = "bgr32_1";
73 
74  av_dynarray_add(&pix_fmts, &nb_pix_fmts, (void *)pix_name);
75  }
76  }
77 
78  if (pix_fmts) {
79  qsort(pix_fmts, nb_pix_fmts, sizeof(*pix_fmts), cmp_str);
80 
81  printf("%s:\n", query_tab[i].class);
82  for (j = 0; j < nb_pix_fmts; j++)
83  printf(" %s\n", pix_fmts[j]);
84  printf("\n");
85 
86  av_free(pix_fmts);
87  }
88  }
89  return 0;
90 }
#define NULL
Definition: coverity.c:32
static av_always_inline int isAnyRGB(enum AVPixelFormat pix_fmt)
static enum AVPixelFormat pix_fmt
static av_always_inline int isPlanarRGB(enum AVPixelFormat pix_fmt)
Memory handling functions.
const char * b
Definition: vf_curves.c:116
static av_always_inline int is16BPS(enum AVPixelFormat pix_fmt)
int main(void)
Definition: pixdesc_query.c:56
int(* cond)(enum AVPixelFormat pix_fmt)
Definition: pixdesc_query.c:28
#define isALPHA(x)
Definition: swscale.c:51
static av_always_inline int isYUV(enum AVPixelFormat pix_fmt)
const char * name
Definition: pixdesc.h:82
#define AV_PIX_FMT_BGR32_1
Definition: pixfmt.h:355
#define s2
Definition: regdef.h:39
enum AVPixelFormat av_pix_fmt_desc_get_id(const AVPixFmtDescriptor *desc)
Definition: pixdesc.c:2465
static av_always_inline int isBayer(enum AVPixelFormat pix_fmt)
#define FF_ARRAY_ELEMS(a)
#define isGray(x)
Definition: swscale.c:40
#define AV_PIX_FMT_BGR32
Definition: pixfmt.h:354
static av_always_inline int isBE(enum AVPixelFormat pix_fmt)
static av_always_inline int isPlanar(enum AVPixelFormat pix_fmt)
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
static int cmp_str(const void *a, const void *b)
Definition: pixdesc_query.c:49
#define AV_PIX_FMT_RGB32
Definition: pixfmt.h:352
static av_always_inline int isRGB(enum AVPixelFormat pix_fmt)
static av_always_inline int isRGBinInt(enum AVPixelFormat pix_fmt)
static av_always_inline int isPlanarYUV(enum AVPixelFormat pix_fmt)
#define s1
Definition: regdef.h:38
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:266
int
#define av_free(p)
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:308
#define AV_PIX_FMT_RGB32_1
Definition: pixfmt.h:353
static av_always_inline int isBGRinInt(enum AVPixelFormat pix_fmt)
static const struct @300 query_tab[]
static av_always_inline int isPackedRGB(enum AVPixelFormat pix_fmt)
static av_always_inline int usePal(enum AVPixelFormat pix_fmt)
static av_always_inline int isPacked(enum AVPixelFormat pix_fmt)
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
static av_always_inline int isNBPS(enum AVPixelFormat pix_fmt)
const AVPixFmtDescriptor * av_pix_fmt_desc_next(const AVPixFmtDescriptor *prev)
Iterate over all pixel format descriptors known to libavutil.
Definition: pixdesc.c:2453