vf_bmovl.c

来自「君正早期ucos系统(只有早期的才不没有打包成库),MPLAYER,文件系统,图」· C语言 代码 · 共 480 行 · 第 1/2 页

C
480
字号
/* vf_bmovl.c v0.9.1 - BitMap OVerLay videofilter for MPlayer * * (C) 2002 Per Wigren <wigren@home.se> * Licenced under the GNU General Public License * * Use MPlayer as a framebuffer to read bitmaps and commands from a FIFO * and display them in the window. * * Commands are: * * RGBA32 width height xpos ypos alpha clear *   * Followed by width*height*4 bytes of raw RGBA32 data. * ABGR32 width height xpos ypos alpha clear *   * Followed by width*height*4 bytes of raw ABGR32 data. * RGB24 width height xpos ypos alpha clear *   * Followed by width*height*3 bytes of raw RGB32 data. * BGR24 width height xpos ypos alpha clear *   * Followed by width*height*3 bytes of raw BGR32 data. * * ALPHA width height xpos ypos alpha *   * Change alpha for area * CLEAR width height xpos ypos *   * Clear area * OPAQUE *   * Disable all alpha transparency! *      Send "ALPHA 0 0 0 0 0" to enable again! * HIDE *   * Hide bitmap * SHOW *   * Show bitmap * * Arguments are: * width, height    Size of image/area * xpos, ypos       Start blitting at X/Y position * alpha            Set alpha difference. 0 means same as original. *                  255 makes everything opaque *                  -255 makes everything transparent *                  If you set this to -255 you can then send a sequence of *                  ALPHA-commands to set the area to -225, -200, -175 etc *                  for a nice fade-in-effect! ;) * clear            Clear the framebuffer before blitting. 1 means clear. *                  If 0, the image will just be blitted on top of the old *                  one, so you don't need to send 1,8MB of RGBA32 data *                  everytime a small part of the screen is updated. * * Arguments for the filter are hidden:opaque:fifo * For example 1:0:/tmp/myfifo.fifo will start the filter hidden, transparent * and use /tmp/myfifo.fifo as the fifo. * * If you find bugs, please send me patches! ;) * * This filter was developed for use in Freevo (http://freevo.sf.net), but * anyone is free to use it! ;) * */#include <uclib.h>#include <uclib.h>#include <uclib.h>#include <uclib.h>#include <errno.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/time.h>#include <fcntl.h>#include "config.h"#include "mp_image.h"#include "vf.h"#include "img_format.h"#include "mp_msg.h"#include "libavutil/common.h"#include "libvo/fastmemcpy.h"#define IS_RAWIMG	0x100#define IS_IMG		0x200#define NONE		0x000#define IMG_RGBA32	0x101#define IMG_ABGR32	0x102#define IMG_RGB24	0x103#define IMG_BGR24	0x104#define IMG_PNG		0x201#define CMD_CLEAR	0x001#define CMD_ALPHA	0x002#define TRUE  1#define FALSE 0#define INRANGE(a,b,c)	( ((a) < (b)) ? (b) : ( ((a) > (c)) ? (c) : (a) ) )#define rgb2y(R,G,B)  ( (( 263*R + 516*G + 100*B) >> 10) + 16  )#define rgb2u(R,G,B)  ( ((-152*R - 298*G + 450*B) >> 10) + 128 )#define rgb2v(R,G,B)  ( (( 450*R - 376*G -  73*B) >> 10) + 128 )#define DBG(a) (mp_msg(MSGT_VFILTER, MSGL_DBG2, "DEBUG: %d\n", a))struct vf_priv_s {    int w, h, x1, y1, x2, y2;	struct {		unsigned char *y, *u, *v, *a, *oa;	} bitmap;    int stream_fd;	fd_set stream_fdset;	int opaque, hidden;};static intquery_format(struct vf_instance_s* vf, unsigned int fmt){    if(fmt==IMGFMT_YV12) return VFCAP_CSP_SUPPORTED;    return 0;}static intconfig(struct vf_instance_s* vf,       int width, int height, int d_width, int d_height,       unsigned int flags, unsigned int outfmt){	vf->priv->bitmap.y  = malloc( width*height );	vf->priv->bitmap.u  = malloc( width*height/4 );	vf->priv->bitmap.v  = malloc( width*height/4 );	vf->priv->bitmap.a  = malloc( width*height );	vf->priv->bitmap.oa = malloc( width*height );	if(!( vf->priv->bitmap.y &&	      vf->priv->bitmap.u &&		  vf->priv->bitmap.v &&		  vf->priv->bitmap.a &&		  vf->priv->bitmap.oa )) {		mp_msg(MSGT_VFILTER, MSGL_ERR, "vf_bmovl: Could not allocate memory for bitmap buffer: %s\n", strerror(errno) );		return FALSE;	}	// Set default to black...	memset( vf->priv->bitmap.u, 128, width*height/4 );	memset( vf->priv->bitmap.v, 128, width*height/4 );    vf->priv->w  = vf->priv->x1 = width;    vf->priv->h  = vf->priv->y1 = height;    vf->priv->y2 = vf->priv->x2 = 0;    return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt);}static voiduninit(struct vf_instance_s *vf){	if(vf->priv) {		free(vf->priv->bitmap.y);		free(vf->priv->bitmap.u);		free(vf->priv->bitmap.v);		free(vf->priv->bitmap.a);		free(vf->priv->bitmap.oa);		if (vf->priv->stream_fd >= 0)		  close(vf->priv->stream_fd);		free(vf->priv);	}}static int_read_cmd(int fd, char *cmd, char *args) {	int done=FALSE, pos=0;	char tmp;	while(!done) {		if(! read( fd, &tmp, 1 ) ) return FALSE;		if( (tmp>='A' && tmp<='Z') || (tmp>='0' && tmp<='9') )			cmd[pos]=tmp;		else if(tmp == ' ') {			cmd[pos]='\0';			done=TRUE;		}		else if(tmp == '\n') {			cmd[pos]='\0';			args[0]='\0';			return TRUE;		}		if(pos++>20) {			cmd[0]='\0';			return TRUE;		}	}	done=FALSE; pos=0;	while(!done) {		if(! read( fd, &tmp, 1 ) ) return FALSE;		if( (tmp >= ' ') && (pos<100) ) args[pos]=tmp;		else {			args[pos]='\0';			done=TRUE;		}		pos++;	}	return TRUE;}			static intput_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){	int buf_x=0, buf_y=0, buf_pos=0;	int have, got, want;	int xpos=0, ypos=0, pos=0;	unsigned char red=0, green=0, blue=0;	int  alpha;	mp_image_t* dmpi;    dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP,						MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,						mpi->w, mpi->h);    memcpy_pic( dmpi->planes[0], mpi->planes[0], mpi->width, mpi->height, dmpi->stride[0], mpi->stride[0] );    memcpy_pic( dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height, dmpi->stride[1], mpi->stride[1] );    memcpy_pic( dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height, dmpi->stride[2], mpi->stride[2] );    if(vf->priv->stream_fd >= 0) {		struct timeval tv;		int ready;		FD_SET( vf->priv->stream_fd, &vf->priv->stream_fdset );		tv.tv_sec=0; tv.tv_usec=0;		ready = select( vf->priv->stream_fd+1, &vf->priv->stream_fdset, NULL, NULL, &tv );		if(ready > 0) {			// We've got new data from the FIFO			char cmd[20], args[100];			int  imgw,imgh,imgx,imgy,clear,imgalpha,pxsz=1,command;			unsigned char *buffer = NULL;			if(! _read_cmd( vf->priv->stream_fd, cmd, args) ) {				mp_msg(MSGT_VFILTER, MSGL_ERR, "\nvf_bmovl: Error reading commands: %s\n\n", strerror(errno));				return FALSE;			}			mp_msg(MSGT_VFILTER, MSGL_DBG2, "\nDEBUG: Got: %s+%s\n", cmd, args);			command=NONE;			if     ( strncmp(cmd,"RGBA32",6)==0 ) { pxsz=4; command = IMG_RGBA32; }			else if( strncmp(cmd,"ABGR32",6)==0 ) { pxsz=4; command = IMG_ABGR32; }			else if( strncmp(cmd,"RGB24" ,5)==0 ) { pxsz=3; command = IMG_RGB24;  }			else if( strncmp(cmd,"BGR24" ,5)==0 ) { pxsz=3; command = IMG_BGR24;  }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?