Ignore svn changes up to r30324
[mplayer/glamo.git] / fmt-conversion.c
blob9371ab1a112f00e259287f46bea11d7af8168a83
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer 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
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include "mp_msg.h"
20 #include "libavutil/avutil.h"
21 #include "libmpcodecs/img_format.h"
22 #include "fmt-conversion.h"
24 static const struct {
25 int fmt;
26 enum PixelFormat pix_fmt;
27 } conversion_map[] = {
28 {IMGFMT_BGR32, PIX_FMT_RGB32},
29 {IMGFMT_BGR24, PIX_FMT_BGR24},
30 {IMGFMT_BGR16, PIX_FMT_RGB565},
31 {IMGFMT_BGR15, PIX_FMT_RGB555},
32 {IMGFMT_BGR8, PIX_FMT_RGB8},
33 {IMGFMT_BGR4, PIX_FMT_RGB4},
34 {IMGFMT_BGR1, PIX_FMT_MONOBLACK},
35 {IMGFMT_RGB1, PIX_FMT_MONOBLACK},
36 {IMGFMT_RG4B, PIX_FMT_BGR4_BYTE},
37 {IMGFMT_BG4B, PIX_FMT_RGB4_BYTE},
38 {IMGFMT_RGB48LE, PIX_FMT_RGB48LE},
39 {IMGFMT_RGB48BE, PIX_FMT_RGB48BE},
40 {IMGFMT_RGB32, PIX_FMT_BGR32},
41 {IMGFMT_RGB24, PIX_FMT_RGB24},
42 {IMGFMT_RGB16, PIX_FMT_BGR565},
43 {IMGFMT_RGB15, PIX_FMT_BGR555},
44 {IMGFMT_RGB8, PIX_FMT_BGR8},
45 {IMGFMT_RGB4, PIX_FMT_BGR4},
46 {IMGFMT_BGR8, PIX_FMT_PAL8},
47 {IMGFMT_YUY2, PIX_FMT_YUYV422},
48 {IMGFMT_UYVY, PIX_FMT_UYVY422},
49 {IMGFMT_NV12, PIX_FMT_NV12},
50 {IMGFMT_NV21, PIX_FMT_NV21},
51 {IMGFMT_Y800, PIX_FMT_GRAY8},
52 {IMGFMT_Y8, PIX_FMT_GRAY8},
53 {IMGFMT_YVU9, PIX_FMT_YUV410P},
54 {IMGFMT_IF09, PIX_FMT_YUV410P},
55 {IMGFMT_YV12, PIX_FMT_YUV420P},
56 {IMGFMT_I420, PIX_FMT_YUV420P},
57 {IMGFMT_IYUV, PIX_FMT_YUV420P},
58 {IMGFMT_411P, PIX_FMT_YUV411P},
59 {IMGFMT_422P, PIX_FMT_YUV422P},
60 {IMGFMT_444P, PIX_FMT_YUV444P},
61 {IMGFMT_440P, PIX_FMT_YUV440P},
63 {IMGFMT_420A, PIX_FMT_YUVA420P},
65 {IMGFMT_420P16_LE, PIX_FMT_YUV420P16LE},
66 {IMGFMT_420P16_BE, PIX_FMT_YUV420P16BE},
67 {IMGFMT_422P16_LE, PIX_FMT_YUV422P16LE},
68 {IMGFMT_422P16_BE, PIX_FMT_YUV422P16BE},
69 {IMGFMT_444P16_LE, PIX_FMT_YUV444P16LE},
70 {IMGFMT_444P16_BE, PIX_FMT_YUV444P16BE},
72 // YUVJ are YUV formats that use the full Y range and not just
73 // 16 - 235 (see colorspaces.txt).
74 // Currently they are all treated the same way.
75 {IMGFMT_YV12, PIX_FMT_YUVJ420P},
76 {IMGFMT_422P, PIX_FMT_YUVJ422P},
77 {IMGFMT_444P, PIX_FMT_YUVJ444P},
78 {IMGFMT_440P, PIX_FMT_YUVJ440P},
80 {IMGFMT_XVMC_MOCO_MPEG2, PIX_FMT_XVMC_MPEG2_MC},
81 {IMGFMT_XVMC_IDCT_MPEG2, PIX_FMT_XVMC_MPEG2_IDCT},
82 {IMGFMT_VDPAU_MPEG1, PIX_FMT_VDPAU_MPEG1},
83 {IMGFMT_VDPAU_MPEG2, PIX_FMT_VDPAU_MPEG2},
84 {IMGFMT_VDPAU_H264, PIX_FMT_VDPAU_H264},
85 {IMGFMT_VDPAU_WMV3, PIX_FMT_VDPAU_WMV3},
86 {IMGFMT_VDPAU_VC1, PIX_FMT_VDPAU_VC1},
87 {IMGFMT_VDPAU_MPEG4, PIX_FMT_VDPAU_MPEG4},
88 {0, PIX_FMT_NONE}
91 enum PixelFormat imgfmt2pixfmt(int fmt)
93 int i;
94 enum PixelFormat pix_fmt;
95 for (i = 0; conversion_map[i].fmt; i++)
96 if (conversion_map[i].fmt == fmt)
97 break;
98 pix_fmt = conversion_map[i].pix_fmt;
99 if (pix_fmt == PIX_FMT_NONE)
100 mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported format %s\n", vo_format_name(fmt));
101 return pix_fmt;
104 int pixfmt2imgfmt(enum PixelFormat pix_fmt)
106 int i;
107 int fmt;
108 for (i = 0; conversion_map[i].pix_fmt != PIX_FMT_NONE; i++)
109 if (conversion_map[i].pix_fmt == pix_fmt)
110 break;
111 fmt = conversion_map[i].fmt;
112 if (!fmt)
113 mp_msg(MSGT_GLOBAL, MSGL_ERR, "Unsupported PixelFormat %i\n", pix_fmt);
114 return fmt;