1
|
1 /*
|
|
2 *
|
|
3 * mga_vid_test.c
|
|
4 *
|
|
5 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
|
|
6 * Sept 1999
|
|
7 *
|
|
8 * This software has been released under the terms of the GNU Public
|
|
9 * license. See http://www.gnu.org/copyleft/gpl.html for details.
|
|
10 */
|
|
11
|
|
12 //#include <stddef.h>
|
|
13 #include <stdio.h>
|
|
14 #include <stdlib.h>
|
|
15 #include <sys/ioctl.h>
|
|
16 #include <unistd.h>
|
|
17 #include <fcntl.h>
|
|
18 #include <sys/mman.h>
|
|
19 #include "mga_vid.h"
|
|
20
|
|
21 mga_vid_config_t config;
|
|
22 uint8_t *mga_vid_base;
|
|
23 uint32_t is_g400;
|
|
24
|
|
25 #define SRC_IMAGE_WIDTH 256
|
|
26 #define SRC_IMAGE_HEIGHT 256
|
|
27
|
|
28 uint8_t y_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
|
|
29 uint8_t cr_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
|
|
30 uint8_t cb_image[SRC_IMAGE_WIDTH * SRC_IMAGE_HEIGHT];
|
|
31
|
|
32
|
|
33 void
|
|
34 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
|
35 {
|
|
36 uint8_t *dest;
|
|
37 uint32_t bespitch,h,w;
|
|
38
|
|
39 dest = mga_vid_base;
|
|
40 bespitch = (config.src_width + 31) & ~31;
|
|
41
|
|
42 for(h=0; h < config.src_height; h++)
|
|
43 {
|
|
44 memcpy(dest, y, config.src_width);
|
|
45 y += config.src_width;
|
|
46 dest += bespitch;
|
|
47 }
|
|
48
|
|
49 for(h=0; h < config.src_height/2; h++)
|
|
50 {
|
|
51 for(w=0; w < config.src_width/2; w++)
|
|
52 {
|
|
53 *dest++ = *cb++;
|
|
54 *dest++ = *cr++;
|
|
55 }
|
|
56 dest += bespitch - config.src_width;
|
|
57 }
|
|
58 }
|
|
59
|
|
60 void
|
|
61 write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
|
62 {
|
|
63 uint8_t *dest;
|
|
64 uint32_t bespitch,h;
|
|
65
|
|
66 dest = mga_vid_base;
|
|
67 bespitch = (config.src_width + 31) & ~31;
|
|
68
|
|
69 for(h=0; h < config.src_height; h++)
|
|
70 {
|
|
71 memcpy(dest, y, config.src_width);
|
|
72 y += config.src_width;
|
|
73 dest += bespitch;
|
|
74 }
|
|
75
|
|
76 for(h=0; h < config.src_height/2; h++)
|
|
77 {
|
|
78 memcpy(dest, cb, config.src_width/2);
|
|
79 cb += config.src_width/2;
|
|
80 dest += bespitch/2;
|
|
81 }
|
|
82
|
|
83 for(h=0; h < config.src_height/2; h++)
|
|
84 {
|
|
85 memcpy(dest, cr, config.src_width/2);
|
|
86 cr += config.src_width/2;
|
|
87 dest += bespitch/2;
|
|
88 }
|
|
89 }
|
|
90
|
|
91 void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb)
|
|
92 {
|
|
93 if(is_g400)
|
|
94 write_frame_g400(y,cr,cb);
|
|
95 else
|
|
96 write_frame_g200(y,cr,cb);
|
|
97 }
|
|
98
|
|
99 void
|
|
100 draw_cool_pattern(void)
|
|
101 {
|
|
102 int i,x,y;
|
|
103
|
|
104 i = 0;
|
|
105 for (y=0; y<config.src_height; y++) {
|
|
106 for (x=0; x<config.src_width; x++) {
|
|
107 y_image[i++] = x*x/2 + y*y/2 - 128;
|
|
108 }
|
|
109 }
|
|
110
|
|
111 i = 0;
|
|
112 for (y=0; y<config.src_height/2; y++)
|
|
113 for (x=0; x<config.src_width/2; x++)
|
|
114 {
|
|
115 cr_image[i++] = x - 128;
|
|
116 }
|
|
117
|
|
118 i = 0;
|
|
119 for (y=0; y<config.src_height/2; y++)
|
|
120 for (x=0; x<config.src_width/2; x++)
|
|
121 {
|
|
122 cb_image[i++] = y - 128;
|
|
123 }
|
|
124 }
|
|
125
|
|
126 void
|
|
127 draw_color_blend(void)
|
|
128 {
|
|
129 int i,x,y;
|
|
130
|
|
131 i = 0;
|
|
132 for (y=0; y<config.src_height; y++) {
|
|
133 for (x=0; x<config.src_width; x++) {
|
|
134 y_image[i++] = 0;
|
|
135 }
|
|
136 }
|
|
137
|
|
138 i = 0;
|
|
139 for (y=0; y<config.src_height/2; y++)
|
|
140 for (x=0; x<config.src_width/2; x++)
|
|
141 {
|
|
142 cr_image[i++] = x - 128;
|
|
143 }
|
|
144
|
|
145 i = 0;
|
|
146 for (y=0; y<config.src_height/2; y++)
|
|
147 for (x=0; x<config.src_width/2; x++)
|
|
148 {
|
|
149 cb_image[i++] = y - 128;
|
|
150 }
|
|
151 }
|
|
152
|
|
153
|
|
154 int
|
|
155 main(int argc, char *argv[])
|
|
156 {
|
|
157 int f;
|
|
158
|
|
159 f = open("/dev/mga_vid",O_RDWR);
|
|
160
|
|
161 if(f == -1)
|
|
162 {
|
|
163 fprintf(stderr,"Couldn't open driver\n");
|
|
164 exit(1);
|
|
165 }
|
|
166
|
|
167 config.src_width = SRC_IMAGE_WIDTH;
|
|
168 config.src_height= SRC_IMAGE_HEIGHT;
|
|
169 config.dest_width = SRC_IMAGE_WIDTH;
|
|
170 config.dest_height = SRC_IMAGE_HEIGHT;
|
|
171 config.x_org= 10;
|
|
172 config.y_org= 10;
|
|
173 config.colkey_on = 0;
|
|
174 config.format = MGA_VID_FORMAT_YV12;
|
|
175
|
|
176 if (ioctl(f,MGA_VID_CONFIG,&config))
|
|
177 {
|
|
178 perror("Error in config ioctl");
|
|
179 }
|
|
180
|
|
181 if (config.card_type == MGA_G200)
|
|
182 {
|
|
183 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config.ram_size);
|
|
184 is_g400 = 0;
|
|
185 }
|
|
186 else
|
|
187 {
|
|
188 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
|
|
189 is_g400 = 1;
|
|
190 }
|
|
191
|
|
192 ioctl(f,MGA_VID_ON,0);
|
|
193 mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);
|
|
194 printf("mga_vid_base = %8p\n",mga_vid_base);
|
|
195
|
|
196
|
|
197 //memset(y_image,80,256 * 128);
|
|
198 //memset(cr_image,80,256/2 * 20);
|
|
199 //memset(cb_image,80,256/2 * 20);
|
|
200 write_frame(y_image,cr_image,cb_image);
|
|
201 printf("(1) There should be a green square, offset by 10 pixels from\n"
|
|
202 " the upper left corner displayed\n");
|
|
203 sleep(3);
|
|
204
|
|
205
|
|
206 draw_cool_pattern();
|
|
207 write_frame(y_image,cr_image,cb_image);
|
|
208 printf("(2) There should be a cool mosaic like pattern now.\n");
|
|
209 sleep(3);
|
|
210
|
|
211 draw_color_blend();
|
|
212 write_frame(y_image,cr_image,cb_image);
|
|
213 printf("(3) There should be a color blend with black, red, purple, blue\n"
|
|
214 " corners (starting top left going CW)\n");
|
|
215 sleep(3);
|
|
216
|
|
217 ioctl(f,MGA_VID_OFF,0);
|
|
218
|
|
219 close(f);
|
|
220 return 0;
|
|
221 }
|