FFmpeg  4.0
pixfmt_best.c
Go to the documentation of this file.
1 /*
2  * This file is part of FFmpeg.
3  *
4  * FFmpeg is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * FFmpeg is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with FFmpeg; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 
19 #include "libavutil/pixdesc.c"
20 
21 static const enum AVPixelFormat pixfmt_list[] = {
40 };
41 
43 {
44  enum AVPixelFormat best = AV_PIX_FMT_NONE;
45  int i;
46  for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
47  best = av_find_best_pix_fmt_of_2(best, pixfmt_list[i],
48  pixfmt, 0, NULL);
49  return best;
50 }
51 
52 int main(void)
53 {
54  enum AVPixelFormat output;
55  int i, pass = 0, fail = 0;
56 
57 #define TEST(input, expected) do { \
58  output = find_best(input); \
59  if (output != expected) { \
60  printf("Matching %s: got %s, expected %s\n", \
61  av_get_pix_fmt_name(input), \
62  av_get_pix_fmt_name(output), \
63  av_get_pix_fmt_name(expected)); \
64  ++fail; \
65  } else \
66  ++pass; \
67  } while (0)
68 
69  // Same formats.
70  for (i = 0; i < FF_ARRAY_ELEMS(pixfmt_list); i++)
72 
73  // Formats containing the same data in different layouts.
86 
87  // Formats additionally containing alpha (here ignored).
100 
101  // Formats requiring upsampling to represent exactly.
119 
120  // Formats containing the same data in different endianness.
133 
134  // Opaque formats are least unlike each other.
136 
137  printf("%d tests passed, %d tests failed.\n", pass, fail);
138  return !!fail;
139 }
packed YUV 4:2:2, 16bpp, Cb Y0 Cr Y1
Definition: pixfmt.h:77
#define NULL
Definition: coverity.c:32
static enum AVPixelFormat pixfmt_list[]
Definition: pixfmt_best.c:21
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:370
int main(void)
Definition: pixfmt_best.c:52
8 bits gray, 8 bits alpha
Definition: pixfmt.h:139
#define AV_PIX_FMT_GBRAP10
Definition: pixfmt.h:388
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
packed RGB 8:8:8, 24bpp, RGBRGB...
Definition: pixfmt.h:64
packed RGB 1:2:1 bitstream, 4bpp, (msb)1B 2G 1R(lsb), a byte contains two pixels, the first pixel in ...
Definition: pixfmt.h:80
#define AV_PIX_FMT_RGBA64
Definition: pixfmt.h:358
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:164
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:384
#define AV_PIX_FMT_BGRA64
Definition: pixfmt.h:363
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:372
#define AV_PIX_FMT_RGB444
Definition: pixfmt.h:357
#define AV_PIX_FMT_GRAY10
Definition: pixfmt.h:350
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), little-endian
Definition: pixfmt.h:102
#define AV_PIX_FMT_P016
Definition: pixfmt.h:414
#define AV_PIX_FMT_GRAY12
Definition: pixfmt.h:351
#define AV_PIX_FMT_P010
Definition: pixfmt.h:413
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:97
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as lit...
Definition: pixfmt.h:99
packed RGB 5:6:5, 16bpp, (msb) 5R 6G 5B(lsb), big-endian
Definition: pixfmt.h:101
packed ABGR 8:8:8:8, 32bpp, ABGRABGR...
Definition: pixfmt.h:90
#define AV_PIX_FMT_YUV444P16
Definition: pixfmt.h:381
Y , 10bpp, little-endian.
Definition: pixfmt.h:294
static enum AVPixelFormat find_best(enum AVPixelFormat pixfmt)
Definition: pixfmt_best.c:42
planar YUV 4:2:2 24bpp, (1 Cr & Cb sample per 2x1 Y & A samples)
Definition: pixfmt.h:172
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), big-endian
Definition: pixfmt.h:132
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), little-endian
Definition: pixfmt.h:157
#define AV_PIX_FMT_YA16
Definition: pixfmt.h:353
planar YUV 4:2:0, 12bpp, 1 plane for Y and 1 plane for the UV components, which are interleaved (firs...
Definition: pixfmt.h:85
#define AV_PIX_FMT_GBRAP12
Definition: pixfmt.h:389
#define AV_PIX_FMT_RGB48
Definition: pixfmt.h:354
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:371
#define fail()
Definition: checkasm.h:116
#define AV_PIX_FMT_GBRAP16
Definition: pixfmt.h:390
packed RGBA 8:8:8:8, 32bpp, RGBARGBA...
Definition: pixfmt.h:89
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
#define pass
Definition: fft_template.c:593
#define AV_PIX_FMT_GBRP16
Definition: pixfmt.h:387
#define AV_PIX_FMT_GRAY16
Definition: pixfmt.h:352
packed RGB 8:8:8, 24bpp, BGRBGR...
Definition: pixfmt.h:65
#define AV_PIX_FMT_YUV444P9
Definition: pixfmt.h:367
#define FF_ARRAY_ELEMS(a)
#define AV_PIX_FMT_YUV420P16
Definition: pixfmt.h:379
planar YUV 4:4:4 32bpp, (1 Cr & Cb sample per 1x1 Y & A samples)
Definition: pixfmt.h:173
packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
Definition: pixfmt.h:63
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:368
planar YUV 4:1:0, 9bpp, (1 Cr & Cb sample per 4x4 Y samples)
Definition: pixfmt.h:68
Y , 16bpp, big-endian.
Definition: pixfmt.h:93
HW acceleration through VDPAU, Picture.data[3] contains a VdpVideoSurface.
Definition: pixfmt.h:193
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:374
#define TEST(input, expected)
#define AV_PIX_FMT_YUV420P9
Definition: pixfmt.h:365
HW decoding through DXVA2, Picture.data[3] contains a LPDIRECT3DSURFACE9 pointer. ...
Definition: pixfmt.h:133
#define AV_PIX_FMT_BGR565
Definition: pixfmt.h:360
#define AV_PIX_FMT_AYUV64
Definition: pixfmt.h:412
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:369
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:375
Y , 10bpp, big-endian.
Definition: pixfmt.h:293
planar YUV 4:4:4, 48bpp, (1 Cr & Cb sample per 1x1 Y samples), little-endian
Definition: pixfmt.h:131
Y , 1bpp, 0 is black, 1 is white, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:72
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
Y , 8bpp.
Definition: pixfmt.h:70
Y , 1bpp, 0 is white, 1 is black, in each byte pixels are ordered from the msb to the lsb...
Definition: pixfmt.h:71
planar GBRA 4:4:4:4 32bpp
Definition: pixfmt.h:211
packed RGB 16:16:16, 48bpp, 16R, 16G, 16B, the 2-byte value for each R/G/B component is stored as big...
Definition: pixfmt.h:98
#define AV_PIX_FMT_RGB555
Definition: pixfmt.h:356
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples)
Definition: pixfmt.h:69
interleaved chroma YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:197
enum AVPixelFormat av_find_best_pix_fmt_of_2(enum AVPixelFormat dst_pix_fmt1, enum AVPixelFormat dst_pix_fmt2, enum AVPixelFormat src_pix_fmt, int has_alpha, int *loss_ptr)
Compute what kind of losses will occur when converting from one specific pixel format to another...
Definition: pixdesc.c:2653
Y , 16bpp, little-endian.
Definition: pixfmt.h:94
enum AVPixelFormat pixfmt
Definition: kmsgrab.c:202
#define AV_PIX_FMT_RGB565
Definition: pixfmt.h:355
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:95
packed RGB 8:8:8, 32bpp, XRGBXRGB... X=unused/undefined
Definition: pixfmt.h:233
packed YUV 4:1:1, 12bpp, Cb Y0 Y1 Cr Y2 Y3
Definition: pixfmt.h:78
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
#define AV_PIX_FMT_YUV422P16
Definition: pixfmt.h:380
planar YUV 4:2:2, 20bpp, (1 Cr & Cb sample per 2x1 Y samples), big-endian
Definition: pixfmt.h:156