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.
27 #include "img_format.h"
31 #include "libswscale/rgb2rgb.h"
33 //===========================================================================//
40 static unsigned int getfmt(unsigned int outfmt
,int forced
){
41 if(forced
) 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
;
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
){
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
,
72 if(mpi
->stride
[0]!=dmpi
->stride
[0] || mpi
->stride
[0]!=mpi
->w
*(mpi
->bpp
/8)){
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
++){
79 rgb32tobgr32(src
,dst
,srcsize
);
81 rgb24tobgr24(src
,dst
,srcsize
);
87 rgb32tobgr32(mpi
->planes
[0],dmpi
->planes
[0],mpi
->w
*mpi
->h
*4);
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
);
100 return vf_next_query_format(vf
,fmt
) & (~VFCAP_CSP_SUPPORTED_BY_HW
);
103 static int vf_open(vf_instance_t
*vf
, char *args
){
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");
112 const vf_info_t vf_info_rgb2bgr
= {
113 "fast 24/32bpp RGB<->BGR conversion",
121 //===========================================================================//