fourcc: fix non zero terminated fallback array
[vlc.git] / src / misc / fourcc.c
blob076117f355c08584cab2979b3ac00af1b2bfa725
1 /*****************************************************************************
2 * fourcc.c: fourcc helpers functions
3 *****************************************************************************
4 * Copyright © 2009-2011 Laurent Aimar
6 * Authors: Laurent Aimar <fenrir@videolan.org>
7 * Jean-Baptiste Kempf <jb@videolan.org>
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Lesser General Public License as published by
11 * the Free Software Foundation; either version 2.1 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public License
20 * along with this program; if not, write to the Free Software Foundation,
21 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
24 /*****************************************************************************
25 * Preamble
26 *****************************************************************************/
27 #ifdef HAVE_CONFIG_H
28 # include "config.h"
29 #endif
31 #include <vlc_common.h>
32 #include <vlc_fourcc.h>
33 #include <vlc_es.h>
34 #include <assert.h>
36 #include "fourcc_tables.h"
38 static int fourcc_cmp(const void *key, const void *ent)
40 return memcmp(key, ent, 4);
43 static vlc_fourcc_t Lookup(vlc_fourcc_t fourcc, const char **restrict dsc,
44 const struct fourcc_mapping *mapv, size_t mapc,
45 const struct fourcc_desc *dscv, size_t dscc)
47 const struct fourcc_mapping *mapping;
48 const struct fourcc_desc *desc;
50 mapping = bsearch(&fourcc, mapv, mapc, sizeof (*mapv), fourcc_cmp);
51 if (mapping != NULL)
53 if (dsc != NULL)
55 desc = bsearch(&fourcc, dscv, dscc, sizeof (*dscv), fourcc_cmp);
56 if (desc != NULL)
58 *dsc = desc->desc;
59 return mapping->fourcc;
62 fourcc = mapping->fourcc;
65 desc = bsearch(&fourcc, dscv, dscc, sizeof (*dscv), fourcc_cmp);
66 if (desc == NULL)
67 return 0; /* Unknown FourCC */
68 if (dsc != NULL)
69 *dsc = desc->desc;
70 return fourcc; /* Known FourCC (has a description) */
73 static vlc_fourcc_t LookupVideo(vlc_fourcc_t fourcc, const char **restrict dsc)
75 return Lookup(fourcc, dsc, mapping_video,
76 sizeof (mapping_video) / sizeof (mapping_video[0]),
77 desc_video, sizeof (desc_video) / sizeof (desc_video[0]));
80 static vlc_fourcc_t LookupAudio(vlc_fourcc_t fourcc, const char **restrict dsc)
82 return Lookup(fourcc, dsc, mapping_audio,
83 sizeof (mapping_audio) / sizeof (mapping_audio[0]),
84 desc_audio, sizeof (desc_audio) / sizeof (desc_audio[0]));
87 static vlc_fourcc_t LookupSpu(vlc_fourcc_t fourcc, const char **restrict dsc)
89 return Lookup(fourcc, dsc, mapping_spu,
90 sizeof (mapping_spu) / sizeof (mapping_spu[0]),
91 desc_spu, sizeof (desc_spu) / sizeof (desc_spu[0]));
94 static vlc_fourcc_t LookupCat(vlc_fourcc_t fourcc, const char **restrict dsc,
95 int cat)
97 switch (cat)
99 case VIDEO_ES:
100 return LookupVideo(fourcc, dsc);
101 case AUDIO_ES:
102 return LookupAudio(fourcc, dsc);
103 case SPU_ES:
104 return LookupSpu(fourcc, dsc);
107 vlc_fourcc_t ret = LookupVideo(fourcc, dsc);
108 if (!ret)
109 ret = LookupAudio(fourcc, dsc);
110 if (!ret)
111 ret = LookupSpu(fourcc, dsc);
112 return ret;
115 vlc_fourcc_t vlc_fourcc_GetCodec(int cat, vlc_fourcc_t fourcc)
117 vlc_fourcc_t codec = LookupCat(fourcc, NULL, cat);
118 return codec ? codec : fourcc;
121 vlc_fourcc_t vlc_fourcc_GetCodecFromString( int i_cat, const char *psz_fourcc )
123 if( !psz_fourcc || strlen(psz_fourcc) != 4 )
124 return 0;
125 return vlc_fourcc_GetCodec( i_cat,
126 VLC_FOURCC( psz_fourcc[0], psz_fourcc[1],
127 psz_fourcc[2], psz_fourcc[3] ) );
130 vlc_fourcc_t vlc_fourcc_GetCodecAudio( vlc_fourcc_t i_fourcc, int i_bits )
132 const int i_bytes = ( i_bits + 7 ) / 8;
134 if( i_fourcc == VLC_FOURCC( 'a', 'f', 'l', 't' ) )
136 switch( i_bytes )
138 case 4:
139 return VLC_CODEC_FL32;
140 case 8:
141 return VLC_CODEC_FL64;
142 default:
143 return 0;
146 else if( i_fourcc == VLC_FOURCC( 'a', 'r', 'a', 'w' ) )
148 switch( i_bytes )
150 case 1:
151 return VLC_CODEC_U8;
152 case 2:
153 return VLC_CODEC_S16L;
154 case 3:
155 return VLC_CODEC_S24L;
156 case 4:
157 return VLC_CODEC_S32L;
158 default:
159 return 0;
162 else if( i_fourcc == VLC_FOURCC( 't', 'w', 'o', 's' ) )
164 switch( i_bytes )
166 case 1:
167 return VLC_CODEC_S8;
168 case 2:
169 return VLC_CODEC_S16B;
170 case 3:
171 return VLC_CODEC_S24B;
172 case 4:
173 return VLC_CODEC_S32B;
174 default:
175 return 0;
178 else if( i_fourcc == VLC_FOURCC( 's', 'o', 'w', 't' ) )
180 switch( i_bytes )
182 case 1:
183 return VLC_CODEC_S8;
184 case 2:
185 return VLC_CODEC_S16L;
186 case 3:
187 return VLC_CODEC_S24L;
188 case 4:
189 return VLC_CODEC_S32L;
190 default:
191 return 0;
194 else
196 return vlc_fourcc_GetCodec( AUDIO_ES, i_fourcc );
200 const char *vlc_fourcc_GetDescription(int cat, vlc_fourcc_t fourcc)
202 const char *ret;
204 return LookupCat(fourcc, &ret, cat) ? ret : "";
208 /* */
209 #define VLC_CODEC_YUV_PLANAR_410 \
210 VLC_CODEC_I410, VLC_CODEC_YV9
212 #define VLC_CODEC_YUV_PLANAR_420 \
213 VLC_CODEC_I420, VLC_CODEC_YV12, VLC_CODEC_J420
215 #define VLC_CODEC_YUV_SEMIPLANAR_420 \
216 VLC_CODEC_NV12, VLC_CODEC_NV21
218 #define VLC_CODEC_YUV_PLANAR_420_16 \
219 VLC_CODEC_I420_16L, VLC_CODEC_I420_16B, VLC_CODEC_I420_12L, VLC_CODEC_I420_12B, VLC_CODEC_I420_10L, VLC_CODEC_I420_10B, VLC_CODEC_I420_9L, VLC_CODEC_I420_9B
221 #define VLC_CODEC_YUV_PLANAR_422 \
222 VLC_CODEC_I422, VLC_CODEC_J422
224 #define VLC_CODEC_YUV_SEMIPLANAR_422 \
225 VLC_CODEC_NV16, VLC_CODEC_NV61
227 #define VLC_CODEC_YUV_PLANAR_422_16 \
228 VLC_CODEC_I422_12L, VLC_CODEC_I422_12B, VLC_CODEC_I422_10L, VLC_CODEC_I422_10B, VLC_CODEC_I422_9L, VLC_CODEC_I422_9B
230 #define VLC_CODEC_YUV_PLANAR_440 \
231 VLC_CODEC_I440, VLC_CODEC_J440
233 #define VLC_CODEC_YUV_PLANAR_444 \
234 VLC_CODEC_I444, VLC_CODEC_J444
236 #define VLC_CODEC_YUV_SEMIPLANAR_444 \
237 VLC_CODEC_NV24, VLC_CODEC_NV42
239 #define VLC_CODEC_YUV_PLANAR_444_16 \
240 VLC_CODEC_I444_10L, VLC_CODEC_I444_10B, VLC_CODEC_I444_9L, VLC_CODEC_I444_9B, \
241 VLC_CODEC_I444_16L, VLC_CODEC_I444_16B, VLC_CODEC_I444_12L, VLC_CODEC_I444_12B
243 #define VLC_CODEC_YUV_PACKED \
244 VLC_CODEC_YUYV, VLC_CODEC_YVYU, \
245 VLC_CODEC_UYVY, VLC_CODEC_VYUY
247 #define VLC_CODEC_FALLBACK_420 \
248 VLC_CODEC_YUV_PLANAR_422, VLC_CODEC_YUV_PACKED, \
249 VLC_CODEC_YUV_PLANAR_444, VLC_CODEC_YUV_PLANAR_440, \
250 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211
252 static const vlc_fourcc_t p_I420_fallback[] = {
253 VLC_CODEC_I420, VLC_CODEC_YV12, VLC_CODEC_J420, VLC_CODEC_FALLBACK_420, 0
255 static const vlc_fourcc_t p_J420_fallback[] = {
256 VLC_CODEC_J420, VLC_CODEC_I420, VLC_CODEC_YV12, VLC_CODEC_FALLBACK_420, 0
258 static const vlc_fourcc_t p_YV12_fallback[] = {
259 VLC_CODEC_YV12, VLC_CODEC_I420, VLC_CODEC_J420, VLC_CODEC_FALLBACK_420, 0
261 static const vlc_fourcc_t p_NV12_fallback[] = {
262 VLC_CODEC_NV12, VLC_CODEC_I420, VLC_CODEC_J420, VLC_CODEC_FALLBACK_420, 0
265 #define VLC_CODEC_FALLBACK_420_16 \
266 VLC_CODEC_I420, VLC_CODEC_YV12, VLC_CODEC_J420, VLC_CODEC_FALLBACK_420
268 static const vlc_fourcc_t p_I420_9L_fallback[] = {
269 VLC_CODEC_I420_9L, VLC_CODEC_I420_9B, VLC_CODEC_FALLBACK_420_16, 0
271 static const vlc_fourcc_t p_I420_9B_fallback[] = {
272 VLC_CODEC_I420_9B, VLC_CODEC_I420_9L, VLC_CODEC_FALLBACK_420_16, 0
274 static const vlc_fourcc_t p_I420_10L_fallback[] = {
275 VLC_CODEC_I420_10L, VLC_CODEC_I420_10B, VLC_CODEC_FALLBACK_420_16, 0
277 static const vlc_fourcc_t p_I420_10B_fallback[] = {
278 VLC_CODEC_I420_10B, VLC_CODEC_I420_10L, VLC_CODEC_FALLBACK_420_16, 0
280 static const vlc_fourcc_t p_I420_12L_fallback[] = {
281 VLC_CODEC_I420_12L, VLC_CODEC_I420_12B, VLC_CODEC_FALLBACK_420_16, 0
283 static const vlc_fourcc_t p_I420_12B_fallback[] = {
284 VLC_CODEC_I420_12B, VLC_CODEC_I420_12L, VLC_CODEC_FALLBACK_420_16, 0
286 static const vlc_fourcc_t p_I420_16L_fallback[] = {
287 VLC_CODEC_I420_16L, VLC_CODEC_I420_16B, VLC_CODEC_FALLBACK_420_16, 0
289 static const vlc_fourcc_t p_I420_16B_fallback[] = {
290 VLC_CODEC_I420_16B, VLC_CODEC_I420_16L, VLC_CODEC_FALLBACK_420_16, 0
294 #define VLC_CODEC_FALLBACK_422 \
295 VLC_CODEC_YUV_PACKED, VLC_CODEC_YUV_PLANAR_420, \
296 VLC_CODEC_YUV_PLANAR_444, VLC_CODEC_YUV_PLANAR_440, \
297 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211
299 static const vlc_fourcc_t p_I422_fallback[] = {
300 VLC_CODEC_I422, VLC_CODEC_J422, VLC_CODEC_FALLBACK_422, 0
302 static const vlc_fourcc_t p_J422_fallback[] = {
303 VLC_CODEC_J422, VLC_CODEC_I422, VLC_CODEC_FALLBACK_422, 0
306 #define VLC_CODEC_FALLBACK_422_16 \
307 VLC_CODEC_I422, VLC_CODEC_J422, VLC_CODEC_FALLBACK_422
309 static const vlc_fourcc_t p_I422_9L_fallback[] = {
310 VLC_CODEC_I422_9L, VLC_CODEC_I422_9B, VLC_CODEC_FALLBACK_422_16, 0
312 static const vlc_fourcc_t p_I422_9B_fallback[] = {
313 VLC_CODEC_I422_9B, VLC_CODEC_I422_9L, VLC_CODEC_FALLBACK_422_16, 0
315 static const vlc_fourcc_t p_I422_10L_fallback[] = {
316 VLC_CODEC_I422_10L, VLC_CODEC_I422_10B, VLC_CODEC_FALLBACK_422_16, 0
318 static const vlc_fourcc_t p_I422_10B_fallback[] = {
319 VLC_CODEC_I422_10B, VLC_CODEC_I422_10L, VLC_CODEC_FALLBACK_422_16, 0
321 static const vlc_fourcc_t p_I422_12L_fallback[] = {
322 VLC_CODEC_I422_12L, VLC_CODEC_I422_12B, VLC_CODEC_FALLBACK_422_16, 0
324 static const vlc_fourcc_t p_I422_12B_fallback[] = {
325 VLC_CODEC_I422_12B, VLC_CODEC_I422_12L, VLC_CODEC_FALLBACK_422_16, 0
328 #define VLC_CODEC_FALLBACK_444 \
329 VLC_CODEC_YUV_PLANAR_422, VLC_CODEC_YUV_PACKED, \
330 VLC_CODEC_YUV_PLANAR_420, VLC_CODEC_YUV_PLANAR_440, \
331 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211
333 static const vlc_fourcc_t p_I444_fallback[] = {
334 VLC_CODEC_I444, VLC_CODEC_J444, VLC_CODEC_FALLBACK_444, 0
336 static const vlc_fourcc_t p_J444_fallback[] = {
337 VLC_CODEC_J444, VLC_CODEC_I444, VLC_CODEC_FALLBACK_444, 0
340 #define VLC_CODEC_FALLBACK_444_16 \
341 VLC_CODEC_I444, VLC_CODEC_J444, VLC_CODEC_FALLBACK_444
343 static const vlc_fourcc_t p_I444_9L_fallback[] = {
344 VLC_CODEC_I444_9L, VLC_CODEC_I444_9B, VLC_CODEC_FALLBACK_444_16, 0
346 static const vlc_fourcc_t p_I444_9B_fallback[] = {
347 VLC_CODEC_I444_9B, VLC_CODEC_I444_9L, VLC_CODEC_FALLBACK_444_16, 0
349 static const vlc_fourcc_t p_I444_10L_fallback[] = {
350 VLC_CODEC_I444_10L, VLC_CODEC_I444_10B, VLC_CODEC_FALLBACK_444_16, 0
352 static const vlc_fourcc_t p_I444_10B_fallback[] = {
353 VLC_CODEC_I444_10B, VLC_CODEC_I444_10L, VLC_CODEC_FALLBACK_444_16, 0
355 static const vlc_fourcc_t p_I444_12L_fallback[] = {
356 VLC_CODEC_I444_12L, VLC_CODEC_I444_12B, VLC_CODEC_FALLBACK_444_16, 0
358 static const vlc_fourcc_t p_I444_12B_fallback[] = {
359 VLC_CODEC_I444_12B, VLC_CODEC_I444_12L, VLC_CODEC_FALLBACK_444_16, 0
361 static const vlc_fourcc_t p_I444_16L_fallback[] = {
362 VLC_CODEC_I444_16L, VLC_CODEC_I444_16B, VLC_CODEC_FALLBACK_444_16, 0
364 static const vlc_fourcc_t p_I444_16B_fallback[] = {
365 VLC_CODEC_I444_16B, VLC_CODEC_I444_16L, VLC_CODEC_FALLBACK_444_16, 0
369 /* Fallbacks for cvpx */
370 static const vlc_fourcc_t p_CVPX_VIDEO_NV12_fallback[] = {
371 VLC_CODEC_CVPX_NV12, VLC_CODEC_I420, 0,
373 static const vlc_fourcc_t p_CVPX_VIDEO_UYVY_fallback[] = {
374 VLC_CODEC_CVPX_UYVY, VLC_CODEC_I420, 0,
376 static const vlc_fourcc_t p_CVPX_VIDEO_I420_fallback[] = {
377 VLC_CODEC_CVPX_I420, VLC_CODEC_I420, 0,
380 static const vlc_fourcc_t p_VAAPI_420_fallback[] = {
381 VLC_CODEC_VAAPI_420, VLC_CODEC_I420, 0,
384 static const vlc_fourcc_t p_I440_fallback[] = {
385 VLC_CODEC_I440,
386 VLC_CODEC_YUV_PLANAR_420,
387 VLC_CODEC_YUV_PLANAR_422,
388 VLC_CODEC_YUV_PLANAR_444,
389 VLC_CODEC_YUV_PACKED,
390 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211, 0
393 #define VLC_CODEC_FALLBACK_PACKED \
394 VLC_CODEC_YUV_PLANAR_422, VLC_CODEC_YUV_PLANAR_420, \
395 VLC_CODEC_YUV_PLANAR_444, VLC_CODEC_YUV_PLANAR_440, \
396 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211
398 static const vlc_fourcc_t p_YUYV_fallback[] = {
399 VLC_CODEC_YUYV,
400 VLC_CODEC_YVYU,
401 VLC_CODEC_UYVY,
402 VLC_CODEC_VYUY,
403 VLC_CODEC_FALLBACK_PACKED, 0
405 static const vlc_fourcc_t p_YVYU_fallback[] = {
406 VLC_CODEC_YVYU,
407 VLC_CODEC_YUYV,
408 VLC_CODEC_UYVY,
409 VLC_CODEC_VYUY,
410 VLC_CODEC_FALLBACK_PACKED, 0
412 static const vlc_fourcc_t p_UYVY_fallback[] = {
413 VLC_CODEC_UYVY,
414 VLC_CODEC_VYUY,
415 VLC_CODEC_YUYV,
416 VLC_CODEC_YVYU,
417 VLC_CODEC_FALLBACK_PACKED, 0
419 static const vlc_fourcc_t p_VYUY_fallback[] = {
420 VLC_CODEC_VYUY,
421 VLC_CODEC_UYVY,
422 VLC_CODEC_YUYV,
423 VLC_CODEC_YVYU,
424 VLC_CODEC_FALLBACK_PACKED, 0
427 static const vlc_fourcc_t *pp_YUV_fallback[] = {
428 p_YV12_fallback,
429 p_I420_fallback,
430 p_I420_9L_fallback,
431 p_I420_9B_fallback,
432 p_I420_10L_fallback,
433 p_I420_10B_fallback,
434 p_I420_12L_fallback,
435 p_I420_12B_fallback,
436 p_I420_16L_fallback,
437 p_I420_16B_fallback,
438 p_J420_fallback,
439 p_I422_fallback,
440 p_I422_9L_fallback,
441 p_I422_9B_fallback,
442 p_I422_10L_fallback,
443 p_I422_10B_fallback,
444 p_I422_12L_fallback,
445 p_I422_12B_fallback,
446 p_J422_fallback,
447 p_I444_fallback,
448 p_J444_fallback,
449 p_I444_9L_fallback,
450 p_I444_9B_fallback,
451 p_I444_10L_fallback,
452 p_I444_10B_fallback,
453 p_I444_12L_fallback,
454 p_I444_12B_fallback,
455 p_I444_16L_fallback,
456 p_I444_16B_fallback,
457 p_I440_fallback,
458 p_YUYV_fallback,
459 p_YVYU_fallback,
460 p_UYVY_fallback,
461 p_VYUY_fallback,
462 p_NV12_fallback,
463 p_CVPX_VIDEO_NV12_fallback,
464 p_CVPX_VIDEO_UYVY_fallback,
465 p_CVPX_VIDEO_I420_fallback,
466 p_VAAPI_420_fallback,
467 NULL,
470 static const vlc_fourcc_t p_list_YUV[] = {
471 VLC_CODEC_YUV_PLANAR_420,
472 VLC_CODEC_YUV_SEMIPLANAR_420,
473 VLC_CODEC_YUV_PLANAR_422,
474 VLC_CODEC_YUV_SEMIPLANAR_422,
475 VLC_CODEC_YUV_PLANAR_440,
476 VLC_CODEC_YUV_PLANAR_444,
477 VLC_CODEC_YUV_SEMIPLANAR_444,
478 VLC_CODEC_YUV_PACKED,
479 VLC_CODEC_I411, VLC_CODEC_YUV_PLANAR_410, VLC_CODEC_Y211,
480 VLC_CODEC_YUV_PLANAR_420_16,
481 VLC_CODEC_YUV_PLANAR_422_16,
482 VLC_CODEC_YUV_PLANAR_444_16,
483 VLC_CODEC_VDPAU_VIDEO_420,
484 VLC_CODEC_VDPAU_VIDEO_422,
485 VLC_CODEC_VDPAU_VIDEO_444,
486 VLC_CODEC_CVPX_NV12,
487 VLC_CODEC_CVPX_UYVY,
488 VLC_CODEC_CVPX_I420,
489 VLC_CODEC_VAAPI_420,
493 /* */
494 static const vlc_fourcc_t p_RGB32_fallback[] = {
495 VLC_CODEC_RGB32,
496 VLC_CODEC_RGB24,
497 VLC_CODEC_RGB16,
498 VLC_CODEC_RGB15,
499 VLC_CODEC_RGB8,
502 static const vlc_fourcc_t p_RGB24_fallback[] = {
503 VLC_CODEC_RGB24,
504 VLC_CODEC_RGB32,
505 VLC_CODEC_RGB16,
506 VLC_CODEC_RGB15,
507 VLC_CODEC_RGB8,
510 static const vlc_fourcc_t p_RGB16_fallback[] = {
511 VLC_CODEC_RGB16,
512 VLC_CODEC_RGB24,
513 VLC_CODEC_RGB32,
514 VLC_CODEC_RGB15,
515 VLC_CODEC_RGB8,
518 static const vlc_fourcc_t p_RGB15_fallback[] = {
519 VLC_CODEC_RGB15,
520 VLC_CODEC_RGB16,
521 VLC_CODEC_RGB24,
522 VLC_CODEC_RGB32,
523 VLC_CODEC_RGB8,
526 static const vlc_fourcc_t p_RGB8_fallback[] = {
527 VLC_CODEC_RGB8,
528 VLC_CODEC_RGB15,
529 VLC_CODEC_RGB16,
530 VLC_CODEC_RGB24,
531 VLC_CODEC_RGB32,
534 static const vlc_fourcc_t *pp_RGB_fallback[] = {
535 p_RGB32_fallback,
536 p_RGB24_fallback,
537 p_RGB16_fallback,
538 p_RGB15_fallback,
539 p_RGB8_fallback,
541 NULL,
545 /* */
546 static const vlc_fourcc_t *GetFallback( vlc_fourcc_t i_fourcc,
547 const vlc_fourcc_t *pp_fallback[],
548 const vlc_fourcc_t p_list[] )
550 for( unsigned i = 0; pp_fallback[i]; i++ )
552 if( pp_fallback[i][0] == i_fourcc )
553 return pp_fallback[i];
555 return p_list;
558 const vlc_fourcc_t *vlc_fourcc_GetYUVFallback( vlc_fourcc_t i_fourcc )
560 return GetFallback( i_fourcc, pp_YUV_fallback, p_list_YUV );
562 const vlc_fourcc_t *vlc_fourcc_GetRGBFallback( vlc_fourcc_t i_fourcc )
564 return GetFallback( i_fourcc, pp_RGB_fallback, p_RGB32_fallback );
567 bool vlc_fourcc_AreUVPlanesSwapped( vlc_fourcc_t a, vlc_fourcc_t b )
569 static const vlc_fourcc_t pp_swapped[][4] = {
570 { VLC_CODEC_YV12, VLC_CODEC_I420, VLC_CODEC_J420, 0 },
571 { VLC_CODEC_YV9, VLC_CODEC_I410, 0 },
572 { 0 }
575 for( int i = 0; pp_swapped[i][0]; i++ )
577 if( pp_swapped[i][0] == b )
579 vlc_fourcc_t t = a;
580 a = b;
581 b = t;
583 if( pp_swapped[i][0] != a )
584 continue;
585 for( int j = 1; pp_swapped[i][j]; j++ )
587 if( pp_swapped[i][j] == b )
588 return true;
591 return false;
594 bool vlc_fourcc_IsYUV(vlc_fourcc_t fcc)
596 for( unsigned i = 0; p_list_YUV[i]; i++ )
598 if( p_list_YUV[i] == fcc )
599 return true;
601 return false;
604 #define PLANAR(n, w_den, h_den, size, bits) \
605 { .plane_count = n, \
606 .p = { {.w = {1, 1}, .h = {1, 1}}, \
607 {.w = {1,w_den}, .h = {1,h_den}}, \
608 {.w = {1,w_den}, .h = {1,h_den}}, \
609 {.w = {1, 1}, .h = {1, 1}} }, \
610 .pixel_size = size, \
611 .pixel_bits = bits }
613 #define PLANAR_8(n, w_den, h_den) PLANAR(n, w_den, h_den, 1, 8)
614 #define PLANAR_16(n, w_den, h_den, bits) PLANAR(n, w_den, h_den, 2, bits)
616 #define PACKED_FMT(size, bits) \
617 { .plane_count = 1, \
618 .p = { {.w = {1,1}, .h = {1,1}} }, \
619 .pixel_size = size, \
620 .pixel_bits = bits }
622 /* Zero planes for hardware picture handles. Cannot be manipulated directly. */
623 #define FAKE_FMT() \
624 { .plane_count = 0, \
625 .p = { {.w = {1,1}, .h = {1,1}} }, \
626 .pixel_size = 0, \
627 .pixel_bits = 0 }
629 static const struct
631 vlc_fourcc_t p_fourcc[4];
632 vlc_chroma_description_t description;
633 } p_list_chroma_description[] = {
634 { { VLC_CODEC_I411 }, PLANAR_8(3, 4, 1) },
635 { { VLC_CODEC_YUV_PLANAR_410 }, PLANAR_8(3, 4, 4) },
636 { { VLC_CODEC_YUV_PLANAR_420 }, PLANAR_8(3, 2, 2) },
637 { { VLC_CODEC_NV12, VLC_CODEC_NV21 }, PLANAR_8(2, 1, 2) },
638 { { VLC_CODEC_YUV_PLANAR_422 }, PLANAR_8(3, 2, 1) },
639 { { VLC_CODEC_NV16, VLC_CODEC_NV61 }, PLANAR_8(2, 1, 1) },
640 { { VLC_CODEC_YUV_PLANAR_440 }, PLANAR_8(3, 1, 2) },
641 { { VLC_CODEC_YUV_PLANAR_444 }, PLANAR_8(3, 1, 1) },
642 { { VLC_CODEC_YUVA }, PLANAR_8(4, 1, 1) },
643 { { VLC_CODEC_YUV420A }, PLANAR_8(4, 2, 2) },
644 { { VLC_CODEC_YUV422A }, PLANAR_8(4, 2, 1) },
646 { { VLC_CODEC_GBR_PLANAR }, PLANAR_8(3, 1, 1) },
647 { { VLC_CODEC_GBR_PLANAR_9L,
648 VLC_CODEC_GBR_PLANAR_9B }, PLANAR_16(3, 1, 1, 9) },
649 { { VLC_CODEC_GBR_PLANAR_10L,
650 VLC_CODEC_GBR_PLANAR_10B }, PLANAR_16(3, 1, 1, 10) },
652 { { VLC_CODEC_I420_16L,
653 VLC_CODEC_I420_16B }, PLANAR_16(3, 2, 2, 16) },
654 { { VLC_CODEC_I420_12L,
655 VLC_CODEC_I420_12B }, PLANAR_16(3, 2, 2, 12) },
656 { { VLC_CODEC_I420_10L,
657 VLC_CODEC_I420_10B }, PLANAR_16(3, 2, 2, 10) },
658 { { VLC_CODEC_I420_9L,
659 VLC_CODEC_I420_9B }, PLANAR_16(3, 2, 2, 9) },
660 { { VLC_CODEC_I422_12L,
661 VLC_CODEC_I422_12B }, PLANAR_16(3, 2, 1, 12) },
662 { { VLC_CODEC_I422_10L,
663 VLC_CODEC_I422_10B }, PLANAR_16(3, 2, 1, 10) },
664 { { VLC_CODEC_I422_9L,
665 VLC_CODEC_I422_9B }, PLANAR_16(3, 2, 1, 9) },
666 { { VLC_CODEC_I444_12L,
667 VLC_CODEC_I444_12B }, PLANAR_16(3, 1, 1, 12) },
668 { { VLC_CODEC_I444_10L,
669 VLC_CODEC_I444_10B }, PLANAR_16(3, 1, 1, 10) },
670 { { VLC_CODEC_I444_9L,
671 VLC_CODEC_I444_9B }, PLANAR_16(3, 1, 1, 9) },
672 { { VLC_CODEC_I444_16L,
673 VLC_CODEC_I444_16B }, PLANAR_16(3, 1, 1, 16) },
674 { { VLC_CODEC_YUVA_444_10L,
675 VLC_CODEC_YUVA_444_10B }, PLANAR_16(4, 1, 1, 10) },
676 { { VLC_CODEC_P010 }, PLANAR_16(2, 1, 2, 10) },
678 { { VLC_CODEC_YUV_PACKED }, PACKED_FMT(2, 16) },
679 { { VLC_CODEC_RGB8, VLC_CODEC_GREY,
680 VLC_CODEC_YUVP, VLC_CODEC_RGBP }, PACKED_FMT(1, 8) },
682 { { VLC_CODEC_RGB15, 0 }, PACKED_FMT(2, 15) },
683 { { VLC_CODEC_RGB12, 0 }, PACKED_FMT(2, 12) },
684 { { VLC_CODEC_RGB16, 0 }, PACKED_FMT(2, 16) },
685 { { VLC_CODEC_RGB24, 0 }, PACKED_FMT(3, 24) },
686 { { VLC_CODEC_RGB32, 0 }, PACKED_FMT(4, 24) },
687 { { VLC_CODEC_RGBA, VLC_CODEC_ARGB,
688 VLC_CODEC_BGRA, }, PACKED_FMT(4, 32) },
690 { { VLC_CODEC_Y211, 0 }, { 1, { {{1,4}, {1,1}} }, 4, 32 } },
691 { { VLC_CODEC_XYZ12, 0 }, PACKED_FMT(6, 48) },
693 { { VLC_CODEC_VDPAU_VIDEO_420, VLC_CODEC_VDPAU_VIDEO_422,
694 VLC_CODEC_VDPAU_VIDEO_444, VLC_CODEC_VDPAU_OUTPUT },
695 FAKE_FMT() },
696 { { VLC_CODEC_ANDROID_OPAQUE, VLC_CODEC_MMAL_OPAQUE,
697 VLC_CODEC_D3D9_OPAQUE, VLC_CODEC_D3D11_OPAQUE },
698 FAKE_FMT() },
699 { { VLC_CODEC_D3D11_OPAQUE_10B, VLC_CODEC_D3D9_OPAQUE_10B },
700 FAKE_FMT() },
702 { { VLC_CODEC_CVPX_NV12, VLC_CODEC_CVPX_UYVY,
703 VLC_CODEC_CVPX_I420, VLC_CODEC_CVPX_BGRA },
704 FAKE_FMT() },
706 { { VLC_CODEC_VAAPI_420 }, FAKE_FMT() },
708 { { 0 }, FAKE_FMT() }
711 #undef PACKED_FMT
712 #undef PLANAR_16
713 #undef PLANAR_8
714 #undef PLANAR
716 const vlc_chroma_description_t *vlc_fourcc_GetChromaDescription( vlc_fourcc_t i_fourcc )
718 for( unsigned i = 0; p_list_chroma_description[i].p_fourcc[0]; i++ )
720 const vlc_fourcc_t *p_fourcc = p_list_chroma_description[i].p_fourcc;
721 for( unsigned j = 0; j < 4 && p_fourcc[j] != 0; j++ )
723 if( p_fourcc[j] == i_fourcc )
724 return &p_list_chroma_description[i].description;
727 return NULL;