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