Change some filename-handling code to use mp_basename()
[mplayer/greg.git] / TOOLS / bmovl-test.c
blob04c1e7dd7109edccc417765cc9b0e179a500b7cc
1 /* small program to test the features of vf_bmovl
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <unistd.h>
20 #include <fcntl.h>
21 #include <string.h>
22 #include <stdlib.h>
23 #include <SDL/SDL.h>
24 #include <SDL/SDL_image.h>
26 #define DEBUG 0
28 static void
29 blit(int fifo, unsigned char *bitmap, int width, int height,
30 int xpos, int ypos, int alpha, int clear)
32 char str[100];
33 int nbytes;
35 sprintf(str, "RGBA32 %d %d %d %d %d %d\n",
36 width, height, xpos, ypos, alpha, clear);
38 if(DEBUG) printf("Sending %s", str);
40 write(fifo, str, strlen(str));
41 nbytes = write(fifo, bitmap, width*height*4);
43 if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes);
46 static void
47 set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) {
48 char str[100];
50 sprintf(str, "ALPHA %d %d %d %d %d\n",
51 width, height, xpos, ypos, alpha);
53 if(DEBUG) printf("Sending %s", str);
55 write(fifo, str, strlen(str));
58 static void
59 paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) {
61 int i;
63 for(i=0; i < size; i+=4) {
64 bitmap[i+0] = red;
65 bitmap[i+1] = green;
66 bitmap[i+2] = blue;
67 bitmap[i+3] = alpha;
71 int main(int argc, char **argv) {
73 int fifo=-1;
74 int width=0, height=0;
75 unsigned char *bitmap;
76 SDL_Surface *image;
77 int i;
79 if(argc<3) {
80 printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]);
81 printf("width and height are w/h of MPlayer's screen!\n");
82 exit(10);
85 width = atoi(argv[3]);
86 height = atoi(argv[4]);
88 fifo = open( argv[1], O_RDWR );
89 if(!fifo) {
90 fprintf(stderr, "Error opening FIFO %s!\n", argv[1]);
91 exit(10);
94 image = IMG_Load(argv[2]);
95 if(!image) {
96 fprintf(stderr, "Couldn't load image %s!\n", argv[2]);
97 exit(10);
100 printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h);
102 // Display and move image
103 for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5)
104 blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1);
106 // Create a 75x75 bitmap
107 bitmap = malloc(75 * 75 * 4);
109 // Paint bitmap red, 50% transparent and blit at position 50,50
110 paint(bitmap, (75*75*4), 255, 0, 0, 128);
111 blit(fifo, bitmap, 75, 75, 50, 50, 0, 0);
113 // Paint bitmap green, 50% transparent and blit at position -50,50
114 paint(bitmap, (75*75*4), 0, 255, 0, 128);
115 blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0);
117 // Paint bitmap blue, 50% transparent and blit at position -50,50
118 paint(bitmap, (75*75*4), 0, 0, 255, 128);
119 blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0);
121 // Blit another image in the middle, completly transparent
122 blit(fifo, image->pixels, image->w, image->h,
123 (width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0);
125 // Fade in image
126 for(i=-255; i <= 0; i++)
127 set_alpha(fifo, image->w, image->h,
128 (width/2)-(image->w/2), (height/2)-(image->h/2), i);
131 // Clean up
132 free(bitmap);
133 SDL_FreeSurface(image);
135 return 0;