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.
20 #include "libavutil/avutil.h"
21 #include <libavutil/pixdesc.h>
22 #include "libmpcodecs/img_format.h"
23 #include "fmt-conversion.h"
27 enum PixelFormat pix_fmt
;
28 } conversion_map
[] = {
29 {IMGFMT_ARGB
, PIX_FMT_ARGB
},
30 {IMGFMT_BGRA
, PIX_FMT_BGRA
},
31 {IMGFMT_BGR24
, PIX_FMT_BGR24
},
32 {IMGFMT_BGR16BE
, PIX_FMT_RGB565BE
},
33 {IMGFMT_BGR16LE
, PIX_FMT_RGB565LE
},
34 {IMGFMT_BGR15BE
, PIX_FMT_RGB555BE
},
35 {IMGFMT_BGR15LE
, PIX_FMT_RGB555LE
},
36 {IMGFMT_BGR12BE
, PIX_FMT_RGB444BE
},
37 {IMGFMT_BGR12LE
, PIX_FMT_RGB444LE
},
38 {IMGFMT_BGR8
, PIX_FMT_RGB8
},
39 {IMGFMT_BGR4
, PIX_FMT_RGB4
},
40 {IMGFMT_BGR1
, PIX_FMT_MONOBLACK
},
41 {IMGFMT_RGB1
, PIX_FMT_MONOBLACK
},
42 {IMGFMT_RG4B
, PIX_FMT_BGR4_BYTE
},
43 {IMGFMT_BG4B
, PIX_FMT_RGB4_BYTE
},
44 {IMGFMT_RGB48LE
, PIX_FMT_RGB48LE
},
45 {IMGFMT_RGB48BE
, PIX_FMT_RGB48BE
},
46 {IMGFMT_ABGR
, PIX_FMT_ABGR
},
47 {IMGFMT_RGBA
, PIX_FMT_RGBA
},
48 {IMGFMT_RGB24
, PIX_FMT_RGB24
},
49 {IMGFMT_RGB16BE
, PIX_FMT_BGR565BE
},
50 {IMGFMT_RGB16LE
, PIX_FMT_BGR565LE
},
51 {IMGFMT_RGB15BE
, PIX_FMT_BGR555BE
},
52 {IMGFMT_RGB15LE
, PIX_FMT_BGR555LE
},
53 {IMGFMT_RGB12BE
, PIX_FMT_BGR444BE
},
54 {IMGFMT_RGB12LE
, PIX_FMT_BGR444LE
},
55 {IMGFMT_RGB8
, PIX_FMT_BGR8
},
56 {IMGFMT_RGB4
, PIX_FMT_BGR4
},
57 {IMGFMT_BGR8
, PIX_FMT_PAL8
},
58 {IMGFMT_YUY2
, PIX_FMT_YUYV422
},
59 {IMGFMT_UYVY
, PIX_FMT_UYVY422
},
60 {IMGFMT_NV12
, PIX_FMT_NV12
},
61 {IMGFMT_NV21
, PIX_FMT_NV21
},
62 {IMGFMT_Y800
, PIX_FMT_GRAY8
},
63 {IMGFMT_Y8
, PIX_FMT_GRAY8
},
64 {IMGFMT_YVU9
, PIX_FMT_YUV410P
},
65 {IMGFMT_IF09
, PIX_FMT_YUV410P
},
66 {IMGFMT_YV12
, PIX_FMT_YUV420P
},
67 {IMGFMT_I420
, PIX_FMT_YUV420P
},
68 {IMGFMT_IYUV
, PIX_FMT_YUV420P
},
69 {IMGFMT_411P
, PIX_FMT_YUV411P
},
70 {IMGFMT_422P
, PIX_FMT_YUV422P
},
71 {IMGFMT_444P
, PIX_FMT_YUV444P
},
72 {IMGFMT_440P
, PIX_FMT_YUV440P
},
74 {IMGFMT_420A
, PIX_FMT_YUVA420P
},
76 {IMGFMT_420P16_LE
, PIX_FMT_YUV420P16LE
},
77 {IMGFMT_420P16_BE
, PIX_FMT_YUV420P16BE
},
78 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 2, 0)
79 {IMGFMT_420P9_LE
, PIX_FMT_YUV420P9LE
},
80 {IMGFMT_420P9_BE
, PIX_FMT_YUV420P9BE
},
81 {IMGFMT_420P10_LE
, PIX_FMT_YUV420P10LE
},
82 {IMGFMT_420P10_BE
, PIX_FMT_YUV420P10BE
},
83 {IMGFMT_422P10_LE
, PIX_FMT_YUV422P10LE
},
84 {IMGFMT_422P10_BE
, PIX_FMT_YUV422P10BE
},
86 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 7, 0)
87 {IMGFMT_444P9_BE
, PIX_FMT_YUV444P9BE
},
88 {IMGFMT_444P9_LE
, PIX_FMT_YUV444P9LE
},
89 {IMGFMT_444P10_BE
, PIX_FMT_YUV444P10BE
},
90 {IMGFMT_444P10_LE
, PIX_FMT_YUV444P10LE
},
92 {IMGFMT_422P16_LE
, PIX_FMT_YUV422P16LE
},
93 {IMGFMT_422P16_BE
, PIX_FMT_YUV422P16BE
},
94 {IMGFMT_444P16_LE
, PIX_FMT_YUV444P16LE
},
95 {IMGFMT_444P16_BE
, PIX_FMT_YUV444P16BE
},
97 // YUVJ are YUV formats that use the full Y range and not just
98 // 16 - 235 (see colorspaces.txt).
99 // Currently they are all treated the same way.
100 {IMGFMT_YV12
, PIX_FMT_YUVJ420P
},
101 {IMGFMT_422P
, PIX_FMT_YUVJ422P
},
102 {IMGFMT_444P
, PIX_FMT_YUVJ444P
},
103 {IMGFMT_440P
, PIX_FMT_YUVJ440P
},
105 {IMGFMT_XVMC_MOCO_MPEG2
, PIX_FMT_XVMC_MPEG2_MC
},
106 {IMGFMT_XVMC_IDCT_MPEG2
, PIX_FMT_XVMC_MPEG2_IDCT
},
107 {IMGFMT_VDPAU_MPEG1
, PIX_FMT_VDPAU_MPEG1
},
108 {IMGFMT_VDPAU_MPEG2
, PIX_FMT_VDPAU_MPEG2
},
109 {IMGFMT_VDPAU_H264
, PIX_FMT_VDPAU_H264
},
110 {IMGFMT_VDPAU_WMV3
, PIX_FMT_VDPAU_WMV3
},
111 {IMGFMT_VDPAU_VC1
, PIX_FMT_VDPAU_VC1
},
112 {IMGFMT_VDPAU_MPEG4
, PIX_FMT_VDPAU_MPEG4
},
116 enum PixelFormat
imgfmt2pixfmt(int fmt
)
119 enum PixelFormat pix_fmt
;
120 for (i
= 0; conversion_map
[i
].fmt
; i
++)
121 if (conversion_map
[i
].fmt
== fmt
)
123 pix_fmt
= conversion_map
[i
].pix_fmt
;
124 if (pix_fmt
== PIX_FMT_NONE
)
125 mp_msg(MSGT_GLOBAL
, MSGL_ERR
, "Unsupported format %s\n", vo_format_name(fmt
));
129 int pixfmt2imgfmt(enum PixelFormat pix_fmt
)
132 for (i
= 0; conversion_map
[i
].pix_fmt
!= PIX_FMT_NONE
; i
++)
133 if (conversion_map
[i
].pix_fmt
== pix_fmt
)
135 int fmt
= conversion_map
[i
].fmt
;
137 #if LIBAVUTIL_VERSION_INT >= AV_VERSION_INT(51, 2, 0)
138 const char *fmtname
= av_get_pix_fmt_name(pix_fmt
);
139 mp_msg(MSGT_GLOBAL
, MSGL_ERR
, "Unsupported PixelFormat %s (%d)\n",
140 fmtname
? fmtname
: "INVALID", pix_fmt
);
142 mp_msg(MSGT_GLOBAL
, MSGL_ERR
, "Unsupported PixelFormat %i\n", pix_fmt
);