5 * Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
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.
15 #include <sys/ioctl.h>
23 mga_vid_config_t config
;
24 uint8_t *mga_vid_base
;
27 #define SRC_IMAGE_WIDTH 256
28 #define SRC_IMAGE_HEIGHT 256
30 uint8_t y_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
31 uint8_t cr_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
32 uint8_t cb_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
36 write_frame_g200(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
39 uint32_t bespitch
,h
,w
;
42 bespitch
= (config
.src_width
+ 31) & ~31;
44 for(h
=0; h
< config
.src_height
; h
++)
46 memcpy(dest
, y
, config
.src_width
);
47 y
+= config
.src_width
;
51 for(h
=0; h
< config
.src_height
/2; h
++)
53 for(w
=0; w
< config
.src_width
/2; w
++)
58 dest
+= bespitch
- config
.src_width
;
63 write_frame_g400(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
69 bespitch
= (config
.src_width
+ 31) & ~31;
71 for(h
=0; h
< config
.src_height
; h
++)
73 memcpy(dest
, y
, config
.src_width
);
74 y
+= config
.src_width
;
78 for(h
=0; h
< config
.src_height
/2; h
++)
80 memcpy(dest
, cb
, config
.src_width
/2);
81 cb
+= config
.src_width
/2;
85 for(h
=0; h
< config
.src_height
/2; h
++)
87 memcpy(dest
, cr
, config
.src_width
/2);
88 cr
+= config
.src_width
/2;
93 void write_frame(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
96 write_frame_g400(y
,cr
,cb
);
98 write_frame_g200(y
,cr
,cb
);
102 draw_cool_pattern(void)
107 for (y
=0; y
<config
.src_height
; y
++) {
108 for (x
=0; x
<config
.src_width
; x
++) {
109 y_image
[i
++] = x
*x
/2 + y
*y
/2 - 128;
114 for (y
=0; y
<config
.src_height
/2; y
++)
115 for (x
=0; x
<config
.src_width
/2; x
++)
117 cr_image
[i
++] = x
- 128;
121 for (y
=0; y
<config
.src_height
/2; y
++)
122 for (x
=0; x
<config
.src_width
/2; x
++)
124 cb_image
[i
++] = y
- 128;
129 draw_color_blend(void)
134 for (y
=0; y
<config
.src_height
; y
++) {
135 for (x
=0; x
<config
.src_width
; x
++) {
141 for (y
=0; y
<config
.src_height
/2; y
++)
142 for (x
=0; x
<config
.src_width
/2; x
++)
144 cr_image
[i
++] = x
- 128;
148 for (y
=0; y
<config
.src_height
/2; y
++)
149 for (x
=0; x
<config
.src_width
/2; x
++)
151 cb_image
[i
++] = y
- 128;
157 main(int argc
, char *argv
[])
161 f
= open("/dev/mga_vid",O_RDWR
);
165 fprintf(stderr
,"Couldn't open driver\n");
169 config
.version
= MGA_VID_VERSION
;
170 config
.src_width
= SRC_IMAGE_WIDTH
;
171 config
.src_height
= SRC_IMAGE_HEIGHT
;
172 config
.dest_width
= SRC_IMAGE_WIDTH
;
173 config
.dest_height
= SRC_IMAGE_HEIGHT
;
176 config
.colkey_on
= 0;
177 config
.format
= MGA_VID_FORMAT_YV12
;
178 config
.frame_size
=SRC_IMAGE_WIDTH
*SRC_IMAGE_HEIGHT
*2;
181 if (ioctl(f
,MGA_VID_CONFIG
,&config
))
183 perror("Error in config ioctl");
186 if (config
.card_type
== MGA_G200
)
188 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config
.ram_size
);
193 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config
.ram_size
);
197 ioctl(f
,MGA_VID_ON
,0);
198 mga_vid_base
= (uint8_t*)mmap(0,256 * 4096,PROT_WRITE
,MAP_SHARED
,f
,0);
199 printf("mga_vid_base = %8p\n",mga_vid_base
);
202 //memset(y_image,80,256 * 128);
203 //memset(cr_image,80,256/2 * 20);
204 //memset(cb_image,80,256/2 * 20);
205 write_frame(y_image
,cr_image
,cb_image
);
206 printf("(1) There should be a green square, offset by 10 pixels from\n"
207 " the upper left corner displayed\n");
212 write_frame(y_image
,cr_image
,cb_image
);
213 printf("(2) There should be a cool mosaic like pattern now.\n");
217 write_frame(y_image
,cr_image
,cb_image
);
218 printf("(3) There should be a color blend with black, red, purple, blue\n"
219 " corners (starting top left going CW)\n");
222 ioctl(f
,MGA_VID_OFF
,0);