vo_tag: fix RGB with alpha output on little-endian
[mplayer/glamo.git] / drivers / mga_vid_test.c
blob8555905a46334c4852ca4c89156e13923d40f379
1 /*
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.
21 //#include <stddef.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <sys/ioctl.h>
25 #include <unistd.h>
26 #include <fcntl.h>
27 #include <sys/mman.h>
28 #include <inttypes.h>
29 #include <string.h>
30 #include "mga_vid.h"
32 mga_vid_config_t config;
33 uint8_t *mga_vid_base;
34 uint32_t is_g400;
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];
44 void
45 write_frame_g200(uint8_t *y,uint8_t *cr, uint8_t *cb)
47 uint8_t *dest;
48 uint32_t bespitch,h,w;
50 dest = mga_vid_base;
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;
57 dest += bespitch;
60 for(h=0; h < config.src_height/2; h++)
62 for(w=0; w < config.src_width/2; w++)
64 *dest++ = *cb++;
65 *dest++ = *cr++;
67 dest += bespitch - config.src_width;
71 void
72 write_frame_g400(uint8_t *y,uint8_t *cr, uint8_t *cb)
74 uint8_t *dest;
75 uint32_t bespitch,h;
77 dest = mga_vid_base;
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;
84 dest += bespitch;
87 for(h=0; h < config.src_height/2; h++)
89 memcpy(dest, cb, config.src_width/2);
90 cb += config.src_width/2;
91 dest += bespitch/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;
98 dest += bespitch/2;
102 void write_frame(uint8_t *y,uint8_t *cr, uint8_t *cb)
104 if(is_g400)
105 write_frame_g400(y,cr,cb);
106 else
107 write_frame_g200(y,cr,cb);
110 void
111 draw_cool_pattern(void)
113 int i,x,y;
115 i = 0;
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;
122 i = 0;
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;
129 i = 0;
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;
137 void
138 draw_color_blend(void)
140 int i,x,y;
142 i = 0;
143 for (y=0; y<config.src_height; y++) {
144 for (x=0; x<config.src_width; x++) {
145 y_image[i++] = 0;
149 i = 0;
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;
156 i = 0;
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;
166 main(void)
168 int f;
170 f = open("/dev/mga_vid",O_RDWR);
172 if(f == -1)
174 fprintf(stderr,"Couldn't open driver\n");
175 exit(1);
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;
183 config.x_org= 10;
184 config.y_org= 10;
185 config.colkey_on = 0;
186 config.format = MGA_VID_FORMAT_YV12;
187 config.frame_size=SRC_IMAGE_WIDTH*SRC_IMAGE_HEIGHT*2;
188 config.num_frames=1;
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);
198 is_g400 = 0;
200 else
202 printf("Testing MGA G400 Backend Scaler with %d MB of RAM\n", config.ram_size);
203 is_g400 = 1;
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");
217 sleep(3);
220 draw_cool_pattern();
221 write_frame(y_image,cr_image,cb_image);
222 printf("(2) There should be a cool mosaic like pattern now.\n");
223 sleep(3);
225 draw_color_blend();
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");
229 sleep(3);
231 ioctl(f,MGA_VID_OFF,0);
233 close(f);
234 return 0;