285
|
1 /*
|
292
|
2 Video driver for SVGAlib - alpha, slow
|
285
|
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];
|
290
|
55 static vid_mode_nums[VID_MODE_NUM] = {17,18,19,34,20,21,22,35,23,24,25,36};
|
285
|
56 static uint8_t vid_mode;
|
327
|
57 static uint8_t bpp;
|
285
|
58
|
|
59 static uint32_t pformat;
|
|
60
|
|
61 static uint8_t checked = 0;
|
|
62
|
286
|
63 static void checksupportedmodes() {
|
285
|
64 int i;
|
|
65
|
|
66 checked = 1;
|
|
67 vga_init();
|
|
68 vga_disabledriverreport();
|
|
69 for (i = 0; i < VID_MODE_NUM; i++) {
|
290
|
70 if (vga_hasmode(vid_mode_nums[i]) > 0)
|
285
|
71 vid_modes[i] = 1;
|
|
72 else vid_modes[i] = 0;
|
|
73 }
|
|
74 }
|
|
75
|
|
76 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width,
|
|
77 uint32_t d_height, uint32_t fullscreen, char *title,
|
|
78 uint32_t format) {
|
|
79 if (!checked) {
|
|
80 checksupportedmodes(); // Looking for available video modes
|
|
81 }
|
|
82 pformat = format;
|
327
|
83 if (format == IMGFMT_YV12) bpp = 32;
|
292
|
84 else bpp = format & 255;
|
343
|
85 if (width > 800)
|
285
|
86 switch (bpp) {
|
|
87 case 32: vid_mode = 36; break;
|
|
88 case 24: vid_mode = 25; break;
|
|
89 case 16: vid_mode = 24; break;
|
|
90 case 15: vid_mode = 23; break;
|
|
91 }
|
|
92 else
|
343
|
93 if (width > 640)
|
285
|
94 switch (bpp) {
|
|
95 case 32: vid_mode = 35; break;
|
|
96 case 24: vid_mode = 22; break;
|
|
97 case 16: vid_mode = 21; break;
|
|
98 case 15: vid_mode = 20; break;
|
|
99 }
|
|
100 else
|
|
101 switch (bpp) {
|
|
102 case 32: vid_mode = 34; break;
|
|
103 case 24: vid_mode = 19; break;
|
|
104 case 16: vid_mode = 18; break;
|
|
105 case 15: vid_mode = 17; break;
|
|
106 }
|
286
|
107 if (vga_setmode(vid_mode) == -1){
|
|
108 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
|
285
|
109 return(1); // error
|
286
|
110 }
|
|
111 if (gl_setcontextvga(vid_mode)){
|
|
112 printf("vo_svga: gl_setcontextvga(%d) failed.\n",vid_mode);
|
285
|
113 return(1); // error
|
286
|
114 }
|
285
|
115 screen = gl_allocatecontext();
|
|
116 gl_getcontext(screen);
|
286
|
117 if (gl_setcontextvgavirtual(vid_mode)){
|
|
118 printf("vo_svga: gl_setcontextvgavirtual(%d) failed.\n",vid_mode);
|
285
|
119 return(1); // error
|
286
|
120 }
|
285
|
121 virt = gl_allocatecontext();
|
|
122 gl_getcontext(virt);
|
|
123 gl_setcontext(virt);
|
|
124 gl_clearscreen(0);
|
|
125
|
|
126 orig_w = width;
|
|
127 orig_h = height;
|
343
|
128 if ((fullscreen & 0x04) && (WIDTH != orig_w)) {
|
292
|
129 if (((orig_w*1.0) / orig_h) < (4.0/3)) {
|
|
130 maxh = HEIGHT;
|
|
131 scaling = maxh / (orig_h * 1.0);
|
|
132 maxw = (uint32_t) (orig_w * scaling);
|
|
133 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
134 } else {
|
|
135 maxw = WIDTH;
|
|
136 scaling = maxw / (orig_w * 1.0);
|
|
137 maxh = (uint32_t) (orig_h * scaling);
|
|
138 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
139 }
|
285
|
140 } else {
|
|
141 maxw = orig_w;
|
|
142 maxh = orig_h;
|
|
143 }
|
|
144
|
|
145 x_pos = (WIDTH - maxw) / 2;
|
|
146 y_pos = (HEIGHT - maxh) / 2;
|
|
147
|
|
148 if (pformat == IMGFMT_YV12) {
|
|
149 yuv2rgb_init(bpp, MODE_RGB);
|
|
150 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
151 }
|
|
152
|
327
|
153 // printf("Vid_mode: %d\n",vid_mode);
|
292
|
154 printf("SVGAlib resolution: %dx%d %dbpp - ", WIDTH, HEIGHT, bpp);
|
293
|
155 if (maxw != orig_w || maxh != orig_h) printf("Video scaled to: %dx%d\n",maxw,maxh);
|
285
|
156 else printf("No video scaling\n");
|
|
157
|
|
158 return (0);
|
|
159 }
|
|
160
|
|
161 static uint32_t query_format(uint32_t format) {
|
|
162 if (!checked)
|
|
163 checksupportedmodes(); // Looking for available video modes
|
|
164 switch (format) {
|
|
165 case IMGFMT_RGB32:
|
|
166 case IMGFMT_BGR|32: {
|
|
167 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]);
|
|
168 }
|
|
169 case IMGFMT_RGB24:
|
|
170 case IMGFMT_BGR|24: {
|
|
171 return (vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M]);
|
|
172 }
|
|
173 case IMGFMT_RGB16:
|
|
174 case IMGFMT_BGR|16: {
|
|
175 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]);
|
|
176 }
|
|
177 case IMGFMT_RGB15:
|
|
178 case IMGFMT_BGR|15: {
|
|
179 return (vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K]);
|
|
180 }
|
|
181 case IMGFMT_YV12: return (1);
|
|
182 }
|
|
183 return (0);
|
|
184 }
|
|
185
|
|
186 static const vo_info_t* get_info(void) {
|
|
187 return (&vo_info);
|
|
188 }
|
|
189
|
|
190 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|
191 unsigned char *srca, int stride) {
|
327
|
192 switch (bpp) {
|
|
193 case 32:
|
|
194 vo_draw_alpha_rgb32(w, h, src, srca, stride, virt->vbuf+4*(y0*WIDTH+x0), 4*WIDTH);
|
|
195 break;
|
|
196 case 24:
|
|
197 vo_draw_alpha_rgb24(w, h, src, srca, stride, virt->vbuf+3*(y0*WIDTH+x0), 3*WIDTH);
|
|
198 break;
|
|
199 case 16:
|
|
200 vo_draw_alpha_rgb16(w, h, src, srca, stride, virt->vbuf+2*(y0*WIDTH+x0), 2*WIDTH);
|
|
201 break;
|
|
202 case 15:
|
|
203 vo_draw_alpha_rgb15(w, h, src, srca, stride, virt->vbuf+2*(y0*WIDTH+x0), 2*WIDTH);
|
|
204 break;
|
|
205 }
|
285
|
206 }
|
|
207
|
|
208 static uint32_t draw_frame(uint8_t *src[]) {
|
|
209 if (pformat == IMGFMT_YV12) {
|
|
210 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2);
|
|
211 src[0] = yuvbuf;
|
|
212 }
|
|
213 if (scalebuf) {
|
|
214 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf);
|
|
215 src[0] = scalebuf;
|
|
216 }
|
|
217 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]);
|
|
218 }
|
|
219
|
|
220 static uint32_t draw_slice(uint8_t *image[], int stride[],
|
|
221 int w, int h, int x, int y) {
|
|
222 uint8_t *src = yuvbuf;
|
|
223
|
|
224 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]);
|
|
225 if (scalebuf) {
|
|
226 gl_scalebox(w, h, yuvbuf,(int) (w * scaling), (int) (h * scaling), scalebuf);
|
|
227 src = scalebuf;
|
|
228 }
|
|
229 gl_putbox(x + x_pos, y + y_pos, (int) (w * scaling), (int) (h * scaling), src);
|
|
230 }
|
|
231
|
|
232
|
|
233 static void flip_page(void) {
|
292
|
234 if (y_pos) {
|
|
235 gl_fillbox(0, 0, WIDTH, y_pos, 0);
|
|
236 gl_fillbox(0, HEIGHT - y_pos, WIDTH, y_pos, 0);
|
|
237 } else {
|
|
238 gl_fillbox(0, 0, x_pos, HEIGHT, 0);
|
|
239 gl_fillbox(WIDTH - x_pos, 0, x_pos, HEIGHT, 0);
|
327
|
240 }
|
285
|
241 vo_draw_text(WIDTH, HEIGHT, draw_alpha);
|
|
242 gl_copyscreen(screen);
|
|
243 }
|
|
244
|
|
245 static void check_events(void) {
|
|
246 }
|
|
247
|
|
248 static void uninit(void) {
|
|
249 gl_freecontext(screen);
|
|
250 gl_freecontext(virt);
|
|
251 vga_setmode(TEXT);
|
|
252 if (scalebuf)
|
|
253 free(scalebuf);
|
|
254 if (yuvbuf)
|
|
255 free(yuvbuf);
|
|
256 }
|
|
257 |