Mercurial > mplayer.hg
annotate libmpcodecs/vf_palette.c @ 30336:33e5899ad14d
Split overly long line.
author | stefano |
---|---|
date | Tue, 19 Jan 2010 22:36:46 +0000 |
parents | e86cf531b110 |
children | bbb6ebec87a0 |
rev | line source |
---|---|
5774 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
17012 | 6 #include "config.h" |
7 #include "mp_msg.h" | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17906
diff
changeset
|
8 #include "help_mp.h" |
5774 | 9 |
10 #include "img_format.h" | |
11 #include "mp_image.h" | |
12 #include "vf.h" | |
13 | |
18861 | 14 #include "libswscale/rgb2rgb.h" |
5774 | 15 |
16 //===========================================================================// | |
17 | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
18 // commented out 16 and 15 bit output support, because the conversion |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
19 // routines are incorrrect. they assume the palette to be of the same |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
20 // depth as the output, which is incorrect. --Joey |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
21 |
5774 | 22 static unsigned int bgr_list[]={ |
23 IMGFMT_BGR32, | |
24 IMGFMT_BGR24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
25 // IMGFMT_BGR16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
26 // IMGFMT_BGR15, |
6188 | 27 0 |
5774 | 28 }; |
29 static unsigned int rgb_list[]={ | |
30 IMGFMT_RGB32, | |
31 IMGFMT_RGB24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
32 // IMGFMT_RGB16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
33 // IMGFMT_RGB15, |
6188 | 34 0 |
5774 | 35 }; |
36 | |
6232 | 37 static unsigned int gray_pal[256]; |
38 | |
5774 | 39 static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){ |
40 unsigned int best=0; | |
41 int ret; | |
42 unsigned int* p; | |
43 if(fmt==IMGFMT_BGR8) p=bgr_list; | |
44 else if(fmt==IMGFMT_RGB8) p=rgb_list; | |
45 else return 0; | |
46 while(*p){ | |
47 ret=vf->next->query_format(vf->next,*p); | |
9276 | 48 mp_msg(MSGT_VFILTER,MSGL_DBG2,"[%s] query(%s) -> %d\n",vf->info->name,vo_format_name(*p),ret&3); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
49 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo! |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
50 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
5774 | 51 ++p; |
52 } | |
53 return best; | |
54 } | |
55 | |
56 //===========================================================================// | |
57 | |
58 struct vf_priv_s { | |
59 unsigned int fmt; | |
9276 | 60 int pal_msg; |
5774 | 61 }; |
62 | |
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){ | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
66 if (!vf->priv->fmt) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
67 vf->priv->fmt=find_best(vf,outfmt); |
5774 | 68 if(!vf->priv->fmt){ |
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; | |
72 else return 0; | |
73 } | |
74 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); | |
75 } | |
76 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
77 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
5774 | 78 mp_image_t *dmpi; |
30072
e86cf531b110
Restore the old value of planes[1] in vf_palette at the end to ensure
reimar
parents:
29263
diff
changeset
|
79 uint8_t *old_palette = mpi->planes[1]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27788
diff
changeset
|
80 |
5774 | 81 // hope we'll get DR buffer: |
82 dmpi=vf_get_image(vf->next,vf->priv->fmt, | |
83 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
84 mpi->w, mpi->h); | |
85 | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
86 if (!mpi->planes[1]) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
87 { |
9276 | 88 if(!vf->priv->pal_msg){ |
89 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name); | |
90 vf->priv->pal_msg=1; | |
91 } | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
92 mpi->planes[1] = (unsigned char*)gray_pal; |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
93 } |
6232 | 94 |
5774 | 95 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ |
96 // no stride conversion needed | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
97 switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ |
5774 | 98 case 15: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
99 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
100 palette8tobgr15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
101 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
102 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 103 break; |
104 case 16: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
105 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
106 palette8tobgr16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
107 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
108 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 109 break; |
110 case 24: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
111 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
112 palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
113 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
114 palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 115 break; |
116 case 32: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
117 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
118 palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
119 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
120 palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 121 break; |
122 } | |
123 } else { | |
124 int y; | |
125 for(y=0;y<mpi->h;y++){ | |
126 unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; | |
127 unsigned char* dst=dmpi->planes[0]+y*dmpi->stride[0]; | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
128 switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ |
5774 | 129 case 15: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
130 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
131 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
132 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
133 palette8torgb15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
134 break; |
5774 | 135 case 16: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
136 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
137 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
138 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
139 palette8torgb16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
140 break; |
5774 | 141 case 24: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
142 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
143 palette8topacked24(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
144 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
145 palette8topacked24(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
146 break; |
5774 | 147 case 32: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
148 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
149 palette8topacked32(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
150 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
151 palette8topacked32(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
152 break; |
5774 | 153 } |
154 } | |
155 } | |
30072
e86cf531b110
Restore the old value of planes[1] in vf_palette at the end to ensure
reimar
parents:
29263
diff
changeset
|
156 mpi->planes[1] = old_palette; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27788
diff
changeset
|
157 |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
158 return vf_next_put_image(vf,dmpi, pts); |
5774 | 159 } |
160 | |
161 //===========================================================================// | |
162 | |
163 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
164 int best=find_best(vf,fmt); | |
165 if(!best) return 0; // no match | |
166 return vf->next->query_format(vf->next,best); | |
167 } | |
168 | |
13641 | 169 static void uninit(vf_instance_t *vf) { |
170 free(vf->priv); | |
171 } | |
172 | |
5774 | 173 static int open(vf_instance_t *vf, char* args){ |
6232 | 174 unsigned int i; |
5774 | 175 vf->config=config; |
13641 | 176 vf->uninit=uninit; |
5774 | 177 vf->put_image=put_image; |
178 vf->query_format=query_format; | |
179 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
180 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
6232 | 181 for(i=0;i<256;i++) gray_pal[i]=0x01010101*i; |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
182 if (args) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
183 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
184 if (!strcasecmp(args,"rgb15")) vf->priv->fmt=IMGFMT_RGB15; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
185 if (!strcasecmp(args,"rgb16")) vf->priv->fmt=IMGFMT_RGB16; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
186 if (!strcasecmp(args,"rgb24")) vf->priv->fmt=IMGFMT_RGB24; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
187 if (!strcasecmp(args,"rgb32")) vf->priv->fmt=IMGFMT_RGB32; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
188 if (!strcasecmp(args,"bgr15")) vf->priv->fmt=IMGFMT_BGR15; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
189 if (!strcasecmp(args,"bgr16")) vf->priv->fmt=IMGFMT_BGR16; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
190 if (!strcasecmp(args,"bgr24")) vf->priv->fmt=IMGFMT_BGR24; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
191 if (!strcasecmp(args,"bgr32")) vf->priv->fmt=IMGFMT_BGR32; else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
192 { |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17906
diff
changeset
|
193 mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_UnknownFormatName, args); |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
25221
diff
changeset
|
194 return 0; |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
195 } |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
196 } |
5774 | 197 return 1; |
198 } | |
199 | |
25221 | 200 const vf_info_t vf_info_palette = { |
5774 | 201 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", |
202 "palette", | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
203 "A'rpi & Alex", |
5774 | 204 "", |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9276
diff
changeset
|
205 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9276
diff
changeset
|
206 NULL |
5774 | 207 }; |
208 | |
209 //===========================================================================// |