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
|
76
|
167 config.version = MGA_VID_VERSION;
|
1
|
168 config.src_width = SRC_IMAGE_WIDTH;
|
|
169 config.src_height= SRC_IMAGE_HEIGHT;
|
|
170 config.dest_width = SRC_IMAGE_WIDTH;
|
|
171 config.dest_height = SRC_IMAGE_HEIGHT;
|
|
172 config.x_org= 10;
|
|
173 config.y_org= 10;
|
|
174 config.colkey_on = 0;
|
|
175 config.format = MGA_VID_FORMAT_YV12;
|
76
|
176 config.frame_size=SRC_IMAGE_WIDTH*SRC_IMAGE_HEIGHT*2;
|
|
177 config.num_frames=1;
|
1
|
178
|
|
179 if (ioctl(f,MGA_VID_CONFIG,&config))
|
|
180 {
|
|
181 perror("Error in config ioctl");
|
|
182 }
|
|
183
|
|
184 if (config.card_type == MGA_G200)
|
|
185 {
|
|
186 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config.ram_size);
|
|
187 is_g400 = 0;
|
|
188 }
|
|
189 else
|
|
190 {
|
|
191 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
|
|
192 is_g400 = 1;
|
|
193 }
|
|
194
|
|
195 ioctl(f,MGA_VID_ON,0);
|
|
196 mga_vid_base = (uint8_t*)mmap(0,256 * 4096,PROT_WRITE,MAP_SHARED,f,0);
|
|
197 printf("mga_vid_base = %8p\n",mga_vid_base);
|
|
198
|
|
199
|
|
200 //memset(y_image,80,256 * 128);
|
|
201 //memset(cr_image,80,256/2 * 20);
|
|
202 //memset(cb_image,80,256/2 * 20);
|
|
203 write_frame(y_image,cr_image,cb_image);
|
|
204 printf("(1) There should be a green square, offset by 10 pixels from\n"
|
|
205 " the upper left corner displayed\n");
|
|
206 sleep(3);
|
|
207
|
|
208
|
|
209 draw_cool_pattern();
|
|
210 write_frame(y_image,cr_image,cb_image);
|
|
211 printf("(2) There should be a cool mosaic like pattern now.\n");
|
|
212 sleep(3);
|
|
213
|
|
214 draw_color_blend();
|
|
215 write_frame(y_image,cr_image,cb_image);
|
|
216 printf("(3) There should be a color blend with black, red, purple, blue\n"
|
|
217 " corners (starting top left going CW)\n");
|
|
218 sleep(3);
|
|
219
|
|
220 ioctl(f,MGA_VID_OFF,0);
|
|
221
|
|
222 close(f);
|
|
223 return 0;
|
|
224 }
|