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;
|
|
57
|
|
58 static uint32_t pformat;
|
|
59
|
|
60 static uint8_t checked = 0;
|
|
61
|
286
|
62 static void checksupportedmodes() {
|
285
|
63 int i;
|
|
64
|
|
65 checked = 1;
|
|
66 vga_init();
|
|
67 vga_disabledriverreport();
|
|
68 for (i = 0; i < VID_MODE_NUM; i++) {
|
290
|
69 if (vga_hasmode(vid_mode_nums[i]) > 0)
|
285
|
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) {
|
292
|
78 static uint8_t bpp;
|
|
79
|
285
|
80 if (!checked) {
|
|
81 checksupportedmodes(); // Looking for available video modes
|
|
82 }
|
|
83 pformat = format;
|
292
|
84 if (format == IMGFMT_YV12) bpp = 32;
|
|
85 else bpp = format & 255;
|
285
|
86 if (d_width > 800)
|
|
87 switch (bpp) {
|
|
88 case 32: vid_mode = 36; break;
|
|
89 case 24: vid_mode = 25; break;
|
|
90 case 16: vid_mode = 24; break;
|
|
91 case 15: vid_mode = 23; break;
|
|
92 }
|
|
93 else
|
|
94 if (d_width > 640)
|
|
95 switch (bpp) {
|
|
96 case 32: vid_mode = 35; break;
|
|
97 case 24: vid_mode = 22; break;
|
|
98 case 16: vid_mode = 21; break;
|
|
99 case 15: vid_mode = 20; break;
|
|
100 }
|
|
101 else
|
|
102 switch (bpp) {
|
|
103 case 32: vid_mode = 34; break;
|
|
104 case 24: vid_mode = 19; break;
|
|
105 case 16: vid_mode = 18; break;
|
|
106 case 15: vid_mode = 17; break;
|
|
107 }
|
286
|
108 if (vga_setmode(vid_mode) == -1){
|
|
109 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
|
285
|
110 return(1); // error
|
286
|
111 }
|
|
112 if (gl_setcontextvga(vid_mode)){
|
|
113 printf("vo_svga: gl_setcontextvga(%d) failed.\n",vid_mode);
|
285
|
114 return(1); // error
|
286
|
115 }
|
285
|
116 screen = gl_allocatecontext();
|
|
117 gl_getcontext(screen);
|
286
|
118 if (gl_setcontextvgavirtual(vid_mode)){
|
|
119 printf("vo_svga: gl_setcontextvgavirtual(%d) failed.\n",vid_mode);
|
285
|
120 return(1); // error
|
286
|
121 }
|
285
|
122 virt = gl_allocatecontext();
|
|
123 gl_getcontext(virt);
|
|
124 gl_setcontext(virt);
|
|
125 gl_clearscreen(0);
|
|
126
|
|
127 orig_w = width;
|
|
128 orig_h = height;
|
|
129 if (fullscreen && (WIDTH != orig_w)) {
|
292
|
130 if (((orig_w*1.0) / orig_h) < (4.0/3)) {
|
|
131 maxh = HEIGHT;
|
|
132 scaling = maxh / (orig_h * 1.0);
|
|
133 maxw = (uint32_t) (orig_w * scaling);
|
|
134 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
135 } else {
|
|
136 maxw = WIDTH;
|
|
137 scaling = maxw / (orig_w * 1.0);
|
|
138 maxh = (uint32_t) (orig_h * scaling);
|
|
139 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
140 }
|
285
|
141 } else {
|
|
142 maxw = orig_w;
|
|
143 maxh = orig_h;
|
|
144 }
|
|
145
|
|
146 x_pos = (WIDTH - maxw) / 2;
|
|
147 y_pos = (HEIGHT - maxh) / 2;
|
|
148
|
|
149 if (pformat == IMGFMT_YV12) {
|
|
150 yuv2rgb_init(bpp, MODE_RGB);
|
|
151 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
152 }
|
|
153
|
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) {
|
|
192 int x, y, i;
|
|
193 uint8_t *dest, buf;
|
|
194
|
|
195 // if (pformat == IMGFMT_YV12) {
|
|
196 for (y = 0; y < h; y++) {
|
|
197 dest = virt->vbuf + ((WIDTH * (y0 + y) + x0) * BYTESPERPIXEL);
|
|
198 for (x = 0; x < w; x++) {
|
|
199 if (srca[x]) {
|
|
200 for (i = 0; i < BYTESPERPIXEL; i++)
|
|
201 dest[i] = /*((dest[i] * srca[x]) >> 8) +*/ src[x] >> 6;
|
|
202 }
|
|
203 dest += BYTESPERPIXEL;
|
|
204 }
|
|
205 src += stride;
|
|
206 srca += stride;
|
|
207 }
|
|
208 // }
|
|
209 }
|
|
210
|
|
211 static uint32_t draw_frame(uint8_t *src[]) {
|
|
212 if (pformat == IMGFMT_YV12) {
|
|
213 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2);
|
|
214 src[0] = yuvbuf;
|
|
215 }
|
|
216 if (scalebuf) {
|
|
217 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf);
|
|
218 src[0] = scalebuf;
|
|
219 }
|
|
220 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]);
|
|
221 }
|
|
222
|
|
223 static uint32_t draw_slice(uint8_t *image[], int stride[],
|
|
224 int w, int h, int x, int y) {
|
|
225 uint8_t *src = yuvbuf;
|
|
226
|
|
227 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]);
|
|
228 if (scalebuf) {
|
|
229 gl_scalebox(w, h, yuvbuf,(int) (w * scaling), (int) (h * scaling), scalebuf);
|
|
230 src = scalebuf;
|
|
231 }
|
|
232 gl_putbox(x + x_pos, y + y_pos, (int) (w * scaling), (int) (h * scaling), src);
|
|
233 }
|
|
234
|
|
235
|
|
236 static void flip_page(void) {
|
292
|
237 if (y_pos) {
|
|
238 gl_fillbox(0, 0, WIDTH, y_pos, 0);
|
|
239 gl_fillbox(0, HEIGHT - y_pos, WIDTH, y_pos, 0);
|
|
240 } else {
|
|
241 gl_fillbox(0, 0, x_pos, HEIGHT, 0);
|
|
242 gl_fillbox(WIDTH - x_pos, 0, x_pos, HEIGHT, 0);
|
|
243 }
|
285
|
244 vo_draw_text(WIDTH, HEIGHT, draw_alpha);
|
|
245 gl_copyscreen(screen);
|
|
246 }
|
|
247
|
|
248 static void check_events(void) {
|
|
249 }
|
|
250
|
|
251 static void uninit(void) {
|
|
252 gl_freecontext(screen);
|
|
253 gl_freecontext(virt);
|
|
254 vga_setmode(TEXT);
|
|
255 if (scalebuf)
|
|
256 free(scalebuf);
|
|
257 if (yuvbuf)
|
|
258 free(yuvbuf);
|
|
259 }
|
|
260 |