comparison libvo/vo_svga.c @ 407:0a5b131f1f11

24/15bpp -> 32/16bpp added.
author se7encode
date Sat, 14 Apr 2001 17:51:37 +0000
parents 43acef8f7c74
children 53203545daa7
comparison
equal deleted inserted replaced
406:b353ad229e3f 407:0a5b131f1f11
1 /* 1 /*
2 Video driver for SVGAlib - alpha, slow 2 Video driver for SVGAlib - alpha, slow
3 by Zoltan Mark Vician <se7en@sch.bme.hu> 3 by Zoltan Mark Vician <se7en@sch.bme.hu>
4 Code started: Mon Apr 1 23:25:47 2001 4 Code started: Mon Apr 1 23:25:47 2001
5
6 Uses HW acceleration if your card is supported by SVGAlib.
5 */ 7 */
6 8
7 #include <stdio.h> 9 #include <stdio.h>
8 #include <stdlib.h> 10 #include <stdlib.h>
9 11
14 #include "video_out.h" 16 #include "video_out.h"
15 #include "video_out_internal.h" 17 #include "video_out_internal.h"
16 18
17 #include "yuv2rgb.h" 19 #include "yuv2rgb.h"
18 #include "mmx.h" 20 #include "mmx.h"
21
22 extern void rgb15to16_mmx(char* s0,char* d0,int count);
19 23
20 LIBVO_EXTERN(svga) 24 LIBVO_EXTERN(svga)
21 25
22 static vo_info_t vo_info = { 26 static vo_info_t vo_info = {
23 "SVGAlib", 27 "SVGAlib",
29 // SVGAlib definitions 33 // SVGAlib definitions
30 34
31 GraphicsContext *screen; 35 GraphicsContext *screen;
32 GraphicsContext *virt; 36 GraphicsContext *virt;
33 37
34 static uint8_t *scalebuf = NULL, *yuvbuf = NULL; 38 static uint8_t *scalebuf = NULL, *yuvbuf = NULL, *bppbuf = NULL;
35 39
36 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height 40 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height
37 static float scaling = 1.0; 41 static float scaling = 1.0;
38 static uint32_t x_pos, y_pos; // Position 42 static uint32_t x_pos, y_pos; // Position
39 43
58 static uint8_t bpp; 62 static uint8_t bpp;
59 63
60 static uint32_t pformat; 64 static uint32_t pformat;
61 65
62 static uint8_t checked = 0; 66 static uint8_t checked = 0;
67 static uint8_t bpp_conv = 0;
63 68
64 static void checksupportedmodes() { 69 static void checksupportedmodes() {
65 int i; 70 int i;
66 71
67 checked = 1; 72 checked = 1;
80 uint32_t wid = (d_width > 0 ? d_width : width); 85 uint32_t wid = (d_width > 0 ? d_width : width);
81 86
82 if (!checked) { 87 if (!checked) {
83 checksupportedmodes(); // Looking for available video modes 88 checksupportedmodes(); // Looking for available video modes
84 } 89 }
90
85 pformat = format; 91 pformat = format;
86 if (format == IMGFMT_YV12) bpp = 32; 92 if (format == IMGFMT_YV12) bpp = 32;
87 else bpp = format & 255; 93 else bpp = format & 255;
88 if (wid > 800) 94 if (wid > 800)
89 switch (bpp) { 95 switch (bpp) {
90 case 32: vid_mode = 36; break; 96 case 32: vid_mode = 36; break;
91 case 24: vid_mode = 25; break; 97 case 24: vid_mode = bpp_conv ? 36 : 25; bpp = 32; break;
92 case 16: vid_mode = 24; break; 98 case 16: vid_mode = 24; break;
93 case 15: vid_mode = 23; break; 99 case 15: vid_mode = bpp_conv ? 24 : 23; bpp = 16; break;
94 } 100 }
95 else 101 else
96 if (wid > 640) 102 if (wid > 640)
97 switch (bpp) { 103 switch (bpp) {
98 case 32: vid_mode = 35; break; 104 case 32: vid_mode = 35; break;
99 case 24: vid_mode = 22; break; 105 case 24: vid_mode = bpp_conv ? 35 : 22; bpp = 32; break;
100 case 16: vid_mode = 21; break; 106 case 16: vid_mode = 21; break;
101 case 15: vid_mode = 20; break; 107 case 15: vid_mode = bpp_conv ? 21 : 20; bpp = 16; break;
102 } 108 }
103 else 109 else
104 switch (bpp) { 110 switch (bpp) {
105 case 32: vid_mode = 34; break; 111 case 32: vid_mode = 34; break;
106 case 24: vid_mode = 19; break; 112 case 24: vid_mode = bpp_conv ? 34 : 19; bpp = 32; break;
107 case 16: vid_mode = 18; break; 113 case 16: vid_mode = 18; break;
108 case 15: vid_mode = 17; break; 114 case 15: vid_mode = bpp_conv ? 18 : 17; bpp = 16; break;
109 } 115 }
116 if (bpp_conv)
117 bppbuf = malloc(maxw * maxh * BYTESPERPIXEL);
118 if (!bppbuf) {
119 printf("vo_svga: Not enough memory for buffering!");
120 uninit();
121 return (1);
122 }
123
124 vga_setlinearaddressing();
110 if (vga_setmode(vid_mode) == -1){ 125 if (vga_setmode(vid_mode) == -1){
111 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode); 126 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
112 return(1); // error 127 return(1); // error
113 } 128 }
114 if (gl_setcontextvga(vid_mode)){ 129 if (gl_setcontextvga(vid_mode)){
132 if (((orig_w*1.0) / orig_h) < (4.0/3)) { 147 if (((orig_w*1.0) / orig_h) < (4.0/3)) {
133 maxh = HEIGHT; 148 maxh = HEIGHT;
134 scaling = maxh / (orig_h * 1.0); 149 scaling = maxh / (orig_h * 1.0);
135 maxw = (uint32_t) (orig_w * scaling); 150 maxw = (uint32_t) (orig_w * scaling);
136 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL); 151 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
152 if (!scalebuf) {
153 printf("vo_svga: Not enough memory for buffering!");
154 uninit();
155 return (1);
156 }
137 } else { 157 } else {
138 maxw = WIDTH; 158 maxw = WIDTH;
139 scaling = maxw / (orig_w * 1.0); 159 scaling = maxw / (orig_w * 1.0);
140 maxh = (uint32_t) (orig_h * scaling); 160 maxh = (uint32_t) (orig_h * scaling);
141 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL); 161 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
162 if (!scalebuf) {
163 printf("vo_svga: Not enough memory for buffering!");
164 uninit();
165 return (1);
166 }
142 } 167 }
143 } else { 168 } else {
144 maxw = orig_w; 169 maxw = orig_w;
145 maxh = orig_h; 170 maxh = orig_h;
146 } 171 }
147
148 x_pos = (WIDTH - maxw) / 2; 172 x_pos = (WIDTH - maxw) / 2;
149 y_pos = (HEIGHT - maxh) / 2; 173 y_pos = (HEIGHT - maxh) / 2;
150 174
151 if (pformat == IMGFMT_YV12) { 175 if (pformat == IMGFMT_YV12) {
152 yuv2rgb_init(bpp, MODE_RGB); 176 yuv2rgb_init(bpp, MODE_RGB);
153 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL); 177 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL);
178 if (!yuvbuf) {
179 printf("vo_svga: Not enough memory for buffering!");
180 uninit();
181 return (1);
182 }
154 } 183 }
155 184
156 printf("SVGAlib resolution: %dx%d %dbpp - ", WIDTH, HEIGHT, bpp); 185 printf("SVGAlib resolution: %dx%d %dbpp - ", WIDTH, HEIGHT, bpp);
157 if (maxw != orig_w || maxh != orig_h) printf("Video scaled to: %dx%d\n",maxw,maxh); 186 if (maxw != orig_w || maxh != orig_h) printf("Video scaled to: %dx%d\n",maxw,maxh);
158 else printf("No video scaling\n"); 187 else printf("No video scaling\n");
159 188
160 return (0); 189 return (0);
161 } 190 }
162 191
163 static uint32_t query_format(uint32_t format) { 192 static uint32_t query_format(uint32_t format) {
164 if (!checked) 193 uint8_t res = 0;
165 checksupportedmodes(); // Looking for available video modes 194
166 switch (format) { 195 if (!checked)
167 case IMGFMT_RGB32: 196 checksupportedmodes(); // Looking for available video modes
168 case IMGFMT_BGR|32: { 197 switch (format) {
169 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]); 198 case IMGFMT_RGB32:
170 } 199 case IMGFMT_BGR|32: {
171 case IMGFMT_RGB24: 200 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]);
172 case IMGFMT_BGR|24: { 201 }
173 return (vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M]); 202 case IMGFMT_RGB24:
174 } 203 case IMGFMT_BGR|24: {
175 case IMGFMT_RGB16: 204 res = vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M];
176 case IMGFMT_BGR|16: { 205 if (!res) {
177 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]); 206 res = vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32];
178 } 207 bpp_conv = 1;
179 case IMGFMT_RGB15: 208 }
180 case IMGFMT_BGR|15: { 209 return (res);
181 return (vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K]); 210 }
182 } 211 case IMGFMT_RGB16:
183 case IMGFMT_YV12: return (1); 212 case IMGFMT_BGR|16: {
184 } 213 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]);
214 }
215 case IMGFMT_RGB15:
216 case IMGFMT_BGR|15: {
217 res = vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K];
218 if (!res) {
219 res = vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K];
220 bpp_conv = 1;
221 }
222 return (res);
223 }
224 case IMGFMT_YV12: return (1);
225 }
185 return (0); 226 return (0);
186 } 227 }
187 228
188 static const vo_info_t* get_info(void) { 229 static const vo_info_t* get_info(void) {
189 return (&vo_info); 230 return (&vo_info);
214 } 255 }
215 if (scalebuf) { 256 if (scalebuf) {
216 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf); 257 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf);
217 src[0] = scalebuf; 258 src[0] = scalebuf;
218 } 259 }
260 if (bpp_conv) {
261 uint16_t *src = (uint16_t *) src[0];
262 uint16_t *dest = (uint16_t *) bppbuf;
263 uint16_t *end;
264
265 switch(bpp) {
266 case 32:
267 end = src + (maxw * maxh * 2);
268 while (src < end) {
269 *dest++ = *src++;
270 (uint8_t *)dest = (uint8_t *)src;
271 *(((uint8_t *)dest)+1) = 0;
272 dest++;
273 src++;
274 }
275 case 16:
276 #ifdef HAVE_MMX
277 rgb15to16_mmx(src[0],bppbuf,maxw * maxh * 2);
278 #else
279 register uint16_t srcdata;
280
281 end = src + (maxw * maxh);
282 while (src < end) {
283 srcdata = *src++;
284 *dest++ = (srcdata & 0x1f) | ((srcdata & 0x7fe0) << 1);
285 }
286 #endif
287 }
288 src[0] = bppbuf;
289 }
219 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]); 290 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]);
220 } 291 }
221 292
222 static uint32_t draw_slice(uint8_t *image[], int stride[], 293 static uint32_t draw_slice(uint8_t *image[], int stride[],
223 int w, int h, int x, int y) { 294 int w, int h, int x, int y) {
252 323
253 static void uninit(void) { 324 static void uninit(void) {
254 gl_freecontext(screen); 325 gl_freecontext(screen);
255 gl_freecontext(virt); 326 gl_freecontext(virt);
256 vga_setmode(TEXT); 327 vga_setmode(TEXT);
328 if (bppbuf)
329 free(bppbuf);
257 if (scalebuf) 330 if (scalebuf)
258 free(scalebuf); 331 free(scalebuf);
259 if (yuvbuf) 332 if (yuvbuf)
260 free(yuvbuf); 333 free(yuvbuf);
261 } 334 }