2 * Copyright (C) 1999 Aaron Holtzman <aholtzma@ess.engr.uvic.ca>
4 * This file is part of mga_vid.
6 * mga_vid is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * mga_vid is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with mga_vid; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 #include <sys/ioctl.h>
32 mga_vid_config_t config
;
33 uint8_t *mga_vid_base
;
36 #define SRC_IMAGE_WIDTH 256
37 #define SRC_IMAGE_HEIGHT 256
39 uint8_t y_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
40 uint8_t cr_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
41 uint8_t cb_image
[SRC_IMAGE_WIDTH
* SRC_IMAGE_HEIGHT
];
45 write_frame_g200(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
48 uint32_t bespitch
,h
,w
;
51 bespitch
= (config
.src_width
+ 31) & ~31;
53 for(h
=0; h
< config
.src_height
; h
++)
55 memcpy(dest
, y
, config
.src_width
);
56 y
+= config
.src_width
;
60 for(h
=0; h
< config
.src_height
/2; h
++)
62 for(w
=0; w
< config
.src_width
/2; w
++)
67 dest
+= bespitch
- config
.src_width
;
72 write_frame_g400(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
78 bespitch
= (config
.src_width
+ 31) & ~31;
80 for(h
=0; h
< config
.src_height
; h
++)
82 memcpy(dest
, y
, config
.src_width
);
83 y
+= config
.src_width
;
87 for(h
=0; h
< config
.src_height
/2; h
++)
89 memcpy(dest
, cb
, config
.src_width
/2);
90 cb
+= config
.src_width
/2;
94 for(h
=0; h
< config
.src_height
/2; h
++)
96 memcpy(dest
, cr
, config
.src_width
/2);
97 cr
+= config
.src_width
/2;
102 void write_frame(uint8_t *y
,uint8_t *cr
, uint8_t *cb
)
105 write_frame_g400(y
,cr
,cb
);
107 write_frame_g200(y
,cr
,cb
);
111 draw_cool_pattern(void)
116 for (y
=0; y
<config
.src_height
; y
++) {
117 for (x
=0; x
<config
.src_width
; x
++) {
118 y_image
[i
++] = x
*x
/2 + y
*y
/2 - 128;
123 for (y
=0; y
<config
.src_height
/2; y
++)
124 for (x
=0; x
<config
.src_width
/2; x
++)
126 cr_image
[i
++] = x
- 128;
130 for (y
=0; y
<config
.src_height
/2; y
++)
131 for (x
=0; x
<config
.src_width
/2; x
++)
133 cb_image
[i
++] = y
- 128;
138 draw_color_blend(void)
143 for (y
=0; y
<config
.src_height
; y
++) {
144 for (x
=0; x
<config
.src_width
; x
++) {
150 for (y
=0; y
<config
.src_height
/2; y
++)
151 for (x
=0; x
<config
.src_width
/2; x
++)
153 cr_image
[i
++] = x
- 128;
157 for (y
=0; y
<config
.src_height
/2; y
++)
158 for (x
=0; x
<config
.src_width
/2; x
++)
160 cb_image
[i
++] = y
- 128;
170 f
= open("/dev/mga_vid",O_RDWR
);
174 fprintf(stderr
,"Couldn't open driver\n");
178 config
.version
= MGA_VID_VERSION
;
179 config
.src_width
= SRC_IMAGE_WIDTH
;
180 config
.src_height
= SRC_IMAGE_HEIGHT
;
181 config
.dest_width
= SRC_IMAGE_WIDTH
;
182 config
.dest_height
= SRC_IMAGE_HEIGHT
;
185 config
.colkey_on
= 0;
186 config
.format
= MGA_VID_FORMAT_YV12
;
187 config
.frame_size
=SRC_IMAGE_WIDTH
*SRC_IMAGE_HEIGHT
*2;
190 if (ioctl(f
,MGA_VID_CONFIG
,&config
))
192 perror("Error in config ioctl");
195 if (config
.card_type
== MGA_G200
)
197 printf("Testing MGA G200 Backend Scaler with %d MB of RAM\n", config
.ram_size
);
202 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config
.ram_size
);
206 ioctl(f
,MGA_VID_ON
,0);
207 mga_vid_base
= (uint8_t*)mmap(0,256 * 4096,PROT_WRITE
,MAP_SHARED
,f
,0);
208 printf("mga_vid_base = %8p\n",mga_vid_base
);
211 //memset(y_image,80,256 * 128);
212 //memset(cr_image,80,256/2 * 20);
213 //memset(cb_image,80,256/2 * 20);
214 write_frame(y_image
,cr_image
,cb_image
);
215 printf("(1) There should be a green square, offset by 10 pixels from\n"
216 " the upper left corner displayed\n");
221 write_frame(y_image
,cr_image
,cb_image
);
222 printf("(2) There should be a cool mosaic like pattern now.\n");
226 write_frame(y_image
,cr_image
,cb_image
);
227 printf("(3) There should be a color blend with black, red, purple, blue\n"
228 " corners (starting top left going CW)\n");
231 ioctl(f
,MGA_VID_OFF
,0);