5774
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7 #include "../mp_msg.h"
|
|
8
|
|
9 #include "img_format.h"
|
|
10 #include "mp_image.h"
|
|
11 #include "vf.h"
|
|
12
|
|
13 #include "../postproc/rgb2rgb.h"
|
|
14
|
|
15 //===========================================================================//
|
|
16
|
|
17 static unsigned int bgr_list[]={
|
|
18 IMGFMT_BGR32,
|
|
19 IMGFMT_BGR24,
|
|
20 IMGFMT_BGR16,
|
|
21 IMGFMT_BGR15,
|
6188
|
22 0
|
5774
|
23 };
|
|
24 static unsigned int rgb_list[]={
|
|
25 IMGFMT_RGB32,
|
|
26 IMGFMT_RGB24,
|
|
27 IMGFMT_RGB16,
|
|
28 IMGFMT_RGB15,
|
6188
|
29 0
|
5774
|
30 };
|
|
31
|
6232
|
32 static unsigned int gray_pal[256];
|
|
33
|
5774
|
34 static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){
|
|
35 unsigned int best=0;
|
|
36 int ret;
|
|
37 unsigned int* p;
|
|
38 if(fmt==IMGFMT_BGR8) p=bgr_list;
|
|
39 else if(fmt==IMGFMT_RGB8) p=rgb_list;
|
|
40 else return 0;
|
|
41 while(*p){
|
|
42 ret=vf->next->query_format(vf->next,*p);
|
9276
|
43 mp_msg(MSGT_VFILTER,MSGL_DBG2,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3);
|
7160
|
44 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo!
|
|
45 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion
|
5774
|
46 ++p;
|
|
47 }
|
|
48 return best;
|
|
49 }
|
|
50
|
|
51 //===========================================================================//
|
|
52
|
|
53 struct vf_priv_s {
|
|
54 unsigned int fmt;
|
9276
|
55 int pal_msg;
|
5774
|
56 };
|
|
57
|
|
58 static int config(struct vf_instance_s* vf,
|
|
59 int width, int height, int d_width, int d_height,
|
|
60 unsigned int flags, unsigned int outfmt){
|
7160
|
61 if (!vf->priv->fmt)
|
|
62 vf->priv->fmt=find_best(vf,outfmt);
|
5774
|
63 if(!vf->priv->fmt){
|
|
64 // no matching fmt, so force one...
|
|
65 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32;
|
|
66 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32;
|
|
67 else return 0;
|
|
68 }
|
|
69 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt);
|
|
70 }
|
|
71
|
7368
|
72 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
5774
|
73 mp_image_t *dmpi;
|
6481
|
74
|
5774
|
75 // hope we'll get DR buffer:
|
|
76 dmpi=vf_get_image(vf->next,vf->priv->fmt,
|
|
77 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
|
78 mpi->w, mpi->h);
|
|
79
|
7160
|
80 if (!mpi->planes[1])
|
|
81 {
|
9276
|
82 if(!vf->priv->pal_msg){
|
|
83 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name);
|
|
84 vf->priv->pal_msg=1;
|
|
85 }
|
7160
|
86 mpi->planes[1] = (unsigned char*)gray_pal;
|
|
87 }
|
6232
|
88
|
5774
|
89 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){
|
|
90 // no stride conversion needed
|
|
91 switch(dmpi->imgfmt&255){
|
|
92 case 15:
|
7333
|
93 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
94 palette8tobgr15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
95 else
|
|
96 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
5774
|
97 break;
|
|
98 case 16:
|
7333
|
99 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
100 palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
101 else
|
|
102 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
5774
|
103 break;
|
|
104 case 24:
|
7333
|
105 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
106 palette8tobgr24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
107 else
|
|
108 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
5774
|
109 break;
|
|
110 case 32:
|
7333
|
111 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
112 palette8tobgr32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
|
113 else
|
|
114 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]);
|
5774
|
115 break;
|
|
116 }
|
|
117 } else {
|
|
118 int y;
|
|
119 for(y=0;y<mpi->h;y++){
|
|
120 unsigned char* src=mpi->planes[0]+y*mpi->stride[0];
|
|
121 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0];
|
|
122 switch(dmpi->imgfmt&255){
|
|
123 case 15:
|
7333
|
124 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
125 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]);
|
|
126 else
|
|
127 palette8torgb15(src,dst,mpi->w,mpi->planes[1]);
|
|
128 break;
|
5774
|
129 case 16:
|
7333
|
130 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
131 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]);
|
|
132 else
|
|
133 palette8torgb16(src,dst,mpi->w,mpi->planes[1]);
|
|
134 break;
|
5774
|
135 case 24:
|
7333
|
136 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
137 palette8tobgr24(src,dst,mpi->w,mpi->planes[1]);
|
|
138 else
|
|
139 palette8torgb24(src,dst,mpi->w,mpi->planes[1]);
|
|
140 break;
|
5774
|
141 case 32:
|
7333
|
142 if (dmpi->flags & MP_IMGFLAG_SWAPPED)
|
7160
|
143 palette8tobgr32(src,dst,mpi->w,mpi->planes[1]);
|
|
144 else
|
|
145 palette8torgb32(src,dst,mpi->w,mpi->planes[1]);
|
|
146 break;
|
5774
|
147 }
|
|
148 }
|
|
149 }
|
|
150
|
7368
|
151 return vf_next_put_image(vf,dmpi);
|
5774
|
152 }
|
|
153
|
|
154 //===========================================================================//
|
|
155
|
|
156 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|
157 int best=find_best(vf,fmt);
|
|
158 if(!best) return 0; // no match
|
|
159 return vf->next->query_format(vf->next,best);
|
|
160 }
|
|
161
|
|
162 static int open(vf_instance_t *vf, char* args){
|
6232
|
163 unsigned int i;
|
5774
|
164 vf->config=config;
|
|
165 vf->put_image=put_image;
|
|
166 vf->query_format=query_format;
|
|
167 vf->priv=malloc(sizeof(struct vf_priv_s));
|
7160
|
168 memset(vf->priv, 0, sizeof(struct vf_priv_s));
|
6232
|
169 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i;
|
7160
|
170 if (args)
|
|
171 {
|
|
172 if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else
|
|
173 if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else
|
|
174 if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else
|
|
175 if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else
|
|
176 if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else
|
|
177 if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else
|
|
178 if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else
|
|
179 if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else
|
|
180 {
|
|
181 printf("Unknown forced format name: '%s'\n", args);
|
|
182 return(0);
|
|
183 }
|
|
184 }
|
5774
|
185 return 1;
|
|
186 }
|
|
187
|
|
188 vf_info_t vf_info_palette = {
|
|
189 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion",
|
|
190 "palette",
|
7160
|
191 "A'rpi & Alex",
|
5774
|
192 "",
|
|
193 open
|
|
194 };
|
|
195
|
|
196 //===========================================================================//
|