Mercurial > mplayer.hg
annotate libvo/vo_matrixview.c @ 36789:82a86ba65249
configure (cosmetic): Adjust indent and add blank lines.
author | ib |
---|---|
date | Wed, 19 Feb 2014 15:30:22 +0000 |
parents | 5d3f93051de9 |
children |
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" | |
36517 | 33 #define NO_DRAW_FRAME |
30140 | 34 #include "video_out_internal.h" |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
35 #include "libmpcodecs/vf.h" |
30140 | 36 #include "gl_common.h" |
37 #include "libswscale/swscale.h" | |
38 #include "libmpcodecs/vf_scale.h" | |
39 #include "osdep/timer.h" | |
40 | |
41 #include "matrixview.h" | |
42 | |
30153 | 43 static const vo_info_t info = { |
30140 | 44 "MatrixView (OpenGL)", |
45 "matrixview", | |
46 "Pigeon <pigeon@pigeond.net>", | |
47 "Based on MatrixView from rss-glx.sf.net" | |
48 }; | |
49 | |
30925
f8939d5b14b5
Mark some more LIBVO_EXTERN declarations as const where possible.
reimar
parents:
30633
diff
changeset
|
50 const LIBVO_EXTERN(matrixview) |
30140 | 51 |
52 static MPGLContext glctx; | |
53 | |
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 | |
36229 | 95 static void resize(void) |
96 { | |
97 matrixview_reshape(vo_dwidth, vo_dheight); | |
98 flip_page(); | |
99 } | |
30140 | 100 |
30153 | 101 static int config(uint32_t width, uint32_t height, |
102 uint32_t d_width, uint32_t d_height, | |
103 uint32_t flags, char *title, uint32_t format) | |
30140 | 104 { |
105 image_height = height; | |
30153 | 106 image_width = width; |
30140 | 107 image_format = format; |
108 | |
36219 | 109 if (mpglcontext_create_window(&glctx, d_width, d_height, flags, title) < 0) |
30153 | 110 return -1; |
30140 | 111 if (glctx.setGlWindow(&glctx) == SET_WINDOW_FAILED) |
112 return -1; | |
113 | |
30153 | 114 if (sws) |
30140 | 115 sws_freeContext(sws); |
116 | |
30153 | 117 sws = sws_getContextFromCmdLine(image_width, image_height, image_format, |
118 matrix_cols, matrix_rows, IMGFMT_Y8); | |
30140 | 119 if (!sws) { |
120 mp_msg(MSGT_VO, MSGL_ERR, "[matrixview] Cannot create SwsContext context\n"); | |
121 return -1; | |
122 } | |
123 | |
30153 | 124 if (!map_image[0]) |
30140 | 125 map_image[0] = calloc(matrix_cols, matrix_rows); |
126 | |
127 map_stride[0] = matrix_cols; | |
128 | |
129 matrixview_init(vo_dwidth, vo_dheight); | |
130 matrixview_matrix_resize(matrix_cols, matrix_rows); | |
131 | |
132 contrast_set(eq_contrast); | |
133 brightness_set(eq_brightness); | |
134 matrixview_reshape(vo_dwidth, vo_dheight); | |
36229 | 135 |
136 #ifdef CONFIG_GL_OSX | |
137 vo_osx_redraw_func = resize; | |
138 #endif | |
30140 | 139 return 0; |
140 } | |
141 | |
142 | |
143 static void check_events(void) | |
144 { | |
30153 | 145 int e = glctx.check_events(); |
146 if (e & VO_EVENT_RESIZE) { | |
36229 | 147 resize(); |
36230 | 148 } else if (e & VO_EVENT_EXPOSE) |
30153 | 149 flip_page(); |
30140 | 150 } |
151 | |
152 | |
153 static void draw_osd(void) | |
154 { | |
155 return; | |
156 } | |
157 | |
158 | |
159 static void flip_page(void) | |
160 { | |
36227 | 161 matrixview_draw(GetTimer(), map_image[0]); |
36226 | 162 // Needed at least on PPC Mac Mini on OSX. Should not hurt |
163 // much to do always. | |
164 mpglFlush(); | |
30140 | 165 glctx.swapGlBuffers(&glctx); |
166 } | |
167 | |
168 | |
169 | |
170 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y) | |
171 { | |
172 sws_scale(sws, src, stride, y, h, map_image, map_stride); | |
173 return 0; | |
174 } | |
175 | |
176 | |
177 static int query_format(uint32_t format) | |
178 { | |
179 int caps = VFCAP_CSP_SUPPORTED | VFCAP_HWSCALE_UP | VFCAP_HWSCALE_DOWN | VFCAP_ACCEPT_STRIDE; | |
180 | |
30153 | 181 switch (format) { |
182 case IMGFMT_YV12: | |
183 case IMGFMT_BGR32: | |
184 case IMGFMT_BGR24: | |
185 case IMGFMT_BGR16: | |
186 case IMGFMT_BGR15: | |
187 case IMGFMT_RGB32: | |
188 case IMGFMT_RGB24: | |
189 return caps; | |
190 default: | |
191 break; | |
30140 | 192 } |
193 | |
194 return 0; | |
195 } | |
196 | |
197 | |
198 static void uninit(void) | |
199 { | |
30153 | 200 if (!vo_config_count) |
201 return; | |
30140 | 202 uninit_mpglcontext(&glctx); |
203 free(map_image[0]); | |
204 map_image[0] = NULL; | |
205 sws_freeContext(sws); | |
206 sws = NULL; | |
207 } | |
208 | |
209 | |
210 static const opt_t subopts[] = | |
211 { | |
30153 | 212 { "rows", OPT_ARG_INT, &matrix_rows, int_pos }, |
213 { "cols", OPT_ARG_INT, &matrix_cols, int_pos }, | |
30140 | 214 { NULL } |
215 }; | |
216 | |
217 | |
218 static int preinit(const char *arg) | |
219 { | |
36219 | 220 enum MPGLType gltype = GLTYPE_AUTO; |
30153 | 221 if (!init_mpglcontext(&glctx, gltype)) |
222 return -1; | |
30140 | 223 |
224 matrix_rows = DEFAULT_MATRIX_ROWS; | |
225 matrix_cols = DEFAULT_MATRIX_COLS; | |
226 | |
30153 | 227 if (subopt_parse(arg, subopts) != 0) { |
30140 | 228 mp_msg(MSGT_VO, MSGL_FATAL, |
229 "\n-vo matrixview command line help:\n" | |
230 "Example: mplayer -vo matrixview:cols=320:rows=240\n" | |
231 "\n" | |
232 "Options:\n" | |
233 "\n" | |
234 " cols=<12-320>\n" | |
235 " Specify the number of columns of the matrix view, default %d\n" | |
236 "\n" | |
237 " rows=<12-240>\n" | |
238 " Specify the number of rows of the matrix view, default %d\n" | |
239 "\n" | |
240 , | |
241 DEFAULT_MATRIX_COLS, DEFAULT_MATRIX_ROWS | |
242 ); | |
243 return -1; | |
244 } | |
245 | |
246 return 0; | |
247 } | |
248 | |
249 | |
33305
ddb45e9443ec
Remove the variable arguments from the libvo control() functions.
iive
parents:
33301
diff
changeset
|
250 static int control(uint32_t request, void *data) |
30140 | 251 { |
252 switch (request) { | |
253 case VOCTRL_QUERY_FORMAT: | |
254 return query_format(*(uint32_t*)data); | |
255 case VOCTRL_ONTOP: | |
256 glctx.ontop(); | |
257 return VO_TRUE; | |
258 case VOCTRL_FULLSCREEN: | |
259 glctx.fullscreen(); | |
36229 | 260 resize(); |
30140 | 261 return VO_TRUE; |
262 case VOCTRL_BORDER: | |
263 glctx.border(); | |
264 return VO_TRUE; | |
265 case VOCTRL_GET_EQUALIZER: | |
266 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
267 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
268 |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
269 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
270 eq->value = eq_contrast; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
271 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
272 eq->value = eq_brightness; |
30140 | 273 } |
274 } | |
275 return VO_TRUE; | |
276 case VOCTRL_SET_EQUALIZER: | |
277 { | |
33301
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
278 vf_equalizer_t *eq=data; |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
279 if (strcasecmp(eq->item, "contrast") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
280 contrast_set(eq->value); |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
281 } else if (strcasecmp(eq->item, "brightness") == 0) { |
899d817e56fc
Implement control() VOCTRL_SET/GET_EQUALIZER using a vf_equalize struct,
iive
parents:
30925
diff
changeset
|
282 brightness_set(eq->value); |
30140 | 283 } |
284 } | |
285 return VO_TRUE; | |
286 case VOCTRL_UPDATE_SCREENINFO: | |
287 glctx.update_xinerama_info(); | |
288 return VO_TRUE; | |
289 } | |
290 return VO_NOTIMPL; | |
291 } |