Mercurial > mplayer.hg
annotate libmpcodecs/vf_stereo3d.c @ 32538:28f08e7c2a0a
Adjust d_height instead of bad ad-hoc scaling.
Patch by Endre Kollr [taxy443 gmail com]
author | reimar |
---|---|
date | Sun, 14 Nov 2010 15:24:12 +0000 |
parents | 7ec524214684 |
children | 8341f48adbc5 |
rev | line source |
---|---|
32441 | 1 /* |
2 * Copyright (C) 2010 Gordon Schmidt <gordon.schmidt <at> s2000.tu-chemnitz.de> | |
3 * | |
4 * This file is part of MPlayer. | |
5 * | |
6 * MPlayer is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or | |
9 * (at your option) any later version. | |
10 * | |
11 * MPlayer is distributed in the hope that it will be useful, | |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 * GNU General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License along | |
17 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
19 */ | |
20 | |
21 //==includes==// | |
22 #include <stdio.h> | |
23 #include <stdlib.h> | |
24 #include <string.h> | |
25 | |
26 #include "config.h" | |
27 #include "mp_msg.h" | |
28 #include "help_mp.h" | |
29 | |
30 #include "img_format.h" | |
31 #include "mp_image.h" | |
32445
7ec524214684
Use proper include instead of extern declarations in the .c file.
reimar
parents:
32441
diff
changeset
|
32 #include "vd.h" |
32441 | 33 #include "vf.h" |
34 #include "m_struct.h" | |
35 | |
36 #include "libavutil/common.h" | |
37 #include "libvo/fastmemcpy.h" | |
38 | |
39 //==types==// | |
40 typedef enum stereo_code { | |
41 ANAGLYPH_RC_GRAY, //anaglyph red/cyan gray | |
42 ANAGLYPH_RC_HALF, //anaglyph red/cyan half colored | |
43 ANAGLYPH_RC_COLOR, //anaglyph red/cyan colored | |
44 ANAGLYPH_RC_DUBOIS, //anaglyph red/cyan dubois | |
45 ANAGLYPH_GM_GRAY, //anaglyph green/magenta gray | |
46 ANAGLYPH_GM_HALF, //anaglyph green/magenta half colored | |
47 ANAGLYPH_GM_COLOR, //anaglyph green/magenta colored | |
48 ANAGLYPH_YB_GRAY, //anaglyph yellow/blue gray | |
49 ANAGLYPH_YB_HALF, //anaglyph yellow/blue half colored | |
50 ANAGLYPH_YB_COLOR, //anaglyph yellow/blue colored | |
51 MONO_L, //mono output for debugging (left eye only) | |
52 MONO_R, //mono output for debugging (right eye only) | |
53 SIDE_BY_SIDE_LR, //side by side parallel (left eye left, right eye right) | |
54 SIDE_BY_SIDE_RL, //side by side crosseye (right eye left, left eye right) | |
55 ABOVE_BELOW_LR, //above-below (left eye above, right eye below) | |
56 ABOVE_BELOW_RL, //above-below (right eye above, left eye below) | |
57 ABOVE_BELOW_2_LR, //above-below with half height resolution | |
58 ABOVE_BELOW_2_RL, //above-below with half height resolution | |
59 STEREO_CODE_COUNT //no value set - TODO: needs autodetection | |
60 } stereo_code; | |
61 | |
62 typedef struct component { | |
63 stereo_code fmt; | |
64 unsigned int width; | |
65 unsigned int height; | |
66 unsigned int off_left; | |
67 unsigned int off_right; | |
68 unsigned int stride; | |
69 } component; | |
70 | |
71 //==global variables==// | |
72 static const int ana_coeff[10][3][6] = { | |
73 {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_GRAY | |
74 { 0, 0, 0, 19595, 38470, 7471}, | |
75 { 0, 0, 0, 19595, 38470, 7471}}, | |
76 {{19595, 38470, 7471, 0, 0, 0}, //ANAGLYPH_RC_HALF | |
77 { 0, 0, 0, 0, 65536, 0}, | |
78 { 0, 0, 0, 0, 0, 65536}}, | |
79 {{65536, 0, 0, 0, 0, 0}, //ANAGLYPH_RC_COLOR | |
80 { 0, 0, 0, 0, 65536, 0}, | |
81 { 0, 0, 0, 0, 0, 65536}}, | |
82 {{29891, 32800, 11559, -2849, -5763, -102}, //ANAGLYPH_RC_DUBOIS | |
83 {-2627, -2479, -1033, 24804, 48080, -1209}, | |
84 { -997, -1350, -358, -4729, -7403, 80373}}, | |
85 {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_GM_GRAY | |
86 {19595, 38470, 7471, 0, 0, 0}, | |
87 { 0, 0, 0, 19595, 38470, 7471}}, | |
88 {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_HALF | |
89 {19595, 38470, 7471, 0, 0, 0}, | |
90 { 0, 0, 0, 0, 0, 65536}}, | |
91 {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_GM_COLOR | |
92 { 0, 65536, 0, 0, 0, 0}, | |
93 { 0, 0, 0, 0, 0, 65536}}, | |
94 {{ 0, 0, 0, 19595, 38470, 7471}, //ANAGLYPH_YB_GRAY | |
95 { 0, 0, 0, 19595, 38470, 7471}, | |
96 {19595, 38470, 7471, 0, 0, 0}}, | |
97 {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_HALF | |
98 { 0, 0, 0, 0, 65536, 0}, | |
99 {19595, 38470, 7471, 0, 0, 0}}, | |
100 {{ 0, 0, 0, 65536, 0, 0}, //ANAGLYPH_YB_COLOR | |
101 { 0, 0, 0, 0, 65536, 0}, | |
102 { 0, 0, 65536, 0, 0, 0}} | |
103 }; | |
104 | |
105 struct vf_priv_s { | |
106 component in; | |
107 component out; | |
108 int ana_matrix[3][6]; | |
109 unsigned int width; | |
110 unsigned int height; | |
111 } const vf_priv_default = { | |
112 {SIDE_BY_SIDE_LR}, | |
113 {ANAGLYPH_RC_DUBOIS} | |
114 }; | |
115 | |
116 //==functions==// | |
117 static inline uint8_t ana_convert(int coeff[6], uint8_t left[3], uint8_t right[3]) | |
118 { | |
119 int sum; | |
120 | |
121 sum = coeff[0] * left[0] + coeff[3] * right[0]; //red in | |
122 sum += coeff[1] * left[1] + coeff[4] * right[1]; //green in | |
123 sum += coeff[2] * left[2] + coeff[5] * right[2]; //blue in | |
124 return av_clip_uint8(sum >> 16); | |
125 } | |
126 | |
127 static int config(struct vf_instance *vf, int width, int height, int d_width, | |
128 int d_height, unsigned int flags, unsigned int outfmt) | |
129 { | |
130 if ((width & 1) || (height & 1)) { | |
131 mp_msg(MSGT_VFILTER, MSGL_WARN, "[stereo3d] invalid height or width\n"); | |
132 return 0; | |
133 } | |
134 //default input values | |
135 vf->priv->width = width; | |
136 vf->priv->height = height; | |
137 vf->priv->in.width = width; | |
138 vf->priv->in.height = height; | |
139 vf->priv->in.off_left = 0; | |
140 vf->priv->in.off_right = 0; | |
141 vf->priv->in.stride = vf->priv->width * 3; | |
142 | |
143 //check input format | |
144 switch (vf->priv->in.fmt) { | |
145 case SIDE_BY_SIDE_LR: | |
146 vf->priv->width = width / 2; | |
147 vf->priv->in.off_right = vf->priv->width * 3; | |
148 vf->priv->in.stride = vf->priv->width * 6; | |
149 break; | |
150 case SIDE_BY_SIDE_RL: | |
151 vf->priv->width = width / 2; | |
152 vf->priv->in.off_left = vf->priv->width * 3; | |
153 vf->priv->in.stride = vf->priv->width * 6; | |
154 break; | |
32538 | 155 case ABOVE_BELOW_2_LR: |
156 d_height *= 2; | |
32441 | 157 case ABOVE_BELOW_LR: |
158 vf->priv->height = height / 2; | |
159 vf->priv->in.off_right = vf->priv->width * vf->priv->height * 3; | |
160 break; | |
32538 | 161 case ABOVE_BELOW_2_RL: |
162 d_height *= 2; | |
32441 | 163 case ABOVE_BELOW_RL: |
164 vf->priv->height = height / 2; | |
165 vf->priv->in.off_left = vf->priv->width * vf->priv->height * 3; | |
166 break; | |
167 default: | |
168 mp_msg(MSGT_VFILTER, MSGL_WARN, | |
169 "[stereo3d] stereo format of input is not supported\n"); | |
170 return 0; | |
171 break; | |
172 } | |
173 //default output values | |
174 vf->priv->out.width = vf->priv->width; | |
175 vf->priv->out.height = vf->priv->height; | |
176 vf->priv->out.off_left = 0; | |
177 vf->priv->out.off_right = 0; | |
178 vf->priv->out.stride = vf->priv->width * 3; | |
179 | |
180 //check output format | |
181 switch (vf->priv->out.fmt) { | |
182 case ANAGLYPH_RC_GRAY: | |
183 case ANAGLYPH_RC_HALF: | |
184 case ANAGLYPH_RC_COLOR: | |
185 case ANAGLYPH_RC_DUBOIS: | |
186 case ANAGLYPH_GM_GRAY: | |
187 case ANAGLYPH_GM_HALF: | |
188 case ANAGLYPH_GM_COLOR: | |
189 case ANAGLYPH_YB_GRAY: | |
190 case ANAGLYPH_YB_HALF: | |
191 case ANAGLYPH_YB_COLOR: | |
192 memcpy(vf->priv->ana_matrix, ana_coeff[vf->priv->out.fmt], | |
193 sizeof(vf->priv->ana_matrix)); | |
194 break; | |
195 case SIDE_BY_SIDE_LR: | |
196 vf->priv->out.width = vf->priv->width * 2; | |
197 vf->priv->out.off_right = vf->priv->width * 3; | |
198 vf->priv->out.stride = vf->priv->width * 6; | |
199 break; | |
200 case SIDE_BY_SIDE_RL: | |
201 vf->priv->out.width = vf->priv->width * 2; | |
202 vf->priv->out.off_left = vf->priv->width * 3; | |
203 vf->priv->out.stride = vf->priv->width * 6; | |
204 break; | |
32538 | 205 case ABOVE_BELOW_2_LR: |
206 d_height /= 2; | |
32441 | 207 case ABOVE_BELOW_LR: |
208 vf->priv->out.height = vf->priv->height * 2; | |
209 vf->priv->out.off_right = vf->priv->width * vf->priv->height * 3; | |
210 break; | |
32538 | 211 case ABOVE_BELOW_2_RL: |
212 d_height /= 2; | |
32441 | 213 case ABOVE_BELOW_RL: |
214 vf->priv->out.height = vf->priv->height * 2; | |
215 vf->priv->out.off_left = vf->priv->width * vf->priv->height * 3; | |
216 break; | |
217 case MONO_R: | |
218 //same as MONO_L only needs switching of input offsets | |
219 vf->priv->in.off_left = vf->priv->in.off_right; | |
220 //nobreak; | |
221 case MONO_L: | |
222 //use default settings | |
223 break; | |
224 default: | |
225 mp_msg(MSGT_VFILTER, MSGL_WARN, | |
226 "[stereo3d] stereo format of output is not supported\n"); | |
227 return 0; | |
228 break; | |
229 } | |
230 if (!opt_screen_size_x && !opt_screen_size_y) { | |
231 d_width = d_width * vf->priv->out.width / width; | |
232 d_height = d_height * vf->priv->out.height / height; | |
233 } | |
234 return vf_next_config(vf, vf->priv->out.width, vf->priv->out.height, | |
235 d_width, d_height, flags, outfmt); | |
236 } | |
237 | |
238 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) | |
239 { | |
240 mp_image_t *dmpi; | |
241 if (vf->priv->in.fmt == vf->priv->out.fmt) { //nothing to do | |
242 dmpi = mpi; | |
243 } else { | |
244 dmpi = vf_get_image(vf->next, IMGFMT_RGB24, MP_IMGTYPE_TEMP, 0, | |
245 vf->priv->out.width, vf->priv->out.height); | |
246 dmpi->h = vf->priv->out.height; | |
247 dmpi->width = vf->priv->out.width; | |
248 switch (vf->priv->out.fmt) { | |
249 case SIDE_BY_SIDE_LR: | |
250 case SIDE_BY_SIDE_RL: | |
251 case ABOVE_BELOW_LR: | |
252 case ABOVE_BELOW_RL: | |
253 case ABOVE_BELOW_2_LR: | |
254 case ABOVE_BELOW_2_RL: | |
32538 | 255 memcpy_pic(dmpi->planes[0] + vf->priv->out.off_left, |
256 mpi->planes[0] + vf->priv->in.off_left, | |
257 3 * vf->priv->width, | |
258 vf->priv->height, | |
259 vf->priv->out.stride, | |
260 vf->priv->in.stride); | |
261 memcpy_pic(dmpi->planes[0] + vf->priv->out.off_right, | |
262 mpi->planes[0] + vf->priv->in.off_right, | |
263 3 * vf->priv->width, | |
264 vf->priv->height, | |
265 vf->priv->out.stride, | |
266 vf->priv->in.stride); | |
32441 | 267 break; |
268 case MONO_L: | |
269 case MONO_R: | |
32538 | 270 memcpy_pic(dmpi->planes[0], |
271 mpi->planes[0] + vf->priv->in.off_left, | |
272 3 * vf->priv->width, | |
273 vf->priv->height, | |
274 vf->priv->out.stride, | |
275 vf->priv->in.stride); | |
32441 | 276 break; |
277 case ANAGLYPH_RC_GRAY: | |
278 case ANAGLYPH_RC_HALF: | |
279 case ANAGLYPH_RC_COLOR: | |
280 case ANAGLYPH_RC_DUBOIS: | |
281 case ANAGLYPH_GM_GRAY: | |
282 case ANAGLYPH_GM_HALF: | |
283 case ANAGLYPH_GM_COLOR: | |
284 case ANAGLYPH_YB_GRAY: | |
285 case ANAGLYPH_YB_HALF: | |
286 case ANAGLYPH_YB_COLOR: { | |
287 int x,y,il,ir,o; | |
288 unsigned char *source = mpi->planes[0]; | |
289 unsigned char *dest = dmpi->planes[0]; | |
290 unsigned int out_width = vf->priv->out.width; | |
291 int *ana_matrix[3]; | |
292 | |
293 for(int i = 0; i < 3; i++) | |
294 ana_matrix[i] = vf->priv->ana_matrix[i]; | |
295 | |
296 for (y = 0; y < vf->priv->out.height; y++) { | |
297 o = vf->priv->out.stride * y; | |
32538 | 298 il = vf->priv->in.off_left + y * |
32441 | 299 vf->priv->in.stride; |
32538 | 300 ir = vf->priv->in.off_right + y * |
32441 | 301 vf->priv->in.stride; |
302 for (x = 0; x < out_width; x++) { | |
303 dest[o ] = ana_convert( | |
304 ana_matrix[0], source + il, source + ir); //red out | |
305 dest[o + 1] = ana_convert( | |
306 ana_matrix[1], source + il, source + ir); //green out | |
307 dest[o + 2] = ana_convert( | |
308 ana_matrix[2], source + il, source + ir); //blue out | |
309 il += 3; | |
310 ir += 3; | |
311 o += 3; | |
312 } | |
313 } | |
314 break; | |
315 } | |
316 default: | |
317 mp_msg(MSGT_VFILTER, MSGL_WARN, | |
318 "[stereo3d] stereo format of output is not supported\n"); | |
319 return 0; | |
320 break; | |
321 } | |
322 } | |
323 return vf_next_put_image(vf, dmpi, pts); | |
324 } | |
325 | |
326 static int query_format(struct vf_instance *vf, unsigned int fmt) | |
327 { | |
328 switch (fmt) | |
329 case IMGFMT_RGB24: | |
330 return vf_next_query_format(vf, fmt); | |
331 return 0; | |
332 } | |
333 | |
334 static void uninit(vf_instance_t *vf) | |
335 { | |
336 free(vf->priv); | |
337 } | |
338 | |
339 static int vf_open(vf_instance_t *vf, char *args) | |
340 { | |
341 vf->config = config; | |
342 vf->uninit = uninit; | |
343 vf->put_image = put_image; | |
344 vf->query_format = query_format; | |
345 vf->default_reqs = VFCAP_ACCEPT_STRIDE; | |
346 | |
347 return 1; | |
348 } | |
349 | |
350 ///Presets usage | |
351 static const struct format_preset { | |
352 char* name; | |
353 stereo_code scode; | |
354 } vf_format_presets_defs[] = { | |
355 {"arcg", ANAGLYPH_RC_GRAY}, | |
356 {"anaglyph_red_cyan_gray", ANAGLYPH_RC_GRAY}, | |
357 {"arch", ANAGLYPH_RC_HALF}, | |
358 {"anaglyph_red_cyan_half_color", ANAGLYPH_RC_HALF}, | |
359 {"arcc", ANAGLYPH_RC_COLOR}, | |
360 {"anaglyph_red_cyan_color", ANAGLYPH_RC_COLOR}, | |
361 {"arcd", ANAGLYPH_RC_DUBOIS}, | |
362 {"anaglyph_red_cyan_dubios", ANAGLYPH_RC_DUBOIS}, | |
363 {"agmg", ANAGLYPH_GM_GRAY}, | |
364 {"anaglyph_green_magenta_gray", ANAGLYPH_GM_GRAY}, | |
365 {"agmh", ANAGLYPH_GM_HALF}, | |
366 {"anaglyph_green_magenta_half_color",ANAGLYPH_GM_HALF}, | |
367 {"agmc", ANAGLYPH_GM_COLOR}, | |
368 {"anaglyph_green_magenta_color", ANAGLYPH_GM_COLOR}, | |
369 {"aybg", ANAGLYPH_YB_GRAY}, | |
370 {"anaglyph_yellow_blue_gray", ANAGLYPH_YB_GRAY}, | |
371 {"aybh", ANAGLYPH_YB_HALF}, | |
372 {"anaglyph_yellow_blue_half_color", ANAGLYPH_YB_HALF}, | |
373 {"aybc", ANAGLYPH_YB_COLOR}, | |
374 {"anaglyph_yellow_blue_color", ANAGLYPH_YB_COLOR}, | |
375 {"ml", MONO_L}, | |
376 {"mono_left", MONO_L}, | |
377 {"mr", MONO_R}, | |
378 {"mono_right", MONO_R}, | |
379 {"sbsl", SIDE_BY_SIDE_LR}, | |
380 {"side_by_side_left_first", SIDE_BY_SIDE_LR}, | |
381 {"sbsr", SIDE_BY_SIDE_RL}, | |
382 {"side_by_side_right_first", SIDE_BY_SIDE_RL}, | |
383 {"abl", ABOVE_BELOW_LR}, | |
384 {"above_below_left_first", ABOVE_BELOW_LR}, | |
385 {"abr", ABOVE_BELOW_RL}, | |
386 {"above_below_right_first", ABOVE_BELOW_RL}, | |
387 {"ab2l", ABOVE_BELOW_2_LR}, | |
388 {"above_below_half_height_left_first", ABOVE_BELOW_2_LR}, | |
389 {"ab2r", ABOVE_BELOW_2_RL}, | |
390 {"above_below_half_height_right_first",ABOVE_BELOW_2_RL}, | |
391 { NULL, 0} | |
392 }; | |
393 | |
394 #define ST_OFF(f) M_ST_OFF(struct format_preset,f) | |
395 static const m_option_t vf_format_preset_fields_in[] = { | |
396 {"in", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL}, | |
397 { NULL, NULL, 0, 0, 0, 0, NULL } | |
398 }; | |
399 static const m_option_t vf_format_preset_fields_out[] = { | |
400 {"out", ST_OFF(scode), CONF_TYPE_INT, 0,0,0, NULL}, | |
401 { NULL, NULL, 0, 0, 0, 0, NULL } | |
402 }; | |
403 | |
404 static const m_struct_t vf_format_preset_in = { | |
405 "stereo_format_preset_in", | |
406 sizeof(struct format_preset), | |
407 NULL, | |
408 vf_format_preset_fields_in | |
409 }; | |
410 static const m_struct_t vf_format_preset_out = { | |
411 "stereo_format_preset_out", | |
412 sizeof(struct format_preset), | |
413 NULL, | |
414 vf_format_preset_fields_out | |
415 }; | |
416 | |
417 static const m_struct_t vf_opts; | |
418 static const m_obj_presets_t format_preset_in = { | |
419 (struct m_struct_st*)&vf_format_preset_in, | |
420 (struct m_struct_st*)&vf_opts, | |
421 (struct format_preset*)vf_format_presets_defs, | |
422 ST_OFF(name) | |
423 }; | |
424 static const m_obj_presets_t format_preset_out = { | |
425 (struct m_struct_st*)&vf_format_preset_out, | |
426 (struct m_struct_st*)&vf_opts, | |
427 (struct format_preset*)vf_format_presets_defs, | |
428 ST_OFF(name) | |
429 }; | |
430 | |
431 /// Now the options | |
432 #undef ST_OFF | |
433 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) | |
434 static const m_option_t vf_opts_fields[] = { | |
435 {"stereo_in", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, | |
436 (m_obj_presets_t*)&format_preset_in}, | |
437 {"stereo_out", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, | |
438 (m_obj_presets_t*)&format_preset_out}, | |
439 {"in", ST_OFF(in.fmt), CONF_TYPE_INT, 0,0,0, NULL}, | |
440 {"out", ST_OFF(out.fmt), CONF_TYPE_INT, 0,0,0, NULL}, | |
441 { NULL, NULL, 0, 0, 0, 0, NULL } | |
442 }; | |
443 | |
444 static const m_struct_t vf_opts = { | |
445 "stereo3d", | |
446 sizeof(struct vf_priv_s), | |
447 &vf_priv_default, | |
448 vf_opts_fields | |
449 }; | |
450 | |
451 | |
452 //==info struct==// | |
453 const vf_info_t vf_info_stereo3d = { | |
454 "stereoscopic 3d view", | |
455 "stereo3d", | |
456 "Gordon Schmidt", | |
457 "view stereoscopic videos", | |
458 vf_open, | |
459 &vf_opts | |
460 }; |