Mercurial > mplayer.hg
annotate libmpcodecs/vf_palette.c @ 17892:2a37ab5a913e
1.226: Print the mute state on the OSD.
1.225: Fix up libaf unknown-format printing
1.224: last print on libaf to af_msg
1.223: [done by diego]
1.222: dwStart support for mencoder
author | kraymer |
---|---|
date | Sat, 18 Mar 2006 19:22:13 +0000 |
parents | 6ff3379a0862 |
children | 20aca9baf5d8 |
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" | |
5774 | 8 |
9 #include "img_format.h" | |
10 #include "mp_image.h" | |
11 #include "vf.h" | |
12 | |
17012 | 13 #include "postproc/rgb2rgb.h" |
5774 | 14 |
15 //===========================================================================// | |
16 | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
17 // 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
|
18 // 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
|
19 // 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
|
20 |
5774 | 21 static unsigned int bgr_list[]={ |
22 IMGFMT_BGR32, | |
23 IMGFMT_BGR24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
24 // IMGFMT_BGR16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
25 // IMGFMT_BGR15, |
6188 | 26 0 |
5774 | 27 }; |
28 static unsigned int rgb_list[]={ | |
29 IMGFMT_RGB32, | |
30 IMGFMT_RGB24, | |
11512
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
31 // IMGFMT_RGB16, |
4ff38d168c2f
fix for vf_palette, because paletted 8-bit to BGR{15,16} conversion is incorrect.
joey
parents:
9593
diff
changeset
|
32 // IMGFMT_RGB15, |
6188 | 33 0 |
5774 | 34 }; |
35 | |
6232 | 36 static unsigned int gray_pal[256]; |
37 | |
5774 | 38 static unsigned int find_best(struct vf_instance_s* vf, unsigned int fmt){ |
39 unsigned int best=0; | |
40 int ret; | |
41 unsigned int* p; | |
42 if(fmt==IMGFMT_BGR8) p=bgr_list; | |
43 else if(fmt==IMGFMT_RGB8) p=rgb_list; | |
44 else return 0; | |
45 while(*p){ | |
46 ret=vf->next->query_format(vf->next,*p); | |
9276 | 47 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
|
48 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
|
49 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
5774 | 50 ++p; |
51 } | |
52 return best; | |
53 } | |
54 | |
55 //===========================================================================// | |
56 | |
57 struct vf_priv_s { | |
58 unsigned int fmt; | |
9276 | 59 int pal_msg; |
5774 | 60 }; |
61 | |
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){ | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
65 if (!vf->priv->fmt) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
66 vf->priv->fmt=find_best(vf,outfmt); |
5774 | 67 if(!vf->priv->fmt){ |
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; | |
71 else return 0; | |
72 } | |
73 return vf_next_config(vf,width,height,d_width,d_height,flags,vf->priv->fmt); | |
74 } | |
75 | |
7368 | 76 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
5774 | 77 mp_image_t *dmpi; |
6481 | 78 |
5774 | 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, | |
82 mpi->w, mpi->h); | |
83 | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
84 if (!mpi->planes[1]) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
85 { |
9276 | 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); | |
88 vf->priv->pal_msg=1; | |
89 } | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
90 mpi->planes[1] = (unsigned char*)gray_pal; |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
91 } |
6232 | 92 |
5774 | 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){ | |
96 case 15: | |
7333 | 97 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
98 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
|
99 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
100 palette8torgb15(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 101 break; |
102 case 16: | |
7333 | 103 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
104 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
|
105 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
106 palette8torgb16(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 107 break; |
108 case 24: | |
7333 | 109 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
110 palette8tobgr24(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
|
111 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
112 palette8torgb24(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 113 break; |
114 case 32: | |
7333 | 115 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
116 palette8tobgr32(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
|
117 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
118 palette8torgb32(mpi->planes[0],dmpi->planes[0],mpi->h*mpi->w,mpi->planes[1]); |
5774 | 119 break; |
120 } | |
121 } else { | |
122 int y; | |
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){ | |
127 case 15: | |
7333 | 128 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
129 palette8tobgr15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
130 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
131 palette8torgb15(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
132 break; |
5774 | 133 case 16: |
7333 | 134 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
135 palette8tobgr16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
136 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
137 palette8torgb16(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
138 break; |
5774 | 139 case 24: |
7333 | 140 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
141 palette8tobgr24(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
142 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
143 palette8torgb24(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
144 break; |
5774 | 145 case 32: |
7333 | 146 if (dmpi->flags & MP_IMGFLAG_SWAPPED) |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
147 palette8tobgr32(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
148 else |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
149 palette8torgb32(src,dst,mpi->w,mpi->planes[1]); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
150 break; |
5774 | 151 } |
152 } | |
153 } | |
154 | |
7368 | 155 return vf_next_put_image(vf,dmpi); |
5774 | 156 } |
157 | |
158 //===========================================================================// | |
159 | |
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); | |
164 } | |
165 | |
13641 | 166 static void uninit(vf_instance_t *vf) { |
167 free(vf->priv); | |
168 } | |
169 | |
5774 | 170 static int open(vf_instance_t *vf, char* args){ |
6232 | 171 unsigned int i; |
5774 | 172 vf->config=config; |
13641 | 173 vf->uninit=uninit; |
5774 | 174 vf->put_image=put_image; |
175 vf->query_format=query_format; | |
176 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
177 memset(vf->priv, 0, sizeof(struct vf_priv_s)); |
6232 | 178 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
|
179 if (args) |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
180 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
181 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
|
182 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
|
183 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
|
184 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
|
185 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
|
186 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
|
187 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
|
188 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
|
189 { |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
190 printf("Unknown forced format name: '%s'\n", args); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
191 return(0); |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
192 } |
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
193 } |
5774 | 194 return 1; |
195 } | |
196 | |
197 vf_info_t vf_info_palette = { | |
198 "8bpp indexed (using palette) -> BGR 15/16/24/32 conversion", | |
199 "palette", | |
7160
447066802e64
added bgr support and support for forcing output format
alex
parents:
7127
diff
changeset
|
200 "A'rpi & Alex", |
5774 | 201 "", |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9276
diff
changeset
|
202 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
9276
diff
changeset
|
203 NULL |
5774 | 204 }; |
205 | |
206 //===========================================================================// |