9 #include "img_format.h"
13 #include "postproc/rgb2rgb.h"
15 //===========================================================================//
17 static unsigned int bgr_list
[]={
45 static unsigned int find_best(struct vf_instance_s
* vf
){
48 unsigned int* p
=bgr_list
;
50 ret
=vf
->next
->query_format(vf
->next
,*p
);
51 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
52 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){ best
=*p
; break;} // no conversion -> bingo!
53 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
) best
=*p
; // best with conversion
59 //===========================================================================//
65 static int config(struct vf_instance_s
* vf
,
66 int width
, int height
, int d_width
, int d_height
,
67 unsigned int flags
, unsigned int outfmt
){
69 vf
->priv
->fmt
=find_best(vf
);
71 // no matching fmt, so force one...
72 if(outfmt
==IMGFMT_RGB8
) vf
->priv
->fmt
=IMGFMT_RGB32
;
73 else if(outfmt
==IMGFMT_BGR8
) vf
->priv
->fmt
=IMGFMT_BGR32
;
76 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,vf
->priv
->fmt
);
79 static int bittab
[8]={128,64,32,16,8,4,2,1};
81 static void convert(mp_image_t
*mpi
, mp_image_t
*dmpi
, int value0
, int value1
,int bpp
){
83 for(y
=0;y
<mpi
->h
;y
++){
84 unsigned char* src
=mpi
->planes
[0]+mpi
->stride
[0]*y
;
87 unsigned char* dst
=dmpi
->planes
[0]+dmpi
->stride
[0]*y
;
90 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
93 uint16_t* dst
=(uint16_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
96 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
99 uint32_t* dst
=(uint32_t*)(dmpi
->planes
[0]+dmpi
->stride
[0]*y
);
101 for(x
=0;x
<mpi
->w
;x
++)
102 dst
[x
]=(src
[x
>>3]&bittab
[x
&7]) ? value1
: value0
;
108 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
111 // hope we'll get DR buffer:
112 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
113 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
116 switch(dmpi
->imgfmt
){
121 convert(mpi
,dmpi
,0,255,1);
130 convert(mpi
,dmpi
,0,255,1);
131 memset(dmpi
->planes
[1],128,dmpi
->stride
[1]*dmpi
->chroma_height
);
132 memset(dmpi
->planes
[2],128,dmpi
->stride
[2]*dmpi
->chroma_height
);
135 convert(mpi
,dmpi
,0x8000,0x80ff,2);
139 convert(mpi
,dmpi
,0,0x7fff,2);
143 convert(mpi
,dmpi
,0,0xffff,2);
147 convert(mpi
,dmpi
,0,0x00ffffff,4);
150 mp_msg(MSGT_VFILTER
,MSGL_ERR
,"Unhandled format: 0x%X\n",dmpi
->imgfmt
);
154 return vf_next_put_image(vf
,dmpi
, pts
);
157 //===========================================================================//
159 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
161 if(fmt
!=IMGFMT_RGB1
&& fmt
!=IMGFMT_BGR1
) return 0;
163 if(!best
) return 0; // no match
164 return vf
->next
->query_format(vf
->next
,best
);
167 static int open(vf_instance_t
*vf
, char* args
){
169 vf
->put_image
=put_image
;
170 vf
->query_format
=query_format
;
171 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
172 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
176 vf_info_t vf_info_1bpp
= {
177 "1bpp bitmap -> YUV/BGR 8/15/16/32 conversion",
185 //===========================================================================//