Mercurial > mplayer.hg
comparison TOOLS/bmovl-test.c @ 22737:6ce48e36dc01
Move gltest and bmovl-test into the main TOOLS directory, subdirectories
for single files are silly.
author | diego |
---|---|
date | Tue, 20 Mar 2007 01:06:51 +0000 |
parents | |
children | 25586323a128 |
comparison
equal
deleted
inserted
replaced
22736:69c9abd89634 | 22737:6ce48e36dc01 |
---|---|
1 /* Small program to test the features of vf_bmovl */ | |
2 | |
3 #include <unistd.h> | |
4 #include <fcntl.h> | |
5 #include <SDL.h> | |
6 #include <SDL_image.h> | |
7 | |
8 #define DEBUG 0 | |
9 | |
10 static void | |
11 blit(int fifo, unsigned char *bitmap, int width, int height, | |
12 int xpos, int ypos, int alpha, int clear) | |
13 { | |
14 char str[100]; | |
15 int nbytes; | |
16 | |
17 sprintf(str, "RGBA32 %d %d %d %d %d %d\n", | |
18 width, height, xpos, ypos, alpha, clear); | |
19 | |
20 if(DEBUG) printf("Sending %s", str); | |
21 | |
22 write(fifo, str, strlen(str)); | |
23 nbytes = write(fifo, bitmap, width*height*4); | |
24 | |
25 if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes); | |
26 } | |
27 | |
28 static void | |
29 set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) { | |
30 char str[100]; | |
31 | |
32 sprintf(str, "ALPHA %d %d %d %d %d\n", | |
33 width, height, xpos, ypos, alpha); | |
34 | |
35 if(DEBUG) printf("Sending %s", str); | |
36 | |
37 write(fifo, str, strlen(str)); | |
38 } | |
39 | |
40 static void | |
41 paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) { | |
42 | |
43 int i; | |
44 | |
45 for(i=0; i < size; i+=4) { | |
46 bitmap[i+0] = red; | |
47 bitmap[i+1] = green; | |
48 bitmap[i+2] = blue; | |
49 bitmap[i+3] = alpha; | |
50 } | |
51 } | |
52 | |
53 int main(int argc, char **argv) { | |
54 | |
55 int fifo=-1; | |
56 int width=0, height=0, xpos=0, ypos=0, alpha=0, clear=0; | |
57 unsigned char *bitmap; | |
58 SDL_Surface *image; | |
59 int i; | |
60 | |
61 if(argc<3) { | |
62 printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]); | |
63 printf("width and height are w/h of MPlayer's screen!\n"); | |
64 exit(10); | |
65 } | |
66 | |
67 width = atoi(argv[3]); | |
68 height = atoi(argv[4]); | |
69 | |
70 fifo = open( argv[1], O_RDWR ); | |
71 if(!fifo) { | |
72 fprintf(stderr, "Error opening FIFO %s!\n", argv[1]); | |
73 exit(10); | |
74 } | |
75 | |
76 image = IMG_Load(argv[2]); | |
77 if(!image) { | |
78 fprintf(stderr, "Couldn't load image %s!\n", argv[2]); | |
79 exit(10); | |
80 } | |
81 | |
82 printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h); | |
83 | |
84 // Display and move image | |
85 for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5) | |
86 blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1); | |
87 | |
88 // Create a 75x75 bitmap | |
89 bitmap = (unsigned char*)malloc(75*75*4); | |
90 | |
91 // Paint bitmap red, 50% transparent and blit at position 50,50 | |
92 paint(bitmap, (75*75*4), 255, 0, 0, 128); | |
93 blit(fifo, bitmap, 75, 75, 50, 50, 0, 0); | |
94 | |
95 // Paint bitmap green, 50% transparent and blit at position -50,50 | |
96 paint(bitmap, (75*75*4), 0, 255, 0, 128); | |
97 blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0); | |
98 | |
99 // Paint bitmap blue, 50% transparent and blit at position -50,50 | |
100 paint(bitmap, (75*75*4), 0, 0, 255, 128); | |
101 blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0); | |
102 | |
103 // Blit another image in the middle, completly transparent | |
104 blit(fifo, image->pixels, image->w, image->h, | |
105 (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0); | |
106 | |
107 // Fade in image | |
108 for(i=-255; i <= 0; i++) | |
109 set_alpha(fifo, image->w, image->h, | |
110 (width/2)-(image->w/2), (height/2)-(image->h/2), i); | |
111 | |
112 | |
113 // Clean up | |
114 free(bitmap); | |
115 SDL_FreeSurface(image); | |
116 } |