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 //===========================================================================//
33 static const unsigned int bgr_list
[]={
61 static unsigned int find_best(struct vf_instance
* vf
){
64 const unsigned int* p
=bgr_list
;
66 ret
=vf
->next
->query_format(vf
->next
,*p
);
67 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
68 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){ best
=*p
; break;} // no conversion -> bingo!
69 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
) best
=*p
; // best with conversion
75 //===========================================================================//
81 static int config(struct vf_instance
* vf
,
82 int width
, int height
, int d_width
, int d_height
,
83 unsigned int flags
, unsigned int outfmt
){
85 vf
->priv
->fmt
=find_best(vf
);
87 // no matching fmt, so force one...
88 if(outfmt
==IMGFMT_RGB8
) vf
->priv
->fmt
=IMGFMT_RGB32
;
89 else if(outfmt
==IMGFMT_BGR8
) vf
->priv
->fmt
=IMGFMT_BGR32
;
92 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,vf
->priv
->fmt
);
95 static const int bittab
[8]={128,64,32,16,8,4,2,1};
97 static void convert(mp_image_t
*mpi
, mp_image_t
*dmpi
, int value0
, int value1
,int bpp
){
99 for(y
=0;y
<mpi
->h
;y
++){
100 unsigned char* src
=mpi
->planes
[0]+mpi
->stride
[0]*y
;
103 unsigned char* dst
=dmpi
->planes
[0]+dmpi
->stride
[0]*y
;
105 for(x
=0;x
<mpi
->w
;x
++)
106 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
109 uint16_t* dst
=(uint16_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
111 for(x
=0;x
<mpi
->w
;x
++)
112 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
115 uint32_t* dst
=(uint32_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
117 for(x
=0;x
<mpi
->w
;x
++)
118 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
124 static int put_image(struct vf_instance
* vf
, mp_image_t
*mpi
, double pts
){
127 // hope we'll get DR buffer:
128 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
129 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
132 switch(dmpi
->imgfmt
){
137 convert(mpi
,dmpi
,0,255,1);
146 convert(mpi
,dmpi
,0,255,1);
147 memset(dmpi
->planes
[1],128,dmpi
->stride
[1]*dmpi
->chroma_height
);
148 memset(dmpi
->planes
[2],128,dmpi
->stride
[2]*dmpi
->chroma_height
);
151 convert(mpi
,dmpi
,0x8000,0x80ff,2);
155 convert(mpi
,dmpi
,0,0x7fff,2);
159 convert(mpi
,dmpi
,0,0xffff,2);
163 convert(mpi
,dmpi
,0,0x00ffffff,4);
166 mp_msg(MSGT_VFILTER
,MSGL_ERR
,"Unhandled format: 0x%X\n",dmpi
->imgfmt
);
170 return vf_next_put_image(vf
,dmpi
, pts
);
173 //===========================================================================//
175 static int query_format(struct vf_instance
* vf
, unsigned int fmt
){
177 if(fmt
!=IMGFMT_RGB1
&& fmt
!=IMGFMT_BGR1
) return 0;
179 if(!best
) return 0; // no match
180 return vf
->next
->query_format(vf
->next
,best
);
183 static int vf_open(vf_instance_t
*vf
, char *args
){
185 vf
->put_image
=put_image
;
186 vf
->query_format
=query_format
;
187 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
188 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
192 const vf_info_t vf_info_1bpp
= {
193 "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
201 //===========================================================================//