demux_lavf: handle new streams appearing during playback
[mplayer.git] / libmpcodecs / vf_scale.c
blob7579e98aceafcbc7b93ea1d039a95274a9fd17ef
1 /*
2 * This file is part of MPlayer.
4 * MPlayer is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * MPlayer is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <inttypes.h>
24 #include "config.h"
25 #include "mp_msg.h"
26 #include "cpudetect.h"
27 #include "options.h"
29 #include "img_format.h"
30 #include "mp_image.h"
31 #include "vf.h"
32 #include "fmt-conversion.h"
33 #include "mpbswap.h"
35 #include "libswscale/swscale.h"
36 #include "vf_scale.h"
38 #include "m_option.h"
39 #include "m_struct.h"
41 static struct vf_priv_s {
42 int w,h;
43 int v_chr_drop;
44 double param[2];
45 unsigned int fmt;
46 struct SwsContext *ctx;
47 struct SwsContext *ctx2; //for interlaced slices only
48 unsigned char* palette;
49 int interlaced;
50 int noup;
51 int accurate_rnd;
52 } const vf_priv_dflt = {
53 -1,-1,
55 {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
57 NULL,
58 NULL,
59 NULL
62 //===========================================================================//
64 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
66 static const unsigned int outfmt_list[]={
67 // YUV:
68 IMGFMT_444P,
69 IMGFMT_444P16_LE,
70 IMGFMT_444P16_BE,
71 IMGFMT_422P,
72 IMGFMT_422P16_LE,
73 IMGFMT_422P16_BE,
74 IMGFMT_YV12,
75 IMGFMT_I420,
76 IMGFMT_420P16_LE,
77 IMGFMT_420P16_BE,
78 IMGFMT_420A,
79 IMGFMT_IYUV,
80 IMGFMT_YVU9,
81 IMGFMT_IF09,
82 IMGFMT_411P,
83 IMGFMT_NV12,
84 IMGFMT_NV21,
85 IMGFMT_YUY2,
86 IMGFMT_UYVY,
87 IMGFMT_440P,
88 // RGB and grayscale (Y8 and Y800):
89 IMGFMT_BGR32,
90 IMGFMT_RGB32,
91 IMGFMT_BGR24,
92 IMGFMT_RGB24,
93 IMGFMT_RGB48LE,
94 IMGFMT_RGB48BE,
95 IMGFMT_BGR16,
96 IMGFMT_RGB16,
97 IMGFMT_BGR15,
98 IMGFMT_RGB15,
99 IMGFMT_BGR12,
100 IMGFMT_RGB12,
101 IMGFMT_Y800,
102 IMGFMT_Y8,
103 IMGFMT_BGR8,
104 IMGFMT_RGB8,
105 IMGFMT_BGR4,
106 IMGFMT_RGB4,
107 IMGFMT_BG4B,
108 IMGFMT_RG4B,
109 IMGFMT_BGR1,
110 IMGFMT_RGB1,
115 * A list of preferred conversions, in order of preference.
116 * This should be used for conversions that e.g. involve no scaling
117 * or to stop vf_scale from choosing a conversion that has no
118 * fast assembler implementation.
120 static int preferred_conversions[][2] = {
121 {IMGFMT_YUY2, IMGFMT_UYVY},
122 {IMGFMT_YUY2, IMGFMT_422P},
123 {IMGFMT_UYVY, IMGFMT_YUY2},
124 {IMGFMT_UYVY, IMGFMT_422P},
125 {IMGFMT_422P, IMGFMT_YUY2},
126 {IMGFMT_422P, IMGFMT_UYVY},
127 {0, 0}
130 static unsigned int find_best_out(vf_instance_t *vf, int in_format){
131 unsigned int best=0;
132 int i = -1;
133 int j = -1;
134 int format = 0;
136 // find the best outfmt:
137 while (1) {
138 int ret;
139 if (j < 0) {
140 format = in_format;
141 j = 0;
142 } else if (i < 0) {
143 while (preferred_conversions[j][0] &&
144 preferred_conversions[j][0] != in_format)
145 j++;
146 format = preferred_conversions[j++][1];
147 // switch to standard list
148 if (!format)
149 i = 0;
151 if (i >= 0)
152 format = outfmt_list[i++];
153 if (!format)
154 break;
155 ret = vf_next_query_format(vf, format);
157 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
158 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
159 best=format; // no conversion -> bingo!
160 break;
162 if(ret&VFCAP_CSP_SUPPORTED && !best)
163 best=format; // best with conversion
165 return best;
168 static int config(struct vf_instance *vf,
169 int width, int height, int d_width, int d_height,
170 unsigned int flags, unsigned int outfmt){
171 struct MPOpts *opts = vf->opts;
172 unsigned int best=find_best_out(vf, outfmt);
173 int vo_flags;
174 int int_sws_flags=0;
175 int round_w=0, round_h=0;
176 int i;
177 SwsFilter *srcFilter, *dstFilter;
178 enum PixelFormat dfmt, sfmt;
180 if(!best){
181 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
182 return 0;
184 sfmt = imgfmt2pixfmt(outfmt);
185 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
186 dfmt = imgfmt2pixfmt(best);
188 vo_flags=vf->next->query_format(vf->next,best);
190 // scaling to dwidth*d_height, if all these TRUE:
191 // - option -zoom
192 // - no other sw/hw up/down scaling avail.
193 // - we're after postproc
194 // - user didn't set w:h
195 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
196 vf->priv->w<0 && vf->priv->h<0){ // -zoom
197 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
198 if(d_width<width || d_height<height){
199 // downscale!
200 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
201 } else {
202 // upscale:
203 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
205 if(x){
206 // user wants sw scaling! (-zoom)
207 vf->priv->w=d_width;
208 vf->priv->h=d_height;
212 if(vf->priv->noup){
213 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
214 vf->priv->w= width;
215 vf->priv->h= height;
219 if (vf->priv->w <= -8) {
220 vf->priv->w += 8;
221 round_w = 1;
223 if (vf->priv->h <= -8) {
224 vf->priv->h += 8;
225 round_h = 1;
228 if (vf->priv->w < -3 || vf->priv->h < -3 ||
229 (vf->priv->w < -1 && vf->priv->h < -1)) {
230 // TODO: establish a direct connection to the user's brain
231 // and find out what the heck he thinks MPlayer should do
232 // with this nonsense.
233 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
234 return 0;
237 if (vf->priv->w == -1)
238 vf->priv->w = width;
239 if (vf->priv->w == 0)
240 vf->priv->w = d_width;
242 if (vf->priv->h == -1)
243 vf->priv->h = height;
244 if (vf->priv->h == 0)
245 vf->priv->h = d_height;
247 if (vf->priv->w == -3)
248 vf->priv->w = vf->priv->h * width / height;
249 if (vf->priv->w == -2)
250 vf->priv->w = vf->priv->h * d_width / d_height;
252 if (vf->priv->h == -3)
253 vf->priv->h = vf->priv->w * height / width;
254 if (vf->priv->h == -2)
255 vf->priv->h = vf->priv->w * d_height / d_width;
257 if (round_w)
258 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
259 if (round_h)
260 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
262 // calculate the missing parameters:
263 switch(best) {
264 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
265 case IMGFMT_I420:
266 case IMGFMT_IYUV:
267 case IMGFMT_NV12:
268 case IMGFMT_NV21:
269 vf->priv->h = (vf->priv->h + 1) & ~1;
270 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
271 case IMGFMT_UYVY:
272 vf->priv->w = (vf->priv->w + 1) & ~1;
275 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
276 width,height,vo_format_name(outfmt),
277 vf->priv->w,vf->priv->h,vo_format_name(best));
279 // free old ctx:
280 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
281 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
283 // new swscaler:
284 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
285 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
286 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
287 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
288 sfmt,
289 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
290 dfmt,
291 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
292 if(vf->priv->interlaced){
293 vf->priv->ctx2=sws_getContext(width, height >> 1,
294 sfmt,
295 vf->priv->w, vf->priv->h >> 1,
296 dfmt,
297 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
299 if(!vf->priv->ctx){
300 // error...
301 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
302 return 0;
304 vf->priv->fmt=best;
306 if(vf->priv->palette){
307 free(vf->priv->palette);
308 vf->priv->palette=NULL;
310 switch(best){
311 case IMGFMT_RGB8: {
312 /* set 332 palette for 8 bpp */
313 vf->priv->palette=malloc(4*256);
314 for(i=0; i<256; i++){
315 vf->priv->palette[4*i+0]=4*(i>>6)*21;
316 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
317 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
318 vf->priv->palette[4*i+3]=0;
320 break; }
321 case IMGFMT_BGR8: {
322 /* set 332 palette for 8 bpp */
323 vf->priv->palette=malloc(4*256);
324 for(i=0; i<256; i++){
325 vf->priv->palette[4*i+0]=4*(i&3)*21;
326 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
327 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
328 vf->priv->palette[4*i+3]=0;
330 break; }
331 case IMGFMT_BGR4:
332 case IMGFMT_BG4B: {
333 vf->priv->palette=malloc(4*16);
334 for(i=0; i<16; i++){
335 vf->priv->palette[4*i+0]=4*(i&1)*63;
336 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
337 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
338 vf->priv->palette[4*i+3]=0;
340 break; }
341 case IMGFMT_RGB4:
342 case IMGFMT_RG4B: {
343 vf->priv->palette=malloc(4*16);
344 for(i=0; i<16; i++){
345 vf->priv->palette[4*i+0]=4*(i>>3)*63;
346 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
347 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
348 vf->priv->palette[4*i+3]=0;
350 break; }
353 if (!opts->screen_size_x && !opts->screen_size_y
354 && !(opts->screen_size_xy >= 0.001)) {
355 // Compute new d_width and d_height, preserving aspect
356 // while ensuring that both are >= output size in pixels.
357 if (vf->priv->h * d_width > vf->priv->w * d_height) {
358 d_width = vf->priv->h * d_width / d_height;
359 d_height = vf->priv->h;
360 } else {
361 d_height = vf->priv->w * d_height / d_width;
362 d_width = vf->priv->w;
364 //d_width=d_width*vf->priv->w/width;
365 //d_height=d_height*vf->priv->h/height;
367 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
370 static void start_slice(struct vf_instance *vf, mp_image_t *mpi){
371 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
372 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
373 // they want slices!!! allocate the buffer.
374 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
375 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
376 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
377 vf->priv->w, vf->priv->h);
380 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
381 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
382 uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
383 #if HAVE_BIGENDIAN
384 uint32_t pal2[256];
385 if (src[1] && !src[2]){
386 int i;
387 for(i=0; i<256; i++)
388 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
389 src2[1]= pal2;
391 #endif
393 if(interlaced){
394 int i;
395 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
396 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
397 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
399 sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
400 for(i=0; i<MP_MAX_PLANES; i++){
401 src2[i] += src_stride[i];
402 dst2[i] += dst_stride[i];
404 sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
405 }else{
406 sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
410 static void draw_slice(struct vf_instance *vf,
411 unsigned char** src, int* stride, int w,int h, int x, int y){
412 mp_image_t *dmpi=vf->dmpi;
413 if(!dmpi){
414 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
415 return;
417 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
418 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
421 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
422 mp_image_t *dmpi=mpi->priv;
424 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
425 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
427 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
429 // hope we'll get DR buffer:
430 dmpi=vf_get_image(vf->next,vf->priv->fmt,
431 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
432 vf->priv->w, vf->priv->h);
434 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
437 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
438 // just conversion, no scaling -> keep postprocessing data
439 // this way we can apply pp filter to non-yv12 source using scaler
440 vf_clone_mpi_attributes(dmpi, mpi);
443 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
445 return vf_next_put_image(vf,dmpi, pts);
448 static int control(struct vf_instance *vf, int request, void* data){
449 int *table;
450 int *inv_table;
451 int r;
452 int brightness, contrast, saturation, srcRange, dstRange;
453 vf_equalizer_t *eq;
455 if(vf->priv->ctx)
456 switch(request){
457 case VFCTRL_GET_EQUALIZER:
458 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
459 if(r<0) break;
461 eq = data;
462 if (!strcmp(eq->item,"brightness")) {
463 eq->value = ((brightness*100) + (1<<15))>>16;
465 else if (!strcmp(eq->item,"contrast")) {
466 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
468 else if (!strcmp(eq->item,"saturation")) {
469 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
471 else
472 break;
473 return CONTROL_TRUE;
474 case VFCTRL_SET_EQUALIZER:
475 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
476 if(r<0) break;
477 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
478 eq = data;
480 if (!strcmp(eq->item,"brightness")) {
481 brightness = (( eq->value <<16) + 50)/100;
483 else if (!strcmp(eq->item,"contrast")) {
484 contrast = (((eq->value+100)<<16) + 50)/100;
486 else if (!strcmp(eq->item,"saturation")) {
487 saturation = (((eq->value+100)<<16) + 50)/100;
489 else
490 break;
492 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
493 if(r<0) break;
494 if(vf->priv->ctx2){
495 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
496 if(r<0) break;
499 return CONTROL_TRUE;
500 default:
501 break;
504 return vf_next_control(vf,request,data);
507 //===========================================================================//
509 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
511 static int query_format(struct vf_instance *vf, unsigned int fmt){
512 switch(fmt){
513 case IMGFMT_YV12:
514 case IMGFMT_I420:
515 case IMGFMT_IYUV:
516 case IMGFMT_UYVY:
517 case IMGFMT_YUY2:
518 case IMGFMT_BGR32:
519 case IMGFMT_BGR24:
520 case IMGFMT_BGR16:
521 case IMGFMT_BGR15:
522 case IMGFMT_RGB32:
523 case IMGFMT_RGB24:
524 case IMGFMT_Y800:
525 case IMGFMT_Y8:
526 case IMGFMT_YVU9:
527 case IMGFMT_IF09:
528 case IMGFMT_444P:
529 case IMGFMT_422P:
530 case IMGFMT_411P:
531 case IMGFMT_440P:
532 case IMGFMT_420A:
533 case IMGFMT_444P16_LE:
534 case IMGFMT_444P16_BE:
535 case IMGFMT_422P16_LE:
536 case IMGFMT_422P16_BE:
537 case IMGFMT_420P16_LE:
538 case IMGFMT_420P16_BE:
539 case IMGFMT_BGR8:
540 case IMGFMT_RGB8:
541 case IMGFMT_BG4B:
542 case IMGFMT_RG4B:
543 case IMGFMT_RGB48LE:
544 case IMGFMT_RGB48BE:
546 unsigned int best=find_best_out(vf, fmt);
547 int flags;
548 if(!best) return 0; // no matching out-fmt
549 flags=vf_next_query_format(vf,best);
550 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
551 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
552 // do not allow scaling, if we are before the PP fliter!
553 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
554 return flags;
557 return 0; // nomatching in-fmt
560 static void uninit(struct vf_instance *vf){
561 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
562 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
563 if(vf->priv->palette) free(vf->priv->palette);
564 free(vf->priv);
567 static int vf_open(vf_instance_t *vf, char *args){
568 vf->config=config;
569 vf->start_slice=start_slice;
570 vf->draw_slice=draw_slice;
571 vf->put_image=put_image;
572 vf->query_format=query_format;
573 vf->control= control;
574 vf->uninit=uninit;
575 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
576 vf->priv->w,
577 vf->priv->h);
579 return 1;
582 //global sws_flags from the command line
583 int sws_flags=2;
585 //global srcFilter
586 static SwsFilter *src_filter= NULL;
588 float sws_lum_gblur= 0.0;
589 float sws_chr_gblur= 0.0;
590 int sws_chr_vshift= 0;
591 int sws_chr_hshift= 0;
592 float sws_chr_sharpen= 0.0;
593 float sws_lum_sharpen= 0.0;
595 int get_sws_cpuflags(void){
596 return
597 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
598 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
599 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
600 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
603 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
605 static int firstTime=1;
606 *flags=0;
608 #if ARCH_X86
609 if(gCpuCaps.hasMMX)
610 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
611 #endif
612 if(firstTime)
614 firstTime=0;
615 *flags= SWS_PRINT_INFO;
617 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
619 if(src_filter) sws_freeFilter(src_filter);
621 src_filter= sws_getDefaultFilter(
622 sws_lum_gblur, sws_chr_gblur,
623 sws_lum_sharpen, sws_chr_sharpen,
624 sws_chr_hshift, sws_chr_vshift, verbose>1);
626 switch(sws_flags)
628 case 0: *flags|= SWS_FAST_BILINEAR; break;
629 case 1: *flags|= SWS_BILINEAR; break;
630 case 2: *flags|= SWS_BICUBIC; break;
631 case 3: *flags|= SWS_X; break;
632 case 4: *flags|= SWS_POINT; break;
633 case 5: *flags|= SWS_AREA; break;
634 case 6: *flags|= SWS_BICUBLIN; break;
635 case 7: *flags|= SWS_GAUSS; break;
636 case 8: *flags|= SWS_SINC; break;
637 case 9: *flags|= SWS_LANCZOS; break;
638 case 10:*flags|= SWS_SPLINE; break;
639 default:*flags|= SWS_BILINEAR; break;
642 *srcFilterParam= src_filter;
643 *dstFilterParam= NULL;
646 // will use sws_flags & src_filter (from cmd line)
647 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
649 int flags;
650 SwsFilter *dstFilterParam, *srcFilterParam;
651 enum PixelFormat dfmt, sfmt;
653 dfmt = imgfmt2pixfmt(dstFormat);
654 sfmt = imgfmt2pixfmt(srcFormat);
655 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
656 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
658 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
661 /// An example of presets usage
662 static const struct size_preset {
663 char* name;
664 int w, h;
665 } vf_size_presets_defs[] = {
666 // TODO add more 'standard' resolutions
667 { "qntsc", 352, 240 },
668 { "qpal", 352, 288 },
669 { "ntsc", 720, 480 },
670 { "pal", 720, 576 },
671 { "sntsc", 640, 480 },
672 { "spal", 768, 576 },
673 { NULL, 0, 0}
676 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
677 static const m_option_t vf_size_preset_fields[] = {
678 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
679 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
680 { NULL, NULL, 0, 0, 0, 0, NULL }
683 static const m_struct_t vf_size_preset = {
684 "scale_size_preset",
685 sizeof(struct size_preset),
686 NULL,
687 vf_size_preset_fields
690 static const m_struct_t vf_opts;
691 static const m_obj_presets_t size_preset = {
692 &vf_size_preset, // Input struct desc
693 &vf_opts, // Output struct desc
694 vf_size_presets_defs, // The list of presets
695 ST_OFF(name) // At wich offset is the name field in the preset struct
698 /// Now the options
699 #undef ST_OFF
700 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
701 static const m_option_t vf_opts_fields[] = {
702 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
703 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
704 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
705 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
706 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
707 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
708 // Note that here the 2 field is NULL (ie 0)
709 // As we want this option to act on the option struct itself
710 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},
711 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
712 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
713 { NULL, NULL, 0, 0, 0, 0, NULL }
716 static const m_struct_t vf_opts = {
717 "scale",
718 sizeof(struct vf_priv_s),
719 &vf_priv_dflt,
720 vf_opts_fields
723 const vf_info_t vf_info_scale = {
724 "software scaling",
725 "scale",
726 "A'rpi",
728 vf_open,
729 &vf_opts
732 //===========================================================================//