annotate TOOLS/bmovl-test/bmovl-test.c @ 17463:b56f34ba3f2f

proper support for shared libpostproc patch by Nico Sabbi, fixes and consistency cleanups by me
author diego
date Sun, 22 Jan 2006 18:11:35 +0000
parents 0e1b59efcef3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7856
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
1 /* Small program to test the features of vf_bmovl */
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
2
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
3 #include <unistd.h>
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
4 #include <fcntl.h>
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
5 #include <SDL.h>
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
6 #include <SDL_image.h>
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
7
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
8 #define DEBUG 0
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
9
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
10 static void
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
11 blit(int fifo, unsigned char *bitmap, int width, int height,
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
12 int xpos, int ypos, int alpha, int clear)
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
13 {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
14 char str[100];
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
15 int nbytes;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
16
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
17 sprintf(str, "RGBA32 %d %d %d %d %d %d\n",
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
18 width, height, xpos, ypos, alpha, clear);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
19
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
20 if(DEBUG) printf("Sending %s", str);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
21
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
22 write(fifo, str, strlen(str));
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
23 nbytes = write(fifo, bitmap, width*height*4);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
24
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
25 if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
26 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
27
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
28 static void
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
29 set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
30 char str[100];
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
31
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
32 sprintf(str, "ALPHA %d %d %d %d %d\n",
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
33 width, height, xpos, ypos, alpha);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
34
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
35 if(DEBUG) printf("Sending %s", str);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
36
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
37 write(fifo, str, strlen(str));
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
38 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
39
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
40 static void
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
41 paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
42
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
43 int i;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
44
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
45 for(i=0; i < size; i+=4) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
46 bitmap[i+0] = red;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
47 bitmap[i+1] = green;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
48 bitmap[i+2] = blue;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
49 bitmap[i+3] = alpha;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
50 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
51 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
52
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
53 int main(int argc, char **argv) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
54
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
55 int fifo=-1;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
56 int width=0, height=0, xpos=0, ypos=0, alpha=0, clear=0;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
57 unsigned char *bitmap;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
58 SDL_Surface *image;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
59 int i;
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
60
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
61 if(argc<3) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
62 printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
63 printf("width and height are w/h of MPlayer's screen!\n");
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
64 exit(10);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
65 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
66
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
67 width = atoi(argv[3]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
68 height = atoi(argv[4]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
69
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
70 fifo = open( argv[1], O_RDWR );
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
71 if(!fifo) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
72 fprintf(stderr, "Error opening FIFO %s!\n", argv[1]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
73 exit(10);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
74 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
75
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
76 image = IMG_Load(argv[2]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
77 if(!image) {
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
78 fprintf(stderr, "Couldn't load image %s!\n", argv[2]);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
79 exit(10);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
80 }
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
81
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
82 printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
83
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
84 // Display and move image
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
85 for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5)
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
86 blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
87
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
88 // Create a 75x75 bitmap
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
89 bitmap = (unsigned char*)malloc(75*75*4);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
90
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
91 // Paint bitmap red, 50% transparent and blit at position 50,50
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
92 paint(bitmap, (75*75*4), 255, 0, 0, 128);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
93 blit(fifo, bitmap, 75, 75, 50, 50, 0, 0);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
94
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
95 // Paint bitmap green, 50% transparent and blit at position -50,50
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
96 paint(bitmap, (75*75*4), 0, 255, 0, 128);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
97 blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
98
13474
0e1b59efcef3 Wrong comment, the bitmap is blue, not green.
diego
parents: 7856
diff changeset
99 // Paint bitmap blue, 50% transparent and blit at position -50,50
7856
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
100 paint(bitmap, (75*75*4), 0, 0, 255, 128);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
101 blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
102
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
103 // Blit another image in the middle, completly transparent
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
104 blit(fifo, image->pixels, image->w, image->h,
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
105 (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
106
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
107 // Fade in image
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
108 for(i=-255; i <= 0; i++)
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
109 set_alpha(fifo, image->w, image->h,
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
110 (width/2)-(image->w/2), (height/2)-(image->h/2), i);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
111
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
112
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
113 // Clean up
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
114 free(bitmap);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
115 SDL_FreeSurface(image);
ac161720f4f0 sample client for -vop bmovl -- loads and alphablend any PNG file
arpi
parents:
diff changeset
116 }