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.
24 #include <SDL/SDL_image.h>
29 blit(int fifo
, unsigned char *bitmap
, int width
, int height
,
30 int xpos
, int ypos
, int alpha
, int clear
)
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
);
47 set_alpha(int fifo
, int width
, int height
, int xpos
, int ypos
, int alpha
) {
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
));
59 paint(unsigned char* bitmap
, int size
, int red
, int green
, int blue
, int alpha
) {
63 for(i
=0; i
< size
; i
+=4) {
71 int main(int argc
, char **argv
) {
74 int width
=0, height
=0;
75 unsigned char *bitmap
;
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");
85 width
= atoi(argv
[3]);
86 height
= atoi(argv
[4]);
88 fifo
= open( argv
[1], O_RDWR
);
90 fprintf(stderr
, "Error opening FIFO %s!\n", argv
[1]);
94 image
= IMG_Load(argv
[2]);
96 fprintf(stderr
, "Couldn't load image %s!\n", argv
[2]);
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);
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
);
133 SDL_FreeSurface(image
);