rtsp: Support RTSP/RTP over HTTP via LIVE555
[mplayer.git] / libmpcodecs / vf_rgb2bgr.c
blob95b3fa363925bc9fd89c8f81e9df0217a114f987
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
27 #include "img_format.h"
28 #include "mp_image.h"
29 #include "vf.h"
31 #include "libswscale/rgb2rgb.h"
33 //===========================================================================//
35 struct vf_priv_s {
36 unsigned int fmt;
37 int forced;
40 static unsigned int getfmt(unsigned int outfmt,int forced){
41 if(forced) switch(outfmt){
42 case IMGFMT_RGB24:
43 case IMGFMT_RGB32:
44 case IMGFMT_BGR24:
45 case IMGFMT_BGR32:
46 return outfmt;
48 switch(outfmt){
49 case IMGFMT_RGB24: return IMGFMT_BGR24;
50 case IMGFMT_RGB32: return IMGFMT_BGR32;
51 case IMGFMT_BGR24: return IMGFMT_RGB24;
52 case IMGFMT_BGR32: return IMGFMT_RGB32;
54 return 0;
57 static int config(struct vf_instance *vf,
58 int width, int height, int d_width, int d_height,
59 unsigned int flags, unsigned int outfmt){
60 vf->priv->fmt=getfmt(outfmt,vf->priv->forced);
61 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
64 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
65 mp_image_t *dmpi;
67 // hope we'll get DR buffer:
68 dmpi=vf_get_image(vf->next,vf->priv->fmt,
69 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
70 mpi->w, mpi->h);
72 if(mpi->stride[0]!=dmpi->stride[0] || mpi->stride[0]!=mpi->w*(mpi->bpp/8)){
73 int y;
74 unsigned char* src=mpi->planes[0];
75 unsigned char* dst=dmpi->planes[0];
76 int srcsize=mpi->w*mpi->bpp/8;
77 for(y=0;y<mpi->h;y++){
78 if(mpi->bpp==32)
79 rgb32tobgr32(src,dst,srcsize);
80 else
81 rgb24tobgr24(src,dst,srcsize);
82 src+=mpi->stride[0];
83 dst+=dmpi->stride[0];
85 } else {
86 if(mpi->bpp==32)
87 rgb32tobgr32(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*4);
88 else
89 rgb24tobgr24(mpi->planes[0],dmpi->planes[0],mpi->w*mpi->h*3);
92 return vf_next_put_image(vf,dmpi, pts);
95 //===========================================================================//
97 static int query_format(struct vf_instance *vf, unsigned int outfmt){
98 unsigned int fmt=getfmt(outfmt,vf->priv->forced);
99 if(!fmt) return 0;
100 return vf_next_query_format(vf,fmt) & (~VFCAP_CSP_SUPPORTED_BY_HW);
103 static int vf_open(vf_instance_t *vf, char *args){
104 vf->config=config;
105 vf->put_image=put_image;
106 vf->query_format=query_format;
107 vf->priv=malloc(sizeof(struct vf_priv_s));
108 vf->priv->forced=args && !strcasecmp(args,"swap");
109 return 1;
112 const vf_info_t vf_info_rgb2bgr = {
113 "fast 24/32bpp RGB<->BGR conversion",
114 "rgb2bgr",
115 "A'rpi",
117 vf_open,
118 NULL
121 //===========================================================================//