2010-01-30 13:35:03 +00:00
|
|
|
/* small program to test the features of vf_bmovl
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
2002-10-23 00:28:27 +00:00
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <fcntl.h>
|
2007-03-20 01:11:55 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2007-03-20 01:20:57 +00:00
|
|
|
#include <SDL/SDL.h>
|
|
|
|
#include <SDL/SDL_image.h>
|
2002-10-23 00:28:27 +00:00
|
|
|
|
|
|
|
#define DEBUG 0
|
|
|
|
|
|
|
|
static void
|
|
|
|
blit(int fifo, unsigned char *bitmap, int width, int height,
|
|
|
|
int xpos, int ypos, int alpha, int clear)
|
|
|
|
{
|
|
|
|
char str[100];
|
|
|
|
int nbytes;
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 00:28:27 +00:00
|
|
|
sprintf(str, "RGBA32 %d %d %d %d %d %d\n",
|
|
|
|
width, height, xpos, ypos, alpha, clear);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 00:28:27 +00:00
|
|
|
if(DEBUG) printf("Sending %s", str);
|
|
|
|
|
|
|
|
write(fifo, str, strlen(str));
|
|
|
|
nbytes = write(fifo, bitmap, width*height*4);
|
|
|
|
|
|
|
|
if(DEBUG) printf("Sent %d bytes of bitmap data...\n", nbytes);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_alpha(int fifo, int width, int height, int xpos, int ypos, int alpha) {
|
|
|
|
char str[100];
|
|
|
|
|
|
|
|
sprintf(str, "ALPHA %d %d %d %d %d\n",
|
|
|
|
width, height, xpos, ypos, alpha);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 00:28:27 +00:00
|
|
|
if(DEBUG) printf("Sending %s", str);
|
|
|
|
|
|
|
|
write(fifo, str, strlen(str));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
paint(unsigned char* bitmap, int size, int red, int green, int blue, int alpha) {
|
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=0; i < size; i+=4) {
|
|
|
|
bitmap[i+0] = red;
|
|
|
|
bitmap[i+1] = green;
|
|
|
|
bitmap[i+2] = blue;
|
|
|
|
bitmap[i+3] = alpha;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv) {
|
|
|
|
|
|
|
|
int fifo=-1;
|
2007-07-04 20:03:17 +00:00
|
|
|
int width=0, height=0;
|
2002-10-23 00:28:27 +00:00
|
|
|
unsigned char *bitmap;
|
|
|
|
SDL_Surface *image;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if(argc<3) {
|
|
|
|
printf("Usage: %s <bmovl fifo> <image file> <width> <height>\n", argv[0]);
|
|
|
|
printf("width and height are w/h of MPlayer's screen!\n");
|
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
width = atoi(argv[3]);
|
|
|
|
height = atoi(argv[4]);
|
|
|
|
|
|
|
|
fifo = open( argv[1], O_RDWR );
|
|
|
|
if(!fifo) {
|
|
|
|
fprintf(stderr, "Error opening FIFO %s!\n", argv[1]);
|
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
image = IMG_Load(argv[2]);
|
|
|
|
if(!image) {
|
|
|
|
fprintf(stderr, "Couldn't load image %s!\n", argv[2]);
|
|
|
|
exit(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("Loaded image %s: width=%d, height=%d\n", argv[2], image->w, image->h);
|
|
|
|
|
|
|
|
// Display and move image
|
|
|
|
for(i=0; (i < (width - image->w)) && (i < (height - image->h)); i += 5)
|
|
|
|
blit(fifo, image->pixels, image->w, image->h, i, i, 0, 1);
|
|
|
|
|
|
|
|
// Create a 75x75 bitmap
|
2010-02-26 15:01:37 +00:00
|
|
|
bitmap = malloc(75 * 75 * 4);
|
2002-10-23 00:28:27 +00:00
|
|
|
|
|
|
|
// Paint bitmap red, 50% transparent and blit at position 50,50
|
|
|
|
paint(bitmap, (75*75*4), 255, 0, 0, 128);
|
|
|
|
blit(fifo, bitmap, 75, 75, 50, 50, 0, 0);
|
|
|
|
|
|
|
|
// Paint bitmap green, 50% transparent and blit at position -50,50
|
|
|
|
paint(bitmap, (75*75*4), 0, 255, 0, 128);
|
|
|
|
blit(fifo, bitmap, 75, 75, width-50-75, 50, 0, 0);
|
|
|
|
|
2004-09-26 12:57:53 +00:00
|
|
|
// Paint bitmap blue, 50% transparent and blit at position -50,50
|
2002-10-23 00:28:27 +00:00
|
|
|
paint(bitmap, (75*75*4), 0, 0, 255, 128);
|
|
|
|
blit(fifo, bitmap, 75, 75, 50, height-50-75, 0, 0);
|
|
|
|
|
|
|
|
// Blit another image in the middle, completly transparent
|
|
|
|
blit(fifo, image->pixels, image->w, image->h,
|
|
|
|
(width/2)-(image->w/2), (height/2)-(image->h/2), -255, 0);
|
|
|
|
|
|
|
|
// Fade in image
|
|
|
|
for(i=-255; i <= 0; i++)
|
|
|
|
set_alpha(fifo, image->w, image->h,
|
|
|
|
(width/2)-(image->w/2), (height/2)-(image->h/2), i);
|
2009-05-13 02:58:57 +00:00
|
|
|
|
2002-10-23 00:28:27 +00:00
|
|
|
|
|
|
|
// Clean up
|
|
|
|
free(bitmap);
|
|
|
|
SDL_FreeSurface(image);
|
2007-03-20 01:15:28 +00:00
|
|
|
|
|
|
|
return 0;
|
2002-10-23 00:28:27 +00:00
|
|
|
}
|