9 #include "img_format.h"
13 #include "../postproc/rgb2rgb.h"
15 //===========================================================================//
17 // commented out 16 and 15 bit output support, because the conversion
18 // routines are incorrrect. they assume the palette to be of the same
19 // depth as the output, which is incorrect. --Joey
21 static unsigned int bgr_list
[]={
28 static unsigned int rgb_list
[]={
36 static unsigned int gray_pal
[256];
38 static unsigned int find_best(struct vf_instance_s
* vf
, unsigned int fmt
){
42 if(fmt
==IMGFMT_BGR8
) p
=bgr_list
;
43 else if(fmt
==IMGFMT_RGB8
) p
=rgb_list
;
46 ret
=vf
->next
->query_format(vf
->next
,*p
);
47 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"[%s] query(%s) -> %d\n",vf
->info
->name
,vo_format_name(*p
),ret
&3);
48 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){ best
=*p
; break;} // no conversion -> bingo!
49 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
) best
=*p
; // best with conversion
55 //===========================================================================//
62 static int config(struct vf_instance_s
* vf
,
63 int width
, int height
, int d_width
, int d_height
,
64 unsigned int flags
, unsigned int outfmt
){
66 vf
->priv
->fmt
=find_best(vf
,outfmt
);
68 // no matching fmt, so force one...
69 if(outfmt
==IMGFMT_RGB8
) vf
->priv
->fmt
=IMGFMT_RGB32
;
70 else if(outfmt
==IMGFMT_BGR8
) vf
->priv
->fmt
=IMGFMT_BGR32
;
73 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,vf
->priv
->fmt
);
76 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
){
79 // hope we'll get DR buffer:
80 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
81 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
,
86 if(!vf
->priv
->pal_msg
){
87 mp_msg(MSGT_VFILTER
,MSGL_V
,"[%s] no palette given, assuming builtin grayscale one\n",vf
->info
->name
);
90 mpi
->planes
[1] = (unsigned char*)gray_pal
;
93 if(mpi
->w
==mpi
->stride
[0] && dmpi
->w
*(dmpi
->bpp
>>3)==dmpi
->stride
[0]){
94 // no stride conversion needed
95 switch(dmpi
->imgfmt
&255){
97 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
98 palette8tobgr15(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
100 palette8torgb15(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
103 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
104 palette8tobgr16(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
106 palette8torgb16(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
109 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
110 palette8tobgr24(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
112 palette8torgb24(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
115 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
116 palette8tobgr32(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
118 palette8torgb32(mpi
->planes
[0],dmpi
->planes
[0],mpi
->h
*mpi
->w
,mpi
->planes
[1]);
123 for(y
=0;y
<mpi
->h
;y
++){
124 unsigned char* src
=mpi
->planes
[0]+y
*mpi
->stride
[0];
125 unsigned char* dst
=dmpi
->planes
[0]+y
*dmpi
->stride
[0];
126 switch(dmpi
->imgfmt
&255){
128 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
129 palette8tobgr15(src
,dst
,mpi
->w
,mpi
->planes
[1]);
131 palette8torgb15(src
,dst
,mpi
->w
,mpi
->planes
[1]);
134 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
135 palette8tobgr16(src
,dst
,mpi
->w
,mpi
->planes
[1]);
137 palette8torgb16(src
,dst
,mpi
->w
,mpi
->planes
[1]);
140 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
141 palette8tobgr24(src
,dst
,mpi
->w
,mpi
->planes
[1]);
143 palette8torgb24(src
,dst
,mpi
->w
,mpi
->planes
[1]);
146 if (dmpi
->flags
& MP_IMGFLAG_SWAPPED
)
147 palette8tobgr32(src
,dst
,mpi
->w
,mpi
->planes
[1]);
149 palette8torgb32(src
,dst
,mpi
->w
,mpi
->planes
[1]);
155 return vf_next_put_image(vf
,dmpi
);
158 //===========================================================================//
160 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
){
161 int best
=find_best(vf
,fmt
);
162 if(!best
) return 0; // no match
163 return vf
->next
->query_format(vf
->next
,best
);
166 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
));
173 for(i
=0;i
<256;i
++) gray_pal
[i
]=0x01010101*i
;
176 if (!strcasecmp(args
,"rgb15")) vf
->priv
->fmt
=IMGFMT_RGB15
; else
177 if (!strcasecmp(args
,"rgb16")) vf
->priv
->fmt
=IMGFMT_RGB16
; else
178 if (!strcasecmp(args
,"rgb24")) vf
->priv
->fmt
=IMGFMT_RGB24
; else
179 if (!strcasecmp(args
,"rgb32")) vf
->priv
->fmt
=IMGFMT_RGB32
; else
180 if (!strcasecmp(args
,"bgr15")) vf
->priv
->fmt
=IMGFMT_BGR15
; else
181 if (!strcasecmp(args
,"bgr16")) vf
->priv
->fmt
=IMGFMT_BGR16
; else
182 if (!strcasecmp(args
,"bgr24")) vf
->priv
->fmt
=IMGFMT_BGR24
; else
183 if (!strcasecmp(args
,"bgr32")) vf
->priv
->fmt
=IMGFMT_BGR32
; else
185 printf("Unknown forced format name: '%s'\n", args
);
192 vf_info_t vf_info_palette
= {
193 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
201 //===========================================================================//