configure: Separate compiler warning flags from other flags
[mplayer.git] / libvo / vo_matrixview.c
blob496d122a4c0fc5cbdbdc3ab2632ddb136ddc777b
1 /*
2 * MatrixView video output driver for MPlayer
4 * by Pigeon <pigeon at pigeond.net>
6 * Based on MatrixView the screensaver from http://rss-glx.sf.net/
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 #include "config.h"
27 #include <stdint.h>
29 #include "mp_msg.h"
30 #include "subopt-helper.h"
31 #include "video_out.h"
32 #include "video_out_internal.h"
33 #include "gl_common.h"
34 #include "libswscale/swscale.h"
35 #include "libmpcodecs/vf_scale.h"
36 #include "osdep/timer.h"
38 #include "matrixview.h"
40 static const vo_info_t info = {
41 "MatrixView (OpenGL)",
42 "matrixview",
43 "Pigeon <pigeon@pigeond.net>",
44 "Based on MatrixView from rss-glx.sf.net"
47 const LIBVO_EXTERN(matrixview)
49 static MPGLContext glctx;
51 #ifdef CONFIG_GL_X11
52 static int wsGLXAttrib[] = {
53 GLX_RGBA,
54 GLX_RED_SIZE,1,
55 GLX_GREEN_SIZE,1,
56 GLX_BLUE_SIZE,1,
57 GLX_DEPTH_SIZE,1,
58 GLX_DOUBLEBUFFER,
59 None
61 #endif
63 static int int_pause;
64 static int eq_contrast;
65 static int eq_brightness;
66 static uint32_t image_width;
67 static uint32_t image_height;
68 static uint32_t image_format;
69 static struct SwsContext *sws;
71 static uint8_t *map_image[MP_MAX_PLANES];
72 static int map_stride[MP_MAX_PLANES];
74 #define DEFAULT_MATRIX_ROWS 96
75 #define DEFAULT_MATRIX_COLS 128
76 static int matrix_rows;
77 static int matrix_cols;
79 #define DEFAULT_CONTRAST 0.90f
80 #define CONTRAST_MULTIPLIER 0.02f
82 #define DEFAULT_BRIGHTNESS 1.0f
83 #define BRIGHTNESS_MULTIPLIER 0.02f
86 static void contrast_set(int value)
88 float contrast = value * CONTRAST_MULTIPLIER + DEFAULT_CONTRAST;
89 eq_contrast = value;
90 if (contrast < 0)
91 contrast = 0;
92 matrixview_contrast_set(contrast);
96 static void brightness_set(int value)
98 float brightness = value * BRIGHTNESS_MULTIPLIER + DEFAULT_BRIGHTNESS;
99 eq_brightness = value;
100 if (brightness < 0)
101 brightness = 0;
102 matrixview_brightness_set(brightness);
106 static int config(uint32_t width, uint32_t height,
107 uint32_t d_width, uint32_t d_height,
108 uint32_t flags, char *title, uint32_t format)
110 image_height = height;
111 image_width = width;
112 image_format = format;
114 int_pause = 0;
116 #ifdef CONFIG_GL_WIN32
117 if (glctx.type == GLTYPE_W32 && !vo_w32_config(d_width, d_height, flags))
118 return -1;
119 #endif
120 #ifdef CONFIG_GL_X11
121 if (glctx.type == GLTYPE_X11) {
122 XVisualInfo *vinfo=glXChooseVisual( mDisplay,mScreen,wsGLXAttrib );
123 if (vinfo == NULL) {
124 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] no GLX support present\n");
125 return -1;
127 mp_msg(MSGT_VO, MSGL_V, "[matrixview] GLX chose visual with ID 0x%x\n",
128 (int)vinfo->visualid);
130 vo_x11_create_vo_window(vinfo, vo_dx, vo_dy, d_width, d_height, flags,
131 XCreateColormap(mDisplay, mRootWin,
132 vinfo->visual, AllocNone),
133 "matrixview", title);
135 #endif /* CONFIG_GL_WIN32 */
136 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED)
137 return -1;
139 if (sws)
140 sws_freeContext(sws);
142 sws = sws_getContextFromCmdLine(image_width, image_height, image_format,
143 matrix_cols, matrix_rows, IMGFMT_Y8);
144 if (!sws) {
145 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] Cannot create SwsContext context\n");
146 return -1;
149 if (!map_image[0])
150 map_image[0] = calloc(matrix_cols, matrix_rows);
152 map_stride[0] = matrix_cols;
154 matrixview_init(vo_dwidth, vo_dheight);
155 matrixview_matrix_resize(matrix_cols, matrix_rows);
157 contrast_set(eq_contrast);
158 brightness_set(eq_brightness);
159 matrixview_reshape(vo_dwidth, vo_dheight);
160 return 0;
164 static void check_events(void)
166 int e = glctx.check_events();
167 if (e & VO_EVENT_RESIZE) {
168 matrixview_reshape(vo_dwidth, vo_dheight);
170 if (e & VO_EVENT_EXPOSE && int_pause)
171 flip_page();
175 static void draw_osd(void)
177 return;
181 static void flip_page(void)
183 matrixview_draw(vo_dwidth, vo_dheight, GetTimer(), 0.0, map_image[0]);
184 glctx.swapGlBuffers(&glctx);
189 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
191 sws_scale(sws, src, stride, y, h, map_image, map_stride);
192 return 0;
196 static int draw_frame(uint8_t *src[])
198 return 0;
202 static int query_format(uint32_t format)
204 int caps = VFCAP_CSP_SUPPORTED | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE;
206 switch (format) {
207 case IMGFMT_YV12:
208 case IMGFMT_BGR32:
209 case IMGFMT_BGR24:
210 case IMGFMT_BGR16:
211 case IMGFMT_BGR15:
212 case IMGFMT_RGB32:
213 case IMGFMT_RGB24:
214 return caps;
215 default:
216 break;
219 return 0;
223 static void uninit(void)
225 if (!vo_config_count)
226 return;
227 uninit_mpglcontext(&glctx);
228 free(map_image[0]);
229 map_image[0] = NULL;
230 sws_freeContext(sws);
231 sws = NULL;
235 static const opt_t subopts[] =
237 { "rows", OPT_ARG_INT, &matrix_rows, int_pos },
238 { "cols", OPT_ARG_INT, &matrix_cols, int_pos },
239 { NULL }
243 static int preinit(const char *arg)
245 enum MPGLType gltype = GLTYPE_X11;
246 #ifdef CONFIG_GL_WIN32
247 gltype = GLTYPE_W32;
248 #endif
249 if (!init_mpglcontext(&glctx, gltype))
250 return -1;
252 matrix_rows = DEFAULT_MATRIX_ROWS;
253 matrix_cols = DEFAULT_MATRIX_COLS;
255 if (subopt_parse(arg, subopts) != 0) {
256 mp_msg(MSGT_VO, MSGL_FATAL,
257 "\n-vo matrixview command line help:\n"
258 "Example: mplayer -vo matrixview:cols=320:rows=240\n"
259 "\n"
260 "Options:\n"
261 "\n"
262 " cols=<12-320>\n"
263 " Specify the number of columns of the matrix view, default %d\n"
264 "\n"
265 " rows=<12-240>\n"
266 " Specify the number of rows of the matrix view, default %d\n"
267 "\n"
269 DEFAULT_MATRIX_COLS, DEFAULT_MATRIX_ROWS
271 return -1;
274 return 0;
278 static int control(uint32_t request, void *data)
280 switch (request) {
281 case VOCTRL_PAUSE:
282 case VOCTRL_RESUME:
283 int_pause = (request == VOCTRL_PAUSE);
284 return VO_TRUE;
285 case VOCTRL_QUERY_FORMAT:
286 return query_format(*(uint32_t*)data);
287 case VOCTRL_ONTOP:
288 glctx.ontop();
289 return VO_TRUE;
290 case VOCTRL_FULLSCREEN:
291 glctx.fullscreen();
292 matrixview_reshape(vo_dwidth, vo_dheight);
293 return VO_TRUE;
294 case VOCTRL_BORDER:
295 glctx.border();
296 return VO_TRUE;
297 case VOCTRL_GET_EQUALIZER:
299 struct voctrl_get_equalizer_args *args = data;
300 if (strcasecmp(args->name, "contrast") == 0) {
301 *args->valueptr = eq_contrast;
303 else if (strcasecmp(args->name, "brightness") == 0) {
304 *args->valueptr = eq_brightness;
307 return VO_TRUE;
308 case VOCTRL_SET_EQUALIZER:
310 struct voctrl_set_equalizer_args *args = data;
311 if (strcasecmp(args->name, "contrast") == 0) {
312 contrast_set(args->value);
314 else if (strcasecmp(args->name, "brightness") == 0) {
315 brightness_set(args->value);
318 return VO_TRUE;
319 case VOCTRL_UPDATE_SCREENINFO:
320 glctx.update_xinerama_info();
321 return VO_TRUE;
323 return VO_NOTIMPL;