Makefile: use $(RM) builtin
[mplayer.git] / libmpcodecs / img_format.c
blobc4884f3eca07e897d3442e28ac377d236333b128
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 "config.h"
20 #include "img_format.h"
21 #include "stdio.h"
22 #include "mpbswap.h"
24 const char *vo_format_name(int format)
26 static char unknown_format[20];
27 switch(format)
29 case IMGFMT_RGB1: return "RGB 1-bit";
30 case IMGFMT_RGB4: return "RGB 4-bit";
31 case IMGFMT_RG4B: return "RGB 4-bit per byte";
32 case IMGFMT_RGB8: return "RGB 8-bit";
33 case IMGFMT_RGB12: return "RGB 12-bit";
34 case IMGFMT_RGB15: return "RGB 15-bit";
35 case IMGFMT_RGB16: return "RGB 16-bit";
36 case IMGFMT_RGB24: return "RGB 24-bit";
37 // case IMGFMT_RGB32: return "RGB 32-bit";
38 case IMGFMT_RGB48LE: return "RGB 48-bit LE";
39 case IMGFMT_RGB48BE: return "RGB 48-bit BE";
40 case IMGFMT_BGR1: return "BGR 1-bit";
41 case IMGFMT_BGR4: return "BGR 4-bit";
42 case IMGFMT_BG4B: return "BGR 4-bit per byte";
43 case IMGFMT_BGR8: return "BGR 8-bit";
44 case IMGFMT_BGR12: return "BGR 12-bit";
45 case IMGFMT_BGR15: return "BGR 15-bit";
46 case IMGFMT_BGR16: return "BGR 16-bit";
47 case IMGFMT_BGR24: return "BGR 24-bit";
48 // case IMGFMT_BGR32: return "BGR 32-bit";
49 case IMGFMT_ABGR: return "ABGR";
50 case IMGFMT_BGRA: return "BGRA";
51 case IMGFMT_ARGB: return "ARGB";
52 case IMGFMT_RGBA: return "RGBA";
53 case IMGFMT_YVU9: return "Planar YVU9";
54 case IMGFMT_IF09: return "Planar IF09";
55 case IMGFMT_YV12: return "Planar YV12";
56 case IMGFMT_I420: return "Planar I420";
57 case IMGFMT_IYUV: return "Planar IYUV";
58 case IMGFMT_CLPL: return "Planar CLPL";
59 case IMGFMT_Y800: return "Planar Y800";
60 case IMGFMT_Y8: return "Planar Y8";
61 case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian";
62 case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian";
63 case IMGFMT_420P10_LE: return "Planar 420P 10-bit little-endian";
64 case IMGFMT_420P10_BE: return "Planar 420P 10-bit big-endian";
65 case IMGFMT_420P9_LE: return "Planar 420P 9-bit little-endian";
66 case IMGFMT_420P9_BE: return "Planar 420P 9-bit big-endian";
67 case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian";
68 case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian";
69 case IMGFMT_422P10_LE: return "Planar 422P 10-bit little-endian";
70 case IMGFMT_422P10_BE: return "Planar 422P 10-bit big-endian";
71 case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian";
72 case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian";
73 case IMGFMT_444P10_LE: return "Planar 444P 10-bit little-endian";
74 case IMGFMT_444P10_BE: return "Planar 444P 10-bit big-endian";
75 case IMGFMT_444P9_LE: return "Planar 444P 9-bit little-endian";
76 case IMGFMT_444P9_BE: return "Planar 444P 9-bit big-endian";
77 case IMGFMT_420A: return "Planar 420P with alpha";
78 case IMGFMT_444P: return "Planar 444P";
79 case IMGFMT_422P: return "Planar 422P";
80 case IMGFMT_411P: return "Planar 411P";
81 case IMGFMT_NV12: return "Planar NV12";
82 case IMGFMT_NV21: return "Planar NV21";
83 case IMGFMT_HM12: return "Planar NV12 Macroblock";
84 case IMGFMT_IUYV: return "Packed IUYV";
85 case IMGFMT_IY41: return "Packed IY41";
86 case IMGFMT_IYU1: return "Packed IYU1";
87 case IMGFMT_IYU2: return "Packed IYU2";
88 case IMGFMT_UYVY: return "Packed UYVY";
89 case IMGFMT_UYNV: return "Packed UYNV";
90 case IMGFMT_cyuv: return "Packed CYUV";
91 case IMGFMT_Y422: return "Packed Y422";
92 case IMGFMT_YUY2: return "Packed YUY2";
93 case IMGFMT_YUNV: return "Packed YUNV";
94 case IMGFMT_YVYU: return "Packed YVYU";
95 case IMGFMT_Y41P: return "Packed Y41P";
96 case IMGFMT_Y211: return "Packed Y211";
97 case IMGFMT_Y41T: return "Packed Y41T";
98 case IMGFMT_Y42T: return "Packed Y42T";
99 case IMGFMT_V422: return "Packed V422";
100 case IMGFMT_V655: return "Packed V655";
101 case IMGFMT_CLJR: return "Packed CLJR";
102 case IMGFMT_YUVP: return "Packed YUVP";
103 case IMGFMT_UYVP: return "Packed UYVP";
104 case IMGFMT_MPEGPES: return "Mpeg PES";
105 case IMGFMT_ZRMJPEGNI: return "Zoran MJPEG non-interlaced";
106 case IMGFMT_ZRMJPEGIT: return "Zoran MJPEG top field first";
107 case IMGFMT_ZRMJPEGIB: return "Zoran MJPEG bottom field first";
108 case IMGFMT_XVMC_MOCO_MPEG2: return "MPEG1/2 Motion Compensation";
109 case IMGFMT_XVMC_IDCT_MPEG2: return "MPEG1/2 Motion Compensation and IDCT";
110 case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration";
111 case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration";
112 case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration";
113 case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration";
114 case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
115 case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
117 snprintf(unknown_format,20,"Unknown 0x%04x",format);
118 return unknown_format;
121 int mp_get_chroma_shift(int format, int *x_shift, int *y_shift, int *component_bits)
123 int xs = 0, ys = 0;
124 int bpp;
125 int err = 0;
126 int bits = 8;
127 if ((format & 0xff0000f0) == 0x34000050)
128 format = bswap_32(format);
129 if ((format & 0xf00000ff) == 0x50000034) {
130 switch (format >> 24) {
131 case 0x50:
132 break;
133 case 0x51:
134 bits = 16;
135 break;
136 case 0x52:
137 bits = 10;
138 break;
139 case 0x53:
140 bits = 9;
141 break;
142 default:
143 err = 1;
144 break;
146 switch (format & 0x00ffffff) {
147 case 0x00343434: // 444
148 xs = 0;
149 ys = 0;
150 break;
151 case 0x00323234: // 422
152 xs = 1;
153 ys = 0;
154 break;
155 case 0x00303234: // 420
156 xs = 1;
157 ys = 1;
158 break;
159 case 0x00313134: // 411
160 xs = 2;
161 ys = 0;
162 break;
163 case 0x00303434: // 440
164 xs = 0;
165 ys = 1;
166 break;
167 default:
168 err = 1;
169 break;
171 } else switch (format) {
172 case IMGFMT_420A:
173 case IMGFMT_I420:
174 case IMGFMT_IYUV:
175 case IMGFMT_YV12:
176 xs = 1;
177 ys = 1;
178 break;
179 case IMGFMT_IF09:
180 case IMGFMT_YVU9:
181 xs = 2;
182 ys = 2;
183 break;
184 case IMGFMT_Y8:
185 case IMGFMT_Y800:
186 xs = 31;
187 ys = 31;
188 break;
189 default:
190 err = 1;
191 break;
193 if (x_shift) *x_shift = xs;
194 if (y_shift) *y_shift = ys;
195 if (component_bits) *component_bits = bits;
196 bpp = 8 + ((16 >> xs) >> ys);
197 if (format == IMGFMT_420A)
198 bpp += 8;
199 bpp *= (bits + 7) >> 3;
200 return err ? 0 : bpp;