Mercurial > mplayer.hg
annotate libmpcodecs/vf_palette.c @ 30918:be200e917ae1
Remove unused OPTFLAGS variable from config.mak.
author | diego |
---|---|
date | Thu, 25 Mar 2010 19:53:05 +0000 |
parents | 0aa7c9d45f92 |
children | 9f894134a0b3 |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30072
diff
changeset
|
18 |
5774 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 | |
17012 | 24 #include "config.h" |
25 #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
|
26 #include "help_mp.h" |
5774 | 27 |
28 #include "img_format.h" | |
29 #include "mp_image.h" | |
30 #include "vf.h" | |
31 | |
18861 | 32 #include "libswscale/rgb2rgb.h" |
5774 | 33 |
34 //===========================================================================// | |
35 | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
36 // 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
|
37 // 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
|
38 // 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
|
39 |
30662 | 40 static const unsigned int bgr_list[]={ |
5774 | 41 IMGFMT_BGR32, |
42 IMGFMT_BGR24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
43 // IMGFMT_BGR16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
44 // IMGFMT_BGR15, |
6188 | 45 0 |
5774 | 46 }; |
30662 | 47 static const unsigned int rgb_list[]={ |
5774 | 48 IMGFMT_RGB32, |
49 IMGFMT_RGB24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
50 // IMGFMT_RGB16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
51 // IMGFMT_RGB15, |
6188 | 52 0 |
5774 | 53 }; |
54 | |
6232 | 55 static unsigned int gray_pal[256]; |
56 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
57 static unsigned int find_best(struct vf_instance *vf, unsigned int fmt){ |
5774 | 58 unsigned int best=0; |
59 int ret; | |
30662 | 60 const unsigned int* p; |
5774 | 61 if(fmt==IMGFMT_BGR8) p=bgr_list; |
62 else if(fmt==IMGFMT_RGB8) p=rgb_list; | |
63 else return 0; | |
64 while(*p){ | |
65 ret=vf->next->query_format(vf->next,*p); | |
9276 | 66 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
|
67 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
|
68 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
5774 | 69 ++p; |
70 } | |
71 return best; | |
72 } | |
73 | |
74 //===========================================================================// | |
75 | |
76 struct vf_priv_s { | |
77 unsigned int fmt; | |
9276 | 78 int pal_msg; |
5774 | 79 }; |
80 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
81 static int config(struct vf_instance *vf, |
5774 | 82 int width, int height, int d_width, int d_height, |
83 unsigned int flags, unsigned int outfmt){ | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
84 if (!vf->priv->fmt) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
85 vf->priv->fmt=find_best(vf,outfmt); |
5774 | 86 if(!vf->priv->fmt){ |
87 // no matching fmt, so force one... | |
88 if(outfmt==IMGFMT_RGB8) vf->priv->fmt=IMGFMT_RGB32; | |
89 else if(outfmt==IMGFMT_BGR8) vf->priv->fmt=IMGFMT_BGR32; | |
90 else return 0; | |
91 } | |
92 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); | |
93 } | |
94 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
95 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
5774 | 96 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
|
97 uint8_t *old_palette = mpi->planes[1]; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27788
diff
changeset
|
98 |
5774 | 99 // hope we'll get DR buffer: |
100 dmpi=vf_get_image(vf->next,vf->priv->fmt, | |
101 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, | |
102 mpi->w, mpi->h); | |
103 | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
104 if (!mpi->planes[1]) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
105 { |
9276 | 106 if(!vf->priv->pal_msg){ |
107 mp_msg(MSGT_VFILTER,MSGL_V,"[%s] no palette given, assuming builtin grayscale one\n",vf->info->name); | |
108 vf->priv->pal_msg=1; | |
109 } | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
110 mpi->planes[1] = (unsigned char*)gray_pal; |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
111 } |
6232 | 112 |
5774 | 113 if(mpi->w==mpi->stride[0] && dmpi->w*(dmpi->bpp>>3)==dmpi->stride[0]){ |
114 // no stride conversion needed | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
115 switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ |
5774 | 116 case 15: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
117 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
118 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
|
119 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
120 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 121 break; |
122 case 16: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
123 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
124 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
|
125 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
126 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 127 break; |
128 case 24: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
129 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
130 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
|
131 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
132 palette8topacked24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 133 break; |
134 case 32: | |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
135 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
136 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
|
137 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
138 palette8topacked32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 139 break; |
140 } | |
141 } else { | |
142 int y; | |
143 for(y=0;y<mpi->h;y++){ | |
144 unsigned char* src=mpi->planes[0]+y*mpi->stride[0]; | |
145 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
|
146 switch(IMGFMT_RGB_DEPTH(dmpi->imgfmt)){ |
5774 | 147 case 15: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
148 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
149 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
150 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
151 palette8torgb15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
152 break; |
5774 | 153 case 16: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
154 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
155 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
156 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
157 palette8torgb16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
158 break; |
5774 | 159 case 24: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
160 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
161 palette8topacked24(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
162 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
163 palette8topacked24(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
164 break; |
5774 | 165 case 32: |
24431
3cfff0f1d9b8
Deobfuscate: use IMGFMT_RGB_DEPTH and IMGFMT_IS_BGR
reimar
parents:
18861
diff
changeset
|
166 if (IMGFMT_IS_BGR(dmpi->imgfmt)) |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
167 palette8topacked32(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
168 else |
27788
0f190fe6aeb4
vf_palette: Fix compilation after libswscale API changes
uau
parents:
26754
diff
changeset
|
169 palette8topacked32(src,dst,mpi->w,mpi->planes[1]); |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
170 break; |
5774 | 171 } |
172 } | |
173 } | |
30072
e86cf531b110
Restore the old value of planes[1] in vf_palette at the end to ensure
reimar
parents:
29263
diff
changeset
|
174 mpi->planes[1] = old_palette; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
27788
diff
changeset
|
175 |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
176 return vf_next_put_image(vf,dmpi, pts); |
5774 | 177 } |
178 | |
179 //===========================================================================// | |
180 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
181 static int query_format(struct vf_instance *vf, unsigned int fmt){ |
5774 | 182 int best=find_best(vf,fmt); |
183 if(!best) return 0; // no match | |
184 return vf->next->query_format(vf->next,best); | |
185 } | |
186 | |
13641 | 187 static void uninit(vf_instance_t *vf) { |
188 free(vf->priv); | |
189 } | |
190 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
191 static int vf_open(vf_instance_t *vf, char *args){ |
6232 | 192 unsigned int i; |
5774 | 193 vf->config=config; |
13641 | 194 vf->uninit=uninit; |
5774 | 195 vf->put_image=put_image; |
196 vf->query_format=query_format; | |
197 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
198 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
6232 | 199 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
|
200 if (args) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
201 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 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
|
209 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
|
210 { |
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
|
211 mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_UnknownFormatName, args); |
26754
63630c09e237
cosmetics: Remove pointless parentheses from return calls.
diego
parents:
25221
diff
changeset
|
212 return 0; |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
213 } |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
214 } |
5774 | 215 return 1; |
216 } | |
217 | |
25221 | 218 const vf_info_t vf_info_palette = { |
5774 | 219 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", |
220 "palette", | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
221 "A'rpi & Alex", |
5774 | 222 "", |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
223 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9276
diff
changeset
|
224 NULL |
5774 | 225 }; |
226 | |
227 //===========================================================================// |