Mercurial > mplayer.hg
annotate libvo/vo_matrixview.c @ 36222:5bff1fc3e7e5
vo_gl_tiled: ensure variables are always initialized.
This applies in particular if the backend isn't X11 or W32.
author | reimar |
---|---|
date | Sun, 09 Jun 2013 18:33:24 +0000 |
parents | 673719da1a92 |
children | 68cbead2e8a5 |
rev | line source |
---|---|
30140 | 1 /* |
2 * MatrixView video output driver for MPlayer | |
3 * | |
4 * by Pigeon <pigeon at pigeond.net> | |
5 * | |
6 * Based on MatrixView the screensaver from http://rss-glx.sf.net/ | |
7 * | |
8 * This file is part of MPlayer. | |
9 * | |
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. | |
14 * | |
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. | |
19 * | |
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. | |
23 */ | |
24 | |
25 #include "config.h" | |
26 | |
27 #include <stdint.h> | |
35903 | 28 #include <strings.h> |
30140 | 29 |
30 #include "mp_msg.h" | |
31 #include "subopt-helper.h" | |
32 #include "video_out.h" | |
33 #include "video_out_internal.h" | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
34 #include "libmpcodecs/vf.h" |
30140 | 35 #include "gl_common.h" |
36 #include "libswscale/swscale.h" | |
37 #include "libmpcodecs/vf_scale.h" | |
38 #include "osdep/timer.h" | |
39 | |
40 #include "matrixview.h" | |
41 | |
30153 | 42 static const vo_info_t info = { |
30140 | 43 "MatrixView (OpenGL)", |
44 "matrixview", | |
45 "Pigeon <pigeon@pigeond.net>", | |
46 "Based on MatrixView from rss-glx.sf.net" | |
47 }; | |
48 | |
30925
f8939d5b14b5
Mark some more LIBVO_EXTERN declarations as const where possible.
reimar
parents:
30633
diff
changeset
|
49 const LIBVO_EXTERN(matrixview) |
30140 | 50 |
51 static MPGLContext glctx; | |
52 | |
53 static int int_pause; | |
54 static int eq_contrast; | |
55 static int eq_brightness; | |
56 static uint32_t image_width; | |
57 static uint32_t image_height; | |
58 static uint32_t image_format; | |
59 static struct SwsContext *sws; | |
60 | |
61 static uint8_t *map_image[MP_MAX_PLANES]; | |
62 static int map_stride[MP_MAX_PLANES]; | |
63 | |
64 #define DEFAULT_MATRIX_ROWS 96 | |
65 #define DEFAULT_MATRIX_COLS 128 | |
66 static int matrix_rows; | |
67 static int matrix_cols; | |
68 | |
69 #define DEFAULT_CONTRAST 0.90f | |
70 #define CONTRAST_MULTIPLIER 0.02f | |
71 | |
72 #define DEFAULT_BRIGHTNESS 1.0f | |
73 #define BRIGHTNESS_MULTIPLIER 0.02f | |
74 | |
75 | |
76 static void contrast_set(int value) | |
77 { | |
78 float contrast = value * CONTRAST_MULTIPLIER + DEFAULT_CONTRAST; | |
79 eq_contrast = value; | |
30153 | 80 if (contrast < 0) |
81 contrast = 0; | |
30140 | 82 matrixview_contrast_set(contrast); |
83 } | |
84 | |
85 | |
86 static void brightness_set(int value) | |
87 { | |
88 float brightness = value * BRIGHTNESS_MULTIPLIER + DEFAULT_BRIGHTNESS; | |
89 eq_brightness = value; | |
30153 | 90 if (brightness < 0) |
91 brightness = 0; | |
30140 | 92 matrixview_brightness_set(brightness); |
93 } | |
94 | |
95 | |
30153 | 96 static int config(uint32_t width, uint32_t height, |
97 uint32_t d_width, uint32_t d_height, | |
98 uint32_t flags, char *title, uint32_t format) | |
30140 | 99 { |
100 image_height = height; | |
30153 | 101 image_width = width; |
30140 | 102 image_format = format; |
103 | |
104 int_pause = 0; | |
105 | |
36219 | 106 flags |= VOFLAG_DEPTH; |
107 if (mpglcontext_create_window(&glctx, d_width, d_height, flags, title) < 0) | |
30153 | 108 return -1; |
30140 | 109 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED) |
110 return -1; | |
111 | |
30153 | 112 if (sws) |
30140 | 113 sws_freeContext(sws); |
114 | |
30153 | 115 sws = sws_getContextFromCmdLine(image_width, image_height, image_format, |
116 matrix_cols, matrix_rows, IMGFMT_Y8); | |
30140 | 117 if (!sws) { |
118 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] Cannot create SwsContext context\n"); | |
119 return -1; | |
120 } | |
121 | |
30153 | 122 if (!map_image[0]) |
30140 | 123 map_image[0] = calloc(matrix_cols, matrix_rows); |
124 | |
125 map_stride[0] = matrix_cols; | |
126 | |
127 matrixview_init(vo_dwidth, vo_dheight); | |
128 matrixview_matrix_resize(matrix_cols, matrix_rows); | |
129 | |
130 contrast_set(eq_contrast); | |
131 brightness_set(eq_brightness); | |
132 matrixview_reshape(vo_dwidth, vo_dheight); | |
133 return 0; | |
134 } | |
135 | |
136 | |
137 static void check_events(void) | |
138 { | |
30153 | 139 int e = glctx.check_events(); |
140 if (e & VO_EVENT_RESIZE) { | |
30140 | 141 matrixview_reshape(vo_dwidth, vo_dheight); |
142 } | |
30153 | 143 if (e & VO_EVENT_EXPOSE && int_pause) |
144 flip_page(); | |
30140 | 145 } |
146 | |
147 | |
148 static void draw_osd(void) | |
149 { | |
150 return; | |
151 } | |
152 | |
153 | |
154 static void flip_page(void) | |
155 { | |
156 matrixview_draw(vo_dwidth, vo_dheight, GetTimer(), 0.0, map_image[0]); | |
157 glctx.swapGlBuffers(&glctx); | |
158 } | |
159 | |
160 | |
161 | |
162 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) | |
163 { | |
164 sws_scale(sws, src, stride, y, h, map_image, map_stride); | |
165 return 0; | |
166 } | |
167 | |
168 | |
169 static int draw_frame(uint8_t *src[]) | |
170 { | |
171 return 0; | |
172 } | |
173 | |
174 | |
175 static int query_format(uint32_t format) | |
176 { | |
177 int caps = VFCAP_CSP_SUPPORTED | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE; | |
178 | |
30153 | 179 switch (format) { |
180 case IMGFMT_YV12: | |
181 case IMGFMT_BGR32: | |
182 case IMGFMT_BGR24: | |
183 case IMGFMT_BGR16: | |
184 case IMGFMT_BGR15: | |
185 case IMGFMT_RGB32: | |
186 case IMGFMT_RGB24: | |
187 return caps; | |
188 default: | |
189 break; | |
30140 | 190 } |
191 | |
192 return 0; | |
193 } | |
194 | |
195 | |
196 static void uninit(void) | |
197 { | |
30153 | 198 if (!vo_config_count) |
199 return; | |
30140 | 200 uninit_mpglcontext(&glctx); |
201 free(map_image[0]); | |
202 map_image[0] = NULL; | |
203 sws_freeContext(sws); | |
204 sws = NULL; | |
205 } | |
206 | |
207 | |
208 static const opt_t subopts[] = | |
209 { | |
30153 | 210 { "rows", OPT_ARG_INT, &matrix_rows, int_pos }, |
211 { "cols", OPT_ARG_INT, &matrix_cols, int_pos }, | |
30140 | 212 { NULL } |
213 }; | |
214 | |
215 | |
216 static int preinit(const char *arg) | |
217 { | |
36219 | 218 enum MPGLType gltype = GLTYPE_AUTO; |
30153 | 219 if (!init_mpglcontext(&glctx, gltype)) |
220 return -1; | |
30140 | 221 |
222 matrix_rows = DEFAULT_MATRIX_ROWS; | |
223 matrix_cols = DEFAULT_MATRIX_COLS; | |
224 | |
30153 | 225 if (subopt_parse(arg, subopts) != 0) { |
30140 | 226 mp_msg(MSGT_VO, MSGL_FATAL, |
227 "\n-vo matrixview command line help:\n" | |
228 "Example: mplayer -vo matrixview:cols=320:rows=240\n" | |
229 "\n" | |
230 "Options:\n" | |
231 "\n" | |
232 " cols=<12-320>\n" | |
233 " Specify the number of columns of the matrix view, default %d\n" | |
234 "\n" | |
235 " rows=<12-240>\n" | |
236 " Specify the number of rows of the matrix view, default %d\n" | |
237 "\n" | |
238 , | |
239 DEFAULT_MATRIX_COLS, DEFAULT_MATRIX_ROWS | |
240 ); | |
241 return -1; | |
242 } | |
243 | |
244 return 0; | |
245 } | |
246 | |
247 | |
33305
ddb45e9443ec
Remove the variable arguments from the libvo control() functions.
iive
parents:
33301
diff
changeset
|
248 static int control(uint32_t request, void *data) |
30140 | 249 { |
250 switch (request) { | |
251 case VOCTRL_PAUSE: | |
252 case VOCTRL_RESUME: | |
253 int_pause = (request == VOCTRL_PAUSE); | |
254 return VO_TRUE; | |
255 case VOCTRL_QUERY_FORMAT: | |
256 return query_format(*(uint32_t*)data); | |
257 case VOCTRL_ONTOP: | |
258 glctx.ontop(); | |
259 return VO_TRUE; | |
260 case VOCTRL_FULLSCREEN: | |
261 glctx.fullscreen(); | |
262 matrixview_reshape(vo_dwidth, vo_dheight); | |
263 return VO_TRUE; | |
264 case VOCTRL_BORDER: | |
265 glctx.border(); | |
266 return VO_TRUE; | |
267 case VOCTRL_GET_EQUALIZER: | |
268 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
269 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
270 |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
271 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
272 eq->value = eq_contrast; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
273 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
274 eq->value = eq_brightness; |
30140 | 275 } |
276 } | |
277 return VO_TRUE; | |
278 case VOCTRL_SET_EQUALIZER: | |
279 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
280 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
281 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
282 contrast_set(eq->value); |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
283 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
284 brightness_set(eq->value); |
30140 | 285 } |
286 } | |
287 return VO_TRUE; | |
288 case VOCTRL_UPDATE_SCREENINFO: | |
289 glctx.update_xinerama_info(); | |
290 return VO_TRUE; | |
291 } | |
292 return VO_NOTIMPL; | |
293 } |