]> git.sesse.net Git - vlc/blob - modules/codec/avcodec/chroma.h
Simplify vlc fourcc/ffmpeg pix format conversion.
[vlc] / modules / codec / avcodec / chroma.h
1 /*****************************************************************************
2  * chroma.h: libavutil <-> libvlc conversion routines
3  *****************************************************************************
4  * Copyright (C) 1999-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8  *          Gildas Bazin <gbazin@videolan.org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 /*****************************************************************************
26  * Chroma fourcc -> ffmpeg_id mapping
27  *****************************************************************************/
28
29 #define VLC_FF( fcc, fav ) \
30     { VLC_FOURCC fcc, fav }
31
32 #if defined(WORDS_BIGENDIAN)
33 #   define VLC_FF_RGB_DEFAULT( fcc, le, be ) VLC_FF( fcc, be )
34 #else
35 #   define VLC_FF_RGB_DEFAULT( fcc, le, be ) VLC_FF( fcc, le )
36 #endif
37
38 static const struct
39 {
40     vlc_fourcc_t  i_chroma;
41     int  i_chroma_id;
42
43 } chroma_table[] =
44 {
45     /* Planar YUV formats */
46     VLC_FF( ('Y','U','V','A'), PIX_FMT_YUV444P ), /* Hack */
47
48     VLC_FF( ('I','4','4','4'), PIX_FMT_YUV444P ),
49     VLC_FF( ('J','4','4','4'), PIX_FMT_YUVJ444P ),
50
51     VLC_FF( ('I','4','2','2'), PIX_FMT_YUV422P ),
52     VLC_FF( ('J','4','2','2'), PIX_FMT_YUVJ422P ),
53
54     VLC_FF( ('I','4','2','0'), PIX_FMT_YUV420P ),
55     VLC_FF( ('Y','V','1','2'), PIX_FMT_YUV420P ),
56     VLC_FF( ('I','Y','U','V'), PIX_FMT_YUV420P ),
57     VLC_FF( ('J','4','2','0'), PIX_FMT_YUVJ420P ),
58     VLC_FF( ('I','4','1','1'), PIX_FMT_YUV411P ),
59     VLC_FF( ('I','4','1','0'), PIX_FMT_YUV410P ),
60     VLC_FF( ('Y','V','U','9'), PIX_FMT_YUV410P ),
61
62     /* Packed YUV formats */
63     VLC_FF( ('Y','U','Y','2'), PIX_FMT_YUV422 ),
64     VLC_FF( ('Y','U','Y','V'), PIX_FMT_YUV422 ),
65     VLC_FF( ('U','Y','V','Y'), PIX_FMT_UYVY422 ),
66
67     /* Packed RGB formats */
68     VLC_FF_RGB_DEFAULT( ('R','G','B','8'), PIX_FMT_RGB8,    PIX_FMT_BGR8 ),
69     VLC_FF_RGB_DEFAULT( ('R','V','1','5'), PIX_FMT_RGB555,  PIX_FMT_BGR555 ),
70     VLC_FF_RGB_DEFAULT( ('R','V','1','6'), PIX_FMT_RGB565,  PIX_FMT_BGR565 ),
71     VLC_FF_RGB_DEFAULT( ('R','V','2','4'), PIX_FMT_RGB24,   PIX_FMT_BGR24 ),
72
73     VLC_FF( ('R','V','3','2'), PIX_FMT_RGBA32 ),    // FIXME is that wanted
74
75 #if defined(PIX_FMT_RGBA)
76     VLC_FF( ('R','G','B','A'), PIX_FMT_RGBA ),
77 #endif
78     VLC_FF( ('G','R','E','Y'), PIX_FMT_GRAY8 ),
79
80     { 0, 0 }
81 };
82
83 static inline int GetFfmpegChroma( vlc_fourcc_t i_chroma )
84 {
85     int i;
86
87     for( i = 0; chroma_table[i].i_chroma != 0; i++ )
88     {
89         if( chroma_table[i].i_chroma == i_chroma )
90             return chroma_table[i].i_chroma_id;
91     }
92     return -1;
93 }
94
95 static inline vlc_fourcc_t GetVlcChroma( int i_ffmpeg_chroma )
96 {
97     int i;
98
99     /* TODO FIXME for rgb format we HAVE to set rgb mask/shift */
100     for( i = 0; chroma_table[i].i_chroma != 0; i++ )
101     {
102         if( chroma_table[i].i_chroma_id == i_ffmpeg_chroma )
103             return chroma_table[i].i_chroma;
104     }
105     return 0;
106 }