annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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>
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
5 #include <SDL.h>
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
6 #include <SDL_image.h>
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
7
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
8 #define DEBUG 0
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 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
11 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
12 int xpos, int ypos, int alpha, int clear)
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
13 {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
14 char str[100];
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
15 int nbytes;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
16
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
17 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
18 width, height, xpos, ypos, alpha, clear);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
19
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
20 if(DEBUG) printf("Sending %s", str);
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 write(fifo, str, strlen(str));
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
23 nbytes = write(fifo, bitmap, width*height*4);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
24
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
25 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
26 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
27
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
28 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
29 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
30 char str[100];
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
31
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
32 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
33 width, height, xpos, ypos, alpha);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
34
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
35 if(DEBUG) printf("Sending %s", str);
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 write(fifo, str, strlen(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
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
40 static void
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
41 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
42
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
43 int i;
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 for(i=0; i < size; i+=4) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
46 bitmap[i+0] = red;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
47 bitmap[i+1] = green;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
48 bitmap[i+2] = blue;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
49 bitmap[i+3] = alpha;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
50 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
51 }
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 int main(int argc, char **argv) {
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 fifo=-1;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
56 int width=0, height=0, xpos=0, ypos=0, alpha=0, clear=0;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
57 unsigned char *bitmap;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
58 SDL_Surface *image;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
59 int i;
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
60
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
61 if(argc<3) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
62 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
63 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
64 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
65 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
66
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
67 width = atoi(argv[3]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
68 height = atoi(argv[4]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
69
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
70 fifo = open( argv[1], O_RDWR );
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
71 if(!fifo) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
72 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
73 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
74 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
75
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
76 image = IMG_Load(argv[2]);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
77 if(!image) {
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
78 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
79 exit(10);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
80 }
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
81
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
82 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
83
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
84 // Display and move image
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
85 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
86 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
87
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
88 // Create a 75x75 bitmap
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
89 bitmap = (unsigned char*)malloc(75*75*4);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
90
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
91 // 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
92 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
93 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
94
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
95 // 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
96 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
97 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
98
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
99 // 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
100 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
101 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
102
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
103 // Blit another image in the middle, completly transparent
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
104 blit(fifo, image->pixels, image->w, image->h,
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
105 (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
106
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
107 // Fade in image
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
108 for(i=-255; i <= 0; i++)
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
109 set_alpha(fifo, image->w, image->h,
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
110 (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
111
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
112
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
113 // Clean up
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
114 free(bitmap);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
115 SDL_FreeSurface(image);
6ce48e36dc01 Move gltest and bmovl-test into the main TOOLS directory, subdirectories
diego
parents:
diff changeset
116 }