Configure needs AS to be set for the Makefiles.
[mplayer/glamo.git] / TOOLS / bmovl-test.c
blob45fa409dcebe115373f65b703883f0dc9b00e2cf
1 /* Small program to test the features of vf_bmovl */
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <string.h>
6 #include <stdlib.h>
7 #include <SDL/SDL.h>
8 #include <SDL/SDL_image.h>
10 #define DEBUG 0
12 static void
13 blit(int fifo, unsigned char *bitmap, int width, int height,
14 int xpos, int ypos, int alpha, int clear)
16 char str[100];
17 int nbytes;
19 sprintf(str, "RGBA32 %d %d %d %d %d %d\n",
20 width, height, xpos, ypos, alpha, clear);
22 if(DEBUG) printf("Sending %s", str);
24 write(fifo, str, strlen(str));
25 nbytes = write(fifo, bitmap, width*height*4);
27 if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes);
30 static void
31 set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) {
32 char str[100];
34 sprintf(str, "ALPHA %d %d %d %d %d\n",
35 width, height, xpos, ypos, alpha);
37 if(DEBUG) printf("Sending %s", str);
39 write(fifo, str, strlen(str));
42 static void
43 paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) {
45 int i;
47 for(i=0; i < size; i+=4) {
48 bitmap[i+0] = red;
49 bitmap[i+1] = green;
50 bitmap[i+2] = blue;
51 bitmap[i+3] = alpha;
55 int main(int argc, char **argv) {
57 int fifo=-1;
58 int width=0, height=0;
59 unsigned char *bitmap;
60 SDL_Surface *image;
61 int i;
63 if(argc<3) {
64 printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]);
65 printf("width and height are w/h of MPlayer's screen!\n");
66 exit(10);
69 width = atoi(argv[3]);
70 height = atoi(argv[4]);
72 fifo = open( argv[1], O_RDWR );
73 if(!fifo) {
74 fprintf(stderr, "Error opening FIFO %s!\n", argv[1]);
75 exit(10);
78 image = IMG_Load(argv[2]);
79 if(!image) {
80 fprintf(stderr, "Couldn't load image %s!\n", argv[2]);
81 exit(10);
84 printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h);
86 // Display and move image
87 for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5)
88 blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1);
90 // Create a 75x75 bitmap
91 bitmap = (unsigned char*)malloc(75*75*4);
93 // Paint bitmap red, 50% transparent and blit at position 50,50
94 paint(bitmap, (75*75*4), 255, 0, 0, 128);
95 blit(fifo, bitmap, 75, 75, 50, 50, 0, 0);
97 // Paint bitmap green, 50% transparent and blit at position -50,50
98 paint(bitmap, (75*75*4), 0, 255, 0, 128);
99 blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0);
101 // Paint bitmap blue, 50% transparent and blit at position -50,50
102 paint(bitmap, (75*75*4), 0, 0, 255, 128);
103 blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0);
105 // Blit another image in the middle, completly transparent
106 blit(fifo, image->pixels, image->w, image->h,
107 (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0);
109 // Fade in image
110 for(i=-255; i <= 0; i++)
111 set_alpha(fifo, image->w, image->h,
112 (width/2)-(image->w/2), (height/2)-(image->h/2), i);
115 // Clean up
116 free(bitmap);
117 SDL_FreeSurface(image);
119 return 0;