Mercurial > mplayer.hg
annotate libmpcodecs/vf_scale.c @ 9547:3b3b7b6fdb22
merging fourcc with codec_tag
author | michael |
---|---|
date | Sat, 08 Mar 2003 02:05:14 +0000 |
parents | 543ab3909b78 |
children | e9a2af584986 |
rev | line source |
---|---|
5522 | 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 | |
5607 | 9 #include "img_format.h" |
10 #include "mp_image.h" | |
5522 | 11 #include "vf.h" |
12 | |
13 #include "../libvo/fastmemcpy.h" | |
14 #include "../postproc/swscale.h" | |
15 | |
16 struct vf_priv_s { | |
17 int w,h; | |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
18 int v_chr_drop; |
6637 | 19 int param; |
5523 | 20 unsigned int fmt; |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
21 struct SwsContext *ctx; |
7783 | 22 unsigned char* palette; |
9491 | 23 mp_image_t *dmpi; |
5522 | 24 }; |
25 | |
6060 | 26 extern int opt_screen_size_x; |
27 extern int opt_screen_size_y; | |
28 | |
5522 | 29 //===========================================================================// |
30 | |
5523 | 31 static unsigned int outfmt_list[]={ |
7403 | 32 // RGB: |
5523 | 33 IMGFMT_BGR32, |
7403 | 34 IMGFMT_RGB32, |
5523 | 35 IMGFMT_BGR24, |
7403 | 36 IMGFMT_RGB24, |
5523 | 37 IMGFMT_BGR16, |
7403 | 38 IMGFMT_RGB16, |
5523 | 39 IMGFMT_BGR15, |
7403 | 40 IMGFMT_RGB15, |
6637 | 41 IMGFMT_BGR8, |
7403 | 42 IMGFMT_RGB8, |
6637 | 43 IMGFMT_BGR4, |
7403 | 44 IMGFMT_RGB4, |
9171 | 45 IMGFMT_BG4B, |
46 IMGFMT_RG4B, | |
6637 | 47 IMGFMT_BGR1, |
48 IMGFMT_RGB1, | |
7403 | 49 // YUV: |
50 IMGFMT_444P, | |
51 IMGFMT_422P, | |
5523 | 52 IMGFMT_YV12, |
53 IMGFMT_I420, | |
54 IMGFMT_IYUV, | |
6533 | 55 IMGFMT_YVU9, |
6536 | 56 IMGFMT_IF09, |
6863 | 57 IMGFMT_411P, |
7403 | 58 IMGFMT_Y800, |
59 IMGFMT_Y8, | |
7720 | 60 IMGFMT_YUY2, |
6188 | 61 0 |
5523 | 62 }; |
63 | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
64 static unsigned int find_best_out(vf_instance_t *vf){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
65 unsigned int best=0; |
5523 | 66 unsigned int* p=outfmt_list; |
67 // find the best outfmt: | |
68 while(*p){ | |
69 int ret=vf_next_query_format(vf,*p); | |
9276 | 70 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(*p),ret&3); |
6708
8058078f1248
support for external pp by divx4. some fixes/cosmetics?
alex
parents:
6637
diff
changeset
|
71 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){ best=*p; break;} // no conversion -> bingo! |
8058078f1248
support for external pp by divx4. some fixes/cosmetics?
alex
parents:
6637
diff
changeset
|
72 if(ret&VFCAP_CSP_SUPPORTED && !best) best=*p; // best with conversion |
5523 | 73 ++p; |
74 } | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
75 return best; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
76 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
77 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
78 static int config(struct vf_instance_s* vf, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
79 int width, int height, int d_width, int d_height, |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
80 unsigned int flags, unsigned int outfmt){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
81 unsigned int best=find_best_out(vf); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
82 int vo_flags; |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
83 int int_sws_flags=0; |
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
84 SwsFilter *srcFilter, *dstFilter; |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
85 |
5523 | 86 if(!best){ |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
6126
diff
changeset
|
87 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n"); |
5523 | 88 return 0; |
89 } | |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
90 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
91 vo_flags=vf->next->query_format(vf->next,best); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
92 |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
93 // scaling to dwidth*d_height, if all these TRUE: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
94 // - option -zoom |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
95 // - no other sw/hw up/down scaling avail. |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
96 // - we're after postproc |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
97 // - user didn't set w:h |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
98 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) && |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
99 vf->priv->w<0 && vf->priv->h<0){ // -zoom |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
100 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
101 if(d_width<width || d_height<height){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
102 // downscale! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
103 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
104 } else { |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
105 // upscale: |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
106 if(vo_flags&VFCAP_HWSCALE_UP) x=0; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
107 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
108 if(x){ |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
109 // user wants sw scaling! (-zoom) |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
110 vf->priv->w=d_width; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
111 vf->priv->h=d_height; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
112 } |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
113 } |
5523 | 114 |
5522 | 115 // calculate the missing parameters: |
6746
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
116 switch(best) { |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
117 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */ |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
118 if(vf->priv->w==-3) vf->priv->w=(vf->priv->h*width/height+1)&~1; else |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
119 if(vf->priv->w==-2) vf->priv->w=(vf->priv->h*d_width/d_height+1)&~1; |
6750
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
120 if(vf->priv->w<0) vf->priv->w=width; else |
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
121 if(vf->priv->w==0) vf->priv->w=d_width; |
6746
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
122 if(vf->priv->h==-3) vf->priv->h=vf->priv->w*height/width; else |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
123 if(vf->priv->h==-2) vf->priv->h=vf->priv->w*d_height/d_width; |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
124 break; |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
125 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */ |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
126 if(vf->priv->w==-3) vf->priv->w=(vf->priv->h*width/height+1)&~1; else |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
127 if(vf->priv->w==-2) vf->priv->w=(vf->priv->h*d_width/d_height+1)&~1; |
6750
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
128 if(vf->priv->w<0) vf->priv->w=width; else |
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
129 if(vf->priv->w==0) vf->priv->w=d_width; |
6746
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
130 if(vf->priv->h==-3) vf->priv->h=(vf->priv->w*height/width+1)&~1; else |
7044
c9ee9c799f4a
typo fix, patch by (Eric Lammerts <eric at lammerts dot org>)
michael
parents:
6876
diff
changeset
|
131 if(vf->priv->h==-2) vf->priv->h=(vf->priv->w*d_height/d_width+1)&~1; |
6746
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
132 break; |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
133 default: |
6126
35eb2b9c7d9c
new special w/h values: -2 and -3. based on proposal by Bohdan Horst <nexus@hoth.amu.edu.pl>
arpi
parents:
6060
diff
changeset
|
134 if(vf->priv->w==-3) vf->priv->w=vf->priv->h*width/height; else |
35eb2b9c7d9c
new special w/h values: -2 and -3. based on proposal by Bohdan Horst <nexus@hoth.amu.edu.pl>
arpi
parents:
6060
diff
changeset
|
135 if(vf->priv->w==-2) vf->priv->w=vf->priv->h*d_width/d_height; |
6750
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
136 if(vf->priv->w<0) vf->priv->w=width; else |
6484f8f9f111
Put back the ordering of the if as requested by Arpi.
kmkaplan
parents:
6746
diff
changeset
|
137 if(vf->priv->w==0) vf->priv->w=d_width; |
6746
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
138 if(vf->priv->h==-3) vf->priv->h=vf->priv->w*height/width; else |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
139 if(vf->priv->h==-2) vf->priv->h=vf->priv->w*d_height/d_width; |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
140 break; |
0e2b14e606ac
Round height or width to valid values when doing automatic calculation.
kmkaplan
parents:
6708
diff
changeset
|
141 } |
6126
35eb2b9c7d9c
new special w/h values: -2 and -3. based on proposal by Bohdan Horst <nexus@hoth.amu.edu.pl>
arpi
parents:
6060
diff
changeset
|
142 |
6003 | 143 if(vf->priv->h<0) vf->priv->h=height; else |
144 if(vf->priv->h==0) vf->priv->h=d_height; | |
5523 | 145 |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
6126
diff
changeset
|
146 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n", |
5523 | 147 width,height,vo_format_name(outfmt), |
148 vf->priv->w,vf->priv->h,vo_format_name(best)); | |
5526 | 149 |
150 // free old ctx: | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
151 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx); |
5523 | 152 |
5522 | 153 // new swscaler: |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
154 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter); |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
155 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT; |
6637 | 156 int_sws_flags|= vf->priv->param << SWS_PARAM_SHIFT; |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
157 vf->priv->ctx=sws_getContext(width,height, |
5712 | 158 (outfmt==IMGFMT_I420 || outfmt==IMGFMT_IYUV)?IMGFMT_YV12:outfmt, |
159 vf->priv->w,vf->priv->h, | |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
160 (best==IMGFMT_I420 || best==IMGFMT_IYUV)?IMGFMT_YV12:best, |
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
161 int_sws_flags, srcFilter, dstFilter); |
5522 | 162 if(!vf->priv->ctx){ |
163 // error... | |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
6126
diff
changeset
|
164 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n"); |
5522 | 165 return 0; |
166 } | |
5523 | 167 vf->priv->fmt=best; |
6060 | 168 |
7783 | 169 if(vf->priv->palette){ |
170 free(vf->priv->palette); | |
171 vf->priv->palette=NULL; | |
172 } | |
173 switch(best){ | |
174 case IMGFMT_BGR8: { | |
175 /* set 332 palette for 8 bpp */ | |
176 int i; | |
177 vf->priv->palette=malloc(4*256); | |
178 for(i=0; i<256; i++){ | |
179 vf->priv->palette[4*i+0]=4*(i&3)*21; | |
180 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9; | |
181 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9; | |
182 } | |
183 break; } | |
9171 | 184 case IMGFMT_BGR4: |
185 case IMGFMT_BG4B: { | |
7783 | 186 int i; |
187 vf->priv->palette=malloc(4*16); | |
188 for(i=0; i<16; i++){ | |
189 vf->priv->palette[4*i+0]=4*(i&1)*63; | |
190 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21; | |
191 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63; | |
192 } | |
193 break; } | |
194 } | |
195 | |
6060 | 196 if(!opt_screen_size_x && !opt_screen_size_y){ |
197 d_width=d_width*vf->priv->w/width; | |
198 d_height=d_height*vf->priv->h/height; | |
199 } | |
5525 | 200 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best); |
5522 | 201 } |
202 | |
9491 | 203 static void start_slice(struct vf_instance_s* vf, mp_image_t *mpi){ |
204 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK); | |
205 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen | |
206 // they want slices!!! allocate the buffer. | |
207 mpi->priv=vf->priv->dmpi=vf_get_image(vf->next,vf->priv->fmt, | |
208 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK), | |
209 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
210 vf->priv->w, vf->priv->h); | |
211 } | |
212 | |
213 static void draw_slice(struct vf_instance_s* vf, | |
214 unsigned char** src, int* stride, int w,int h, int x, int y){ | |
215 mp_image_t *dmpi=vf->priv->dmpi; | |
216 if(!dmpi){ | |
217 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image??)\n"); | |
218 return; | |
219 } | |
220 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h); | |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
221 sws_scale(vf->priv->ctx,src,stride,y,h,dmpi->planes,dmpi->stride); |
9491 | 222 } |
223 | |
7368 | 224 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
9491 | 225 mp_image_t *dmpi=mpi->priv; |
5522 | 226 |
9491 | 227 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n", |
228 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)); | |
229 | |
230 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){ | |
231 | |
5522 | 232 // hope we'll get DR buffer: |
5523 | 233 dmpi=vf_get_image(vf->next,vf->priv->fmt, |
6876 | 234 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, |
5522 | 235 vf->priv->w, vf->priv->h); |
9494
543ab3909b78
sws_ prefix, more seperation between internal & external swscaler API
michael
parents:
9491
diff
changeset
|
236 sws_scale(vf->priv->ctx,mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride); |
7720 | 237 |
9491 | 238 } |
239 | |
5527 | 240 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){ |
241 // just conversion, no scaling -> keep postprocessing data | |
242 // this way we can apply pp filter to non-yv12 source using scaler | |
243 dmpi->qscale=mpi->qscale; | |
244 dmpi->qstride=mpi->qstride; | |
245 } | |
7783 | 246 |
247 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette! | |
5527 | 248 |
7368 | 249 return vf_next_put_image(vf,dmpi); |
5522 | 250 } |
251 | |
9476
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
252 static int control(struct vf_instance_s* vf, int request, void* data){ |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
253 int *table; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
254 int *inv_table; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
255 int r; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
256 int brightness, contrast, saturation, srcRange, dstRange; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
257 vf_equalizer_t *eq; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
258 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
259 switch(request){ |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
260 case VFCTRL_GET_EQUALIZER: |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
261 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation); |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
262 if(r<0) break; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
263 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
264 eq = data; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
265 if (!strcmp(eq->item,"brightness")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
266 eq->value = ((brightness*100) + (1<<15))>>16; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
267 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
268 else if (!strcmp(eq->item,"contrast")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
269 eq->value = (((contrast *100) + (1<<15))>>16) - 100; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
270 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
271 else if (!strcmp(eq->item,"saturation")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
272 eq->value = (((saturation*100) + (1<<15))>>16) - 100; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
273 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
274 else |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
275 break; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
276 return CONTROL_TRUE; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
277 case VFCTRL_SET_EQUALIZER: |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
278 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation); |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
279 if(r<0) break; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
280 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16)); |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
281 eq = data; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
282 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
283 if (!strcmp(eq->item,"brightness")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
284 brightness = (( eq->value <<16) + 50)/100; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
285 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
286 else if (!strcmp(eq->item,"contrast")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
287 contrast = (((eq->value+100)<<16) + 50)/100; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
288 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
289 else if (!strcmp(eq->item,"saturation")) { |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
290 saturation = (((eq->value+100)<<16) + 50)/100; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
291 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
292 else |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
293 break; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
294 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
295 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation); |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
296 if(r<0) break; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
297 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
298 return CONTROL_TRUE; |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
299 default: |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
300 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
301 |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
302 return vf_next_control(vf,request,data); |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
303 } |
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
304 |
5522 | 305 //===========================================================================// |
306 | |
9071 | 307 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800 |
5523 | 308 |
309 static int query_format(struct vf_instance_s* vf, unsigned int fmt){ | |
310 switch(fmt){ | |
311 case IMGFMT_YV12: | |
312 case IMGFMT_I420: | |
313 case IMGFMT_IYUV: | |
9071 | 314 case IMGFMT_UYVY: |
5523 | 315 case IMGFMT_YUY2: |
316 case IMGFMT_BGR32: | |
317 case IMGFMT_BGR24: | |
318 case IMGFMT_BGR16: | |
319 case IMGFMT_BGR15: | |
320 case IMGFMT_RGB32: | |
321 case IMGFMT_RGB24: | |
6533 | 322 case IMGFMT_Y800: |
323 case IMGFMT_Y8: | |
324 case IMGFMT_YVU9: | |
6536 | 325 case IMGFMT_IF09: |
6863 | 326 case IMGFMT_444P: |
327 case IMGFMT_422P: | |
328 case IMGFMT_411P: | |
6533 | 329 { |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
330 unsigned int best=find_best_out(vf); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
331 int flags; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
332 if(!best) return 0; // no matching out-fmt |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
333 flags=vf_next_query_format(vf,best); |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
334 if(!(flags&3)) return 0; // huh? |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
335 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
336 // do not allow scaling, if we are before the PP fliter! |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
337 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
338 return flags; |
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
339 } |
5523 | 340 } |
5565
0b301fec999a
capabilities support -> automatic insertion of scale, expand, pp
arpi
parents:
5527
diff
changeset
|
341 return 0; // nomatching in-fmt |
5523 | 342 } |
343 | |
5522 | 344 static int open(vf_instance_t *vf, char* args){ |
345 vf->config=config; | |
9491 | 346 vf->start_slice=start_slice; |
347 vf->draw_slice=draw_slice; | |
5522 | 348 vf->put_image=put_image; |
5526 | 349 vf->query_format=query_format; |
9476
eff727517e6b
yuv2rgb brightness/contrast/saturation/different colorspaces support finished
michael
parents:
9276
diff
changeset
|
350 vf->control= control; |
5522 | 351 vf->priv=malloc(sizeof(struct vf_priv_s)); |
352 // TODO: parse args -> | |
353 vf->priv->ctx=NULL; | |
354 vf->priv->w= | |
355 vf->priv->h=-1; | |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
356 vf->priv->v_chr_drop=0; |
6637 | 357 vf->priv->param=0; |
7783 | 358 vf->priv->palette=NULL; |
6637 | 359 if(args) sscanf(args, "%d:%d:%d:%d", |
5522 | 360 &vf->priv->w, |
6542
7af3fcd76d2d
support dropping some chroma src lines for a bit extra speed
michael
parents:
6536
diff
changeset
|
361 &vf->priv->h, |
6637 | 362 &vf->priv->v_chr_drop, |
363 &vf->priv->param); | |
6138
523014df7d32
big cosmetics patch, cleanup of messages printed by mplayer and libs.
arpi
parents:
6126
diff
changeset
|
364 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n", |
5522 | 365 vf->priv->w, |
366 vf->priv->h); | |
367 return 1; | |
368 } | |
369 | |
370 vf_info_t vf_info_scale = { | |
371 "software scaling", | |
372 "scale", | |
373 "A'rpi", | |
374 "", | |
375 open | |
376 }; | |
377 | |
378 //===========================================================================// |