Mercurial > mplayer.hg
comparison libvo/vo_svga.c @ 285:5cb4fdc94146
SVGAlib support - vo_svga.c added.
author | se7encode |
---|---|
date | Thu, 05 Apr 2001 08:42:02 +0000 |
parents | |
children | b2f3f2ab3787 |
comparison
equal
deleted
inserted
replaced
284:1ddac77b0d43 | 285:5cb4fdc94146 |
---|---|
1 /* | |
2 Video driver for SVGAlib - alpha version | |
3 by Zoltan Mark Vician <se7en@sch.bme.hu> | |
4 Code started: Mon Apr 1 23:25:47 2000 | |
5 */ | |
6 | |
7 #include <stdio.h> | |
8 #include <stdlib.h> | |
9 | |
10 #include <vga.h> | |
11 #include <vgagl.h> | |
12 | |
13 #include "config.h" | |
14 #include "video_out.h" | |
15 #include "video_out_internal.h" | |
16 | |
17 #include "yuv2rgb.h" | |
18 | |
19 LIBVO_EXTERN(svga) | |
20 | |
21 static vo_info_t vo_info = { | |
22 "SVGAlib", | |
23 "svga", | |
24 "Zoltan Mark Vician <se7en@sch.bme.hu>", | |
25 "" | |
26 }; | |
27 | |
28 // SVGAlib definitions | |
29 | |
30 GraphicsContext *screen; | |
31 GraphicsContext *virt; | |
32 | |
33 static uint8_t *scalebuf = NULL, *yuvbuf = NULL; | |
34 | |
35 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height | |
36 static float scaling = 0; | |
37 static uint32_t x_pos, y_pos; // Position | |
38 | |
39 // Order must not change! | |
40 #define _640x480x32K 0 // 17 | |
41 #define _640x480x64K 1 // 18 | |
42 #define _640x480x16M 2 // 19 | |
43 #define _640x480x16M32 3 // 34 | |
44 #define _800x600x32K 4 // 20 | |
45 #define _800x600x64K 5 // 21 | |
46 #define _800x600x16M 6 // 22 | |
47 #define _800x600x16M32 7 // 35 | |
48 #define _1024x768x32K 8 // 23 | |
49 #define _1024x768x64K 9 // 24 | |
50 #define _1024x768x16M 10 // 25 | |
51 #define _1024x768x16M32 11 // 36 | |
52 #define VID_MODE_NUM 12 | |
53 | |
54 static uint8_t vid_modes[VID_MODE_NUM]; | |
55 static uint8_t vid_mode; | |
56 | |
57 static uint32_t pformat; | |
58 static uint8_t bpp; | |
59 | |
60 static uint8_t checked = 0; | |
61 | |
62 static checksupportedmodes() { | |
63 int i; | |
64 | |
65 checked = 1; | |
66 vga_init(); | |
67 vga_disabledriverreport(); | |
68 for (i = 0; i < VID_MODE_NUM; i++) { | |
69 if (vga_hasmode(i) > 0) | |
70 vid_modes[i] = 1; | |
71 else vid_modes[i] = 0; | |
72 } | |
73 } | |
74 | |
75 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, | |
76 uint32_t d_height, uint32_t fullscreen, char *title, | |
77 uint32_t format) { | |
78 if (!checked) { | |
79 checksupportedmodes(); // Looking for available video modes | |
80 } | |
81 pformat = format; | |
82 if (d_width > 800) | |
83 switch (bpp) { | |
84 case 32: vid_mode = 36; break; | |
85 case 24: vid_mode = 25; break; | |
86 case 16: vid_mode = 24; break; | |
87 case 15: vid_mode = 23; break; | |
88 } | |
89 else | |
90 if (d_width > 640) | |
91 switch (bpp) { | |
92 case 32: vid_mode = 35; break; | |
93 case 24: vid_mode = 22; break; | |
94 case 16: vid_mode = 21; break; | |
95 case 15: vid_mode = 20; break; | |
96 } | |
97 else | |
98 switch (bpp) { | |
99 case 32: vid_mode = 34; break; | |
100 case 24: vid_mode = 19; break; | |
101 case 16: vid_mode = 18; break; | |
102 case 15: vid_mode = 17; break; | |
103 } | |
104 if (vga_setmode(vid_mode) == -1) | |
105 return(1); // error | |
106 if (gl_setcontextvga(vid_mode)) | |
107 return(1); // error | |
108 screen = gl_allocatecontext(); | |
109 gl_getcontext(screen); | |
110 if (gl_setcontextvgavirtual(vid_mode)) | |
111 return(1); // error | |
112 virt = gl_allocatecontext(); | |
113 gl_getcontext(virt); | |
114 gl_setcontext(virt); | |
115 gl_clearscreen(0); | |
116 | |
117 orig_w = width; | |
118 orig_h = height; | |
119 if (fullscreen && (WIDTH != orig_w)) { | |
120 maxw = WIDTH; | |
121 scaling = maxw / (orig_w*1.0); | |
122 maxh = (uint32_t) (orig_h * scaling); | |
123 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL); | |
124 } else { | |
125 maxw = orig_w; | |
126 maxh = orig_h; | |
127 } | |
128 | |
129 x_pos = (WIDTH - maxw) / 2; | |
130 y_pos = (HEIGHT - maxh) / 2; | |
131 | |
132 if (pformat == IMGFMT_YV12) { | |
133 yuv2rgb_init(bpp, MODE_RGB); | |
134 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL); | |
135 } | |
136 | |
137 printf("SVGAlib resolution: %dx%d %dbpp - ",WIDTH,HEIGHT,bpp); | |
138 if (maxw != orig_w || maxh != orig_h) printf("Video scaled to: %dx%d\n",maxw,maxh); | |
139 else printf("No video scaling\n"); | |
140 | |
141 return (0); | |
142 } | |
143 | |
144 static uint32_t query_format(uint32_t format) { | |
145 if (!checked) | |
146 checksupportedmodes(); // Looking for available video modes | |
147 switch (format) { | |
148 case IMGFMT_RGB32: | |
149 case IMGFMT_BGR|32: { | |
150 bpp = 32; | |
151 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]); | |
152 } | |
153 case IMGFMT_RGB24: | |
154 case IMGFMT_BGR|24: { | |
155 bpp = 24; | |
156 return (vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M]); | |
157 } | |
158 case IMGFMT_RGB16: | |
159 case IMGFMT_BGR|16: { | |
160 bpp = 16; | |
161 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]); | |
162 } | |
163 case IMGFMT_RGB15: | |
164 case IMGFMT_BGR|15: { | |
165 bpp = 15; | |
166 return (vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K]); | |
167 } | |
168 case IMGFMT_YV12: return (1); | |
169 } | |
170 return (0); | |
171 } | |
172 | |
173 static const vo_info_t* get_info(void) { | |
174 return (&vo_info); | |
175 } | |
176 | |
177 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src, | |
178 unsigned char *srca, int stride) { | |
179 int x, y, i; | |
180 uint8_t *dest, buf; | |
181 | |
182 // if (pformat == IMGFMT_YV12) { | |
183 for (y = 0; y < h; y++) { | |
184 dest = virt->vbuf + ((WIDTH * (y0 + y) + x0) * BYTESPERPIXEL); | |
185 for (x = 0; x < w; x++) { | |
186 if (srca[x]) { | |
187 for (i = 0; i < BYTESPERPIXEL; i++) | |
188 dest[i] = /*((dest[i] * srca[x]) >> 8) +*/ src[x] >> 6; | |
189 } | |
190 dest += BYTESPERPIXEL; | |
191 } | |
192 src += stride; | |
193 srca += stride; | |
194 } | |
195 // } | |
196 } | |
197 | |
198 static uint32_t draw_frame(uint8_t *src[]) { | |
199 if (pformat == IMGFMT_YV12) { | |
200 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2); | |
201 src[0] = yuvbuf; | |
202 } | |
203 if (scalebuf) { | |
204 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf); | |
205 src[0] = scalebuf; | |
206 } | |
207 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]); | |
208 } | |
209 | |
210 static uint32_t draw_slice(uint8_t *image[], int stride[], | |
211 int w, int h, int x, int y) { | |
212 uint8_t *src = yuvbuf; | |
213 | |
214 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]); | |
215 if (scalebuf) { | |
216 gl_scalebox(w, h, yuvbuf,(int) (w * scaling), (int) (h * scaling), scalebuf); | |
217 src = scalebuf; | |
218 } | |
219 gl_putbox(x + x_pos, y + y_pos, (int) (w * scaling), (int) (h * scaling), src); | |
220 } | |
221 | |
222 | |
223 static void flip_page(void) { | |
224 gl_fillbox(0, 0, WIDTH, y_pos, 0); | |
225 gl_fillbox(0, HEIGHT - y_pos, WIDTH, y_pos, 0); | |
226 vo_draw_text(WIDTH, HEIGHT, draw_alpha); | |
227 gl_copyscreen(screen); | |
228 } | |
229 | |
230 static void check_events(void) { | |
231 } | |
232 | |
233 static void uninit(void) { | |
234 gl_freecontext(screen); | |
235 gl_freecontext(virt); | |
236 vga_setmode(TEXT); | |
237 if (scalebuf) | |
238 free(scalebuf); | |
239 if (yuvbuf) | |
240 free(yuvbuf); | |
241 } | |
242 |