9 #include "img_format.h"
13 //===========================================================================//
15 static const unsigned int bgr_list
[]={
43 static unsigned int find_best(struct vf_instance_s
* vf
){
46 const unsigned int* p
=bgr_list
;
48 ret
=vf
->next
->query_format(vf
->next
,*p
);
49 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
50 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){ best
=*p
; break;} // no conversion -> bingo!
51 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
) best
=*p
; // best with conversion
57 //===========================================================================//
63 static int config(struct vf_instance_s
* vf
,
64 int width
, int height
, int d_width
, int d_height
,
65 unsigned int flags
, unsigned int outfmt
){
67 vf
->priv
->fmt
=find_best(vf
);
69 // no matching fmt, so force one...
70 if(outfmt
==IMGFMT_RGB8
) vf
->priv
->fmt
=IMGFMT_RGB32
;
71 else if(outfmt
==IMGFMT_BGR8
) vf
->priv
->fmt
=IMGFMT_BGR32
;
74 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,vf
->priv
->fmt
);
77 static const int bittab
[8]={128,64,32,16,8,4,2,1};
79 static void convert(mp_image_t
*mpi
, mp_image_t
*dmpi
, int value0
, int value1
,int bpp
){
81 for(y
=0;y
<mpi
->h
;y
++){
82 unsigned char* src
=mpi
->planes
[0]+mpi
->stride
[0]*y
;
85 unsigned char* dst
=dmpi
->planes
[0]+dmpi
->stride
[0]*y
;
88 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
91 uint16_t* dst
=(uint16_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
94 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
97 uint32_t* dst
=(uint32_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
100 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
106 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
109 // hope we'll get DR buffer:
110 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
111 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
114 switch(dmpi
->imgfmt
){
119 convert(mpi
,dmpi
,0,255,1);
128 convert(mpi
,dmpi
,0,255,1);
129 memset(dmpi
->planes
[1],128,dmpi
->stride
[1]*dmpi
->chroma_height
);
130 memset(dmpi
->planes
[2],128,dmpi
->stride
[2]*dmpi
->chroma_height
);
133 convert(mpi
,dmpi
,0x8000,0x80ff,2);
137 convert(mpi
,dmpi
,0,0x7fff,2);
141 convert(mpi
,dmpi
,0,0xffff,2);
145 convert(mpi
,dmpi
,0,0x00ffffff,4);
148 mp_msg(MSGT_VFILTER
,MSGL_ERR
,"Unhandled format: 0x%X\n",dmpi
->imgfmt
);
152 return vf_next_put_image(vf
,dmpi
, pts
);
155 //===========================================================================//
157 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
159 if(fmt
!=IMGFMT_RGB1
&& fmt
!=IMGFMT_BGR1
) return 0;
161 if(!best
) return 0; // no match
162 return vf
->next
->query_format(vf
->next
,best
);
165 static int open(vf_instance_t
*vf
, char* args
){
167 vf
->put_image
=put_image
;
168 vf
->query_format
=query_format
;
169 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
170 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
174 const vf_info_t vf_info_1bpp
= {
175 "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
183 //===========================================================================//