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