10 #include "img_format.h"
14 #include "libswscale/rgb2rgb.h"
16 //===========================================================================//
18 // commented out 16 and 15 bit output support, because the conversion
19 // routines are incorrrect. they assume the palette to be of the same
20 // depth as the output, which is incorrect. --Joey
22 static unsigned int bgr_list
[]={
29 static unsigned int rgb_list
[]={
37 static unsigned int gray_pal
[256];
39 static unsigned int find_best(struct vf_instance_s
* vf
, unsigned int fmt
){
43 if(fmt
==IMGFMT_BGR8
) p
=bgr_list
;
44 else if(fmt
==IMGFMT_RGB8
) p
=rgb_list
;
47 ret
=vf
->next
->query_format(vf
->next
,*p
);
48 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
49 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){ best
=*p
; break;} // no conversion -> bingo!
50 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
) best
=*p
; // best with conversion
56 //===========================================================================//
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
,outfmt
);
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 int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
80 // hope we'll get DR buffer:
81 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
82 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
87 if(!vf
->priv
->pal_msg
){
88 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] no palette given, assuming builtin grayscale one\n",vf
->info
->name
);
91 mpi
->planes
[1] = (unsigned char*)gray_pal
;
94 if(mpi
->w
==mpi
->stride
[0] && dmpi
->w
*(dmpi
->bpp
>>3)==dmpi
->stride
[0]){
95 // no stride conversion needed
96 switch(IMGFMT_RGB_DEPTH(dmpi
->imgfmt
)){
98 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
99 palette8tobgr15(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
101 palette8torgb15(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
104 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
105 palette8tobgr16(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
107 palette8torgb16(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
110 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
111 palette8tobgr24(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
113 palette8torgb24(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
116 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
117 palette8tobgr32(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
119 palette8torgb32(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
124 for(y
=0;y
<mpi
->h
;y
++){
125 unsigned char* src
=mpi
->planes
[0]+y
*mpi
->stride
[0];
126 unsigned char* dst
=dmpi
->planes
[0]+y
*dmpi
->stride
[0];
127 switch(IMGFMT_RGB_DEPTH(dmpi
->imgfmt
)){
129 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
130 palette8tobgr15(src
,dst
,mpi
->w
,mpi
->planes
[1]);
132 palette8torgb15(src
,dst
,mpi
->w
,mpi
->planes
[1]);
135 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
136 palette8tobgr16(src
,dst
,mpi
->w
,mpi
->planes
[1]);
138 palette8torgb16(src
,dst
,mpi
->w
,mpi
->planes
[1]);
141 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
142 palette8tobgr24(src
,dst
,mpi
->w
,mpi
->planes
[1]);
144 palette8torgb24(src
,dst
,mpi
->w
,mpi
->planes
[1]);
147 if (IMGFMT_IS_BGR(dmpi
->imgfmt
))
148 palette8tobgr32(src
,dst
,mpi
->w
,mpi
->planes
[1]);
150 palette8torgb32(src
,dst
,mpi
->w
,mpi
->planes
[1]);
156 return vf_next_put_image(vf
,dmpi
, pts
);
159 //===========================================================================//
161 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
162 int best
=find_best(vf
,fmt
);
163 if(!best
) return 0; // no match
164 return vf
->next
->query_format(vf
->next
,best
);
167 static void uninit(vf_instance_t
*vf
) {
171 static int open(vf_instance_t
*vf
, char* args
){
175 vf
->put_image
=put_image
;
176 vf
->query_format
=query_format
;
177 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
178 memset(vf
->priv
, 0, sizeof(struct vf_priv_s
));
179 for(i
=0;i
<256;i
++) gray_pal
[i
]=0x01010101*i
;
182 if (!strcasecmp(args
,"rgb15")) vf
->priv
->fmt
=IMGFMT_RGB15
; else
183 if (!strcasecmp(args
,"rgb16")) vf
->priv
->fmt
=IMGFMT_RGB16
; else
184 if (!strcasecmp(args
,"rgb24")) vf
->priv
->fmt
=IMGFMT_RGB24
; else
185 if (!strcasecmp(args
,"rgb32")) vf
->priv
->fmt
=IMGFMT_RGB32
; else
186 if (!strcasecmp(args
,"bgr15")) vf
->priv
->fmt
=IMGFMT_BGR15
; else
187 if (!strcasecmp(args
,"bgr16")) vf
->priv
->fmt
=IMGFMT_BGR16
; else
188 if (!strcasecmp(args
,"bgr24")) vf
->priv
->fmt
=IMGFMT_BGR24
; else
189 if (!strcasecmp(args
,"bgr32")) vf
->priv
->fmt
=IMGFMT_BGR32
; else
191 mp_msg(MSGT_VFILTER
, MSGL_WARN
, MSGTR_MPCODECS_UnknownFormatName
, args
);
198 const vf_info_t vf_info_palette
= {
199 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
207 //===========================================================================//