vo_glamo: sub.h was moved to sub directory in c9026cb3210205b07e2e068467a18ee40f9259a3
[mplayer/glamo.git] / libmpcodecs / img_format.c
blobd2a600cbf30796cfd2f6e45251ffa2c17cab91ba
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"
23 const char *vo_format_name(int format)
25 static char unknown_format[20];
26 switch(format)
28 case IMGFMT_RGB1: return "RGB 1-bit";
29 case IMGFMT_RGB4: return "RGB 4-bit";
30 case IMGFMT_RG4B: return "RGB 4-bit per byte";
31 case IMGFMT_RGB8: return "RGB 8-bit";
32 case IMGFMT_RGB12: return "RGB 12-bit";
33 case IMGFMT_RGB15: return "RGB 15-bit";
34 case IMGFMT_RGB16: return "RGB 16-bit";
35 case IMGFMT_RGB24: return "RGB 24-bit";
36 // case IMGFMT_RGB32: return "RGB 32-bit";
37 case IMGFMT_RGB48LE: return "RGB 48-bit LE";
38 case IMGFMT_RGB48BE: return "RGB 48-bit BE";
39 case IMGFMT_BGR1: return "BGR 1-bit";
40 case IMGFMT_BGR4: return "BGR 4-bit";
41 case IMGFMT_BG4B: return "BGR 4-bit per byte";
42 case IMGFMT_BGR8: return "BGR 8-bit";
43 case IMGFMT_BGR12: return "BGR 12-bit";
44 case IMGFMT_BGR15: return "BGR 15-bit";
45 case IMGFMT_BGR16: return "BGR 16-bit";
46 case IMGFMT_BGR24: return "BGR 24-bit";
47 // case IMGFMT_BGR32: return "BGR 32-bit";
48 case IMGFMT_ABGR: return "ABGR";
49 case IMGFMT_BGRA: return "BGRA";
50 case IMGFMT_ARGB: return "ARGB";
51 case IMGFMT_RGBA: return "RGBA";
52 case IMGFMT_YVU9: return "Planar YVU9";
53 case IMGFMT_IF09: return "Planar IF09";
54 case IMGFMT_YV12: return "Planar YV12";
55 case IMGFMT_I420: return "Planar I420";
56 case IMGFMT_IYUV: return "Planar IYUV";
57 case IMGFMT_CLPL: return "Planar CLPL";
58 case IMGFMT_Y800: return "Planar Y800";
59 case IMGFMT_Y8: return "Planar Y8";
60 case IMGFMT_420P16_LE: return "Planar 420P 16-bit little-endian";
61 case IMGFMT_420P16_BE: return "Planar 420P 16-bit big-endian";
62 case IMGFMT_422P16_LE: return "Planar 422P 16-bit little-endian";
63 case IMGFMT_422P16_BE: return "Planar 422P 16-bit big-endian";
64 case IMGFMT_444P16_LE: return "Planar 444P 16-bit little-endian";
65 case IMGFMT_444P16_BE: return "Planar 444P 16-bit big-endian";
66 case IMGFMT_420A: return "Planar 420P with alpha";
67 case IMGFMT_444P: return "Planar 444P";
68 case IMGFMT_422P: return "Planar 422P";
69 case IMGFMT_411P: return "Planar 411P";
70 case IMGFMT_NV12: return "Planar NV12";
71 case IMGFMT_NV21: return "Planar NV21";
72 case IMGFMT_HM12: return "Planar NV12 Macroblock";
73 case IMGFMT_IUYV: return "Packed IUYV";
74 case IMGFMT_IY41: return "Packed IY41";
75 case IMGFMT_IYU1: return "Packed IYU1";
76 case IMGFMT_IYU2: return "Packed IYU2";
77 case IMGFMT_UYVY: return "Packed UYVY";
78 case IMGFMT_UYNV: return "Packed UYNV";
79 case IMGFMT_cyuv: return "Packed CYUV";
80 case IMGFMT_Y422: return "Packed Y422";
81 case IMGFMT_YUY2: return "Packed YUY2";
82 case IMGFMT_YUNV: return "Packed YUNV";
83 case IMGFMT_YVYU: return "Packed YVYU";
84 case IMGFMT_Y41P: return "Packed Y41P";
85 case IMGFMT_Y211: return "Packed Y211";
86 case IMGFMT_Y41T: return "Packed Y41T";
87 case IMGFMT_Y42T: return "Packed Y42T";
88 case IMGFMT_V422: return "Packed V422";
89 case IMGFMT_V655: return "Packed V655";
90 case IMGFMT_CLJR: return "Packed CLJR";
91 case IMGFMT_YUVP: return "Packed YUVP";
92 case IMGFMT_UYVP: return "Packed UYVP";
93 case IMGFMT_MPEGPES: return "Mpeg PES";
94 case IMGFMT_MPEG4: return "MPEG-4";
95 case IMGFMT_ZRMJPEGNI: return "Zoran MJPEG non-interlaced";
96 case IMGFMT_ZRMJPEGIT: return "Zoran MJPEG top field first";
97 case IMGFMT_ZRMJPEGIB: return "Zoran MJPEG bottom field first";
98 case IMGFMT_XVMC_MOCO_MPEG2: return "MPEG1/2 Motion Compensation";
99 case IMGFMT_XVMC_IDCT_MPEG2: return "MPEG1/2 Motion Compensation and IDCT";
100 case IMGFMT_VDPAU_MPEG1: return "MPEG1 VDPAU acceleration";
101 case IMGFMT_VDPAU_MPEG2: return "MPEG2 VDPAU acceleration";
102 case IMGFMT_VDPAU_H264: return "H.264 VDPAU acceleration";
103 case IMGFMT_VDPAU_MPEG4: return "MPEG-4 Part 2 VDPAU acceleration";
104 case IMGFMT_VDPAU_WMV3: return "WMV3 VDPAU acceleration";
105 case IMGFMT_VDPAU_VC1: return "VC1 VDPAU acceleration";
107 snprintf(unknown_format,20,"Unknown 0x%04x",format);
108 return unknown_format;
111 int mp_get_chroma_shift(int format, int *x_shift, int *y_shift)
113 int xs = 0, ys = 0;
114 int bpp;
115 int bpp_factor = 1;
116 int err = 0;
117 switch (format) {
118 case IMGFMT_420P16_LE:
119 case IMGFMT_420P16_BE:
120 bpp_factor = 2;
121 case IMGFMT_420A:
122 case IMGFMT_I420:
123 case IMGFMT_IYUV:
124 case IMGFMT_YV12:
125 xs = 1;
126 ys = 1;
127 break;
128 case IMGFMT_IF09:
129 case IMGFMT_YVU9:
130 xs = 2;
131 ys = 2;
132 break;
133 case IMGFMT_444P16_LE:
134 case IMGFMT_444P16_BE:
135 bpp_factor = 2;
136 case IMGFMT_444P:
137 xs = 0;
138 ys = 0;
139 break;
140 case IMGFMT_422P16_LE:
141 case IMGFMT_422P16_BE:
142 bpp_factor = 2;
143 case IMGFMT_422P:
144 xs = 1;
145 ys = 0;
146 break;
147 case IMGFMT_411P:
148 xs = 2;
149 ys = 0;
150 break;
151 case IMGFMT_440P:
152 xs = 0;
153 ys = 1;
154 break;
155 case IMGFMT_Y8:
156 case IMGFMT_Y800:
157 xs = 31;
158 ys = 31;
159 break;
160 default:
161 err = 1;
162 break;
164 if (x_shift) *x_shift = xs;
165 if (y_shift) *y_shift = ys;
166 bpp = 8 + ((16 >> xs) >> ys);
167 if (format == IMGFMT_420A)
168 bpp += 8;
169 bpp *= bpp_factor;
170 return err ? 0 : bpp;