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.
26 #include "cpudetect.h"
29 #include "img_format.h"
32 #include "fmt-conversion.h"
35 #include "libswscale/swscale.h"
38 #include "libvo/csputils.h"
40 #include "libvo/video_out.h"
45 static struct vf_priv_s
{
51 struct SwsContext
*ctx
;
52 struct SwsContext
*ctx2
; //for interlaced slices only
53 unsigned char* palette
;
57 struct mp_csp_details colorspace
;
58 } const vf_priv_dflt
= {
62 {SWS_PARAM_DEFAULT
, SWS_PARAM_DEFAULT
},
69 //===========================================================================//
71 void sws_getFlagsAndFilterFromCmdLine(int *flags
, SwsFilter
**srcFilterParam
, SwsFilter
**dstFilterParam
);
73 static const unsigned int outfmt_list
[]={
105 // RGB and grayscale (Y8 and Y800):
132 * A list of preferred conversions, in order of preference.
133 * This should be used for conversions that e.g. involve no scaling
134 * or to stop vf_scale from choosing a conversion that has no
135 * fast assembler implementation.
137 static int preferred_conversions
[][2] = {
138 {IMGFMT_YUY2
, IMGFMT_UYVY
},
139 {IMGFMT_YUY2
, IMGFMT_422P
},
140 {IMGFMT_UYVY
, IMGFMT_YUY2
},
141 {IMGFMT_UYVY
, IMGFMT_422P
},
142 {IMGFMT_422P
, IMGFMT_YUY2
},
143 {IMGFMT_422P
, IMGFMT_UYVY
},
147 static unsigned int find_best_out(vf_instance_t
*vf
, int in_format
){
153 // find the best outfmt:
160 while (preferred_conversions
[j
][0] &&
161 preferred_conversions
[j
][0] != in_format
)
163 format
= preferred_conversions
[j
++][1];
164 // switch to standard list
169 format
= outfmt_list
[i
++];
172 ret
= vf_next_query_format(vf
, format
);
174 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"scale: query(%s) -> %d\n",vo_format_name(format
),ret
&3);
175 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){
176 best
=format
; // no conversion -> bingo!
179 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
)
180 best
=format
; // best with conversion
185 static int config(struct vf_instance
*vf
,
186 int width
, int height
, int d_width
, int d_height
,
187 unsigned int flags
, unsigned int outfmt
){
188 struct MPOpts
*opts
= vf
->opts
;
189 unsigned int best
=find_best_out(vf
, outfmt
);
192 int round_w
=0, round_h
=0;
194 SwsFilter
*srcFilter
, *dstFilter
;
195 enum PixelFormat dfmt
, sfmt
;
197 vf
->priv
->colorspace
= (struct mp_csp_details
) {0};
200 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"SwScale: no supported outfmt found :(\n");
203 sfmt
= imgfmt2pixfmt(outfmt
);
204 if (outfmt
== IMGFMT_RGB8
|| outfmt
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
205 dfmt
= imgfmt2pixfmt(best
);
207 vo_flags
=vf
->next
->query_format(vf
->next
,best
);
209 vf
->priv
->w
= vf
->priv
->cfg_w
;
210 vf
->priv
->h
= vf
->priv
->cfg_h
;
212 // scaling to dwidth*d_height, if all these TRUE:
214 // - no other sw/hw up/down scaling avail.
215 // - we're after postproc
216 // - user didn't set w:h
217 if(!(vo_flags
&VFCAP_POSTPROC
) && (flags
&VOFLAG_SWSCALE
) &&
218 vf
->priv
->w
<0 && vf
->priv
->h
<0){ // -zoom
219 int x
=(vo_flags
&VFCAP_SWSCALE
) ? 0 : 1;
220 if(d_width
<width
|| d_height
<height
){
222 if(vo_flags
&VFCAP_HWSCALE_DOWN
) x
=0;
225 if(vo_flags
&VFCAP_HWSCALE_UP
) x
=0;
228 // user wants sw scaling! (-zoom)
230 vf
->priv
->h
=d_height
;
235 if((vf
->priv
->w
> width
) + (vf
->priv
->h
> height
) >= vf
->priv
->noup
){
241 if (vf
->priv
->w
<= -8) {
245 if (vf
->priv
->h
<= -8) {
250 if (vf
->priv
->w
< -3 || vf
->priv
->h
< -3 ||
251 (vf
->priv
->w
< -1 && vf
->priv
->h
< -1)) {
252 // TODO: establish a direct connection to the user's brain
253 // and find out what the heck he thinks MPlayer should do
254 // with this nonsense.
255 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
259 if (vf
->priv
->w
== -1)
261 if (vf
->priv
->w
== 0)
262 vf
->priv
->w
= d_width
;
264 if (vf
->priv
->h
== -1)
265 vf
->priv
->h
= height
;
266 if (vf
->priv
->h
== 0)
267 vf
->priv
->h
= d_height
;
269 if (vf
->priv
->w
== -3)
270 vf
->priv
->w
= vf
->priv
->h
* width
/ height
;
271 if (vf
->priv
->w
== -2)
272 vf
->priv
->w
= vf
->priv
->h
* d_width
/ d_height
;
274 if (vf
->priv
->h
== -3)
275 vf
->priv
->h
= vf
->priv
->w
* height
/ width
;
276 if (vf
->priv
->h
== -2)
277 vf
->priv
->h
= vf
->priv
->w
* d_height
/ d_width
;
280 vf
->priv
->w
= ((vf
->priv
->w
+ 8) / 16) * 16;
282 vf
->priv
->h
= ((vf
->priv
->h
+ 8) / 16) * 16;
284 // calculate the missing parameters:
286 case IMGFMT_YV12
: /* YV12 needs w & h rounded to 2 */
291 vf
->priv
->h
= (vf
->priv
->h
+ 1) & ~1;
292 case IMGFMT_YUY2
: /* YUY2 needs w rounded to 2 */
294 vf
->priv
->w
= (vf
->priv
->w
+ 1) & ~1;
297 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"SwScale: scaling %dx%d %s to %dx%d %s \n",
298 width
,height
,vo_format_name(outfmt
),
299 vf
->priv
->w
,vf
->priv
->h
,vo_format_name(best
));
302 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
303 if(vf
->priv
->ctx2
)sws_freeContext(vf
->priv
->ctx2
);
306 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags
, &srcFilter
, &dstFilter
);
307 int_sws_flags
|= vf
->priv
->v_chr_drop
<< SWS_SRC_V_CHR_DROP_SHIFT
;
308 int_sws_flags
|= vf
->priv
->accurate_rnd
* SWS_ACCURATE_RND
;
309 vf
->priv
->ctx
=sws_getContext(width
, height
>> vf
->priv
->interlaced
,
311 vf
->priv
->w
, vf
->priv
->h
>> vf
->priv
->interlaced
,
313 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
314 if(vf
->priv
->interlaced
){
315 vf
->priv
->ctx2
=sws_getContext(width
, height
>> 1,
317 vf
->priv
->w
, vf
->priv
->h
>> 1,
319 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
323 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"Couldn't init SwScaler for this setup\n");
328 free(vf
->priv
->palette
);
329 vf
->priv
->palette
=NULL
;
332 /* set 332 palette for 8 bpp */
333 vf
->priv
->palette
=malloc(4*256);
334 for(i
=0; i
<256; i
++){
335 vf
->priv
->palette
[4*i
+0]=4*(i
>>6)*21;
336 vf
->priv
->palette
[4*i
+1]=4*((i
>>3)&7)*9;
337 vf
->priv
->palette
[4*i
+2]=4*((i
&7)&7)*9;
338 vf
->priv
->palette
[4*i
+3]=0;
342 /* set 332 palette for 8 bpp */
343 vf
->priv
->palette
=malloc(4*256);
344 for(i
=0; i
<256; i
++){
345 vf
->priv
->palette
[4*i
+0]=4*(i
&3)*21;
346 vf
->priv
->palette
[4*i
+1]=4*((i
>>2)&7)*9;
347 vf
->priv
->palette
[4*i
+2]=4*((i
>>5)&7)*9;
348 vf
->priv
->palette
[4*i
+3]=0;
353 vf
->priv
->palette
=malloc(4*16);
355 vf
->priv
->palette
[4*i
+0]=4*(i
&1)*63;
356 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
357 vf
->priv
->palette
[4*i
+2]=4*((i
>>3)&1)*63;
358 vf
->priv
->palette
[4*i
+3]=0;
363 vf
->priv
->palette
=malloc(4*16);
365 vf
->priv
->palette
[4*i
+0]=4*(i
>>3)*63;
366 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
367 vf
->priv
->palette
[4*i
+2]=4*((i
&1)&1)*63;
368 vf
->priv
->palette
[4*i
+3]=0;
373 if (!opts
->screen_size_x
&& !opts
->screen_size_y
374 && !(opts
->screen_size_xy
>= 0.001)) {
375 // Compute new d_width and d_height, preserving aspect
376 // while ensuring that both are >= output size in pixels.
377 if (vf
->priv
->h
* d_width
> vf
->priv
->w
* d_height
) {
378 d_width
= vf
->priv
->h
* d_width
/ d_height
;
379 d_height
= vf
->priv
->h
;
381 d_height
= vf
->priv
->w
* d_height
/ d_width
;
382 d_width
= vf
->priv
->w
;
384 //d_width=d_width*vf->priv->w/width;
385 //d_height=d_height*vf->priv->h/height;
387 return vf_next_config(vf
,vf
->priv
->w
,vf
->priv
->h
,d_width
,d_height
,flags
,best
);
390 static void start_slice(struct vf_instance
*vf
, mp_image_t
*mpi
){
391 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
392 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
)) return; // shouldn't happen
393 // they want slices!!! allocate the buffer.
394 mpi
->priv
=vf
->dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
395 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
396 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
397 vf
->priv
->w
, vf
->priv
->h
);
400 static void scale(struct SwsContext
*sws1
, struct SwsContext
*sws2
, uint8_t *src
[MP_MAX_PLANES
], int src_stride
[MP_MAX_PLANES
],
401 int y
, int h
, uint8_t *dst
[MP_MAX_PLANES
], int dst_stride
[MP_MAX_PLANES
], int interlaced
){
402 const uint8_t *src2
[MP_MAX_PLANES
]={src
[0], src
[1], src
[2], src
[3]};
405 if (src
[1] && !src
[2]){
408 pal2
[i
]= bswap_32(((uint32_t*)src
[1])[i
]);
415 uint8_t *dst2
[MP_MAX_PLANES
]={dst
[0], dst
[1], dst
[2], dst
[3]};
416 int src_stride2
[MP_MAX_PLANES
]={2*src_stride
[0], 2*src_stride
[1], 2*src_stride
[2], 2*src_stride
[3]};
417 int dst_stride2
[MP_MAX_PLANES
]={2*dst_stride
[0], 2*dst_stride
[1], 2*dst_stride
[2], 2*dst_stride
[3]};
419 sws_scale(sws1
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
420 for(i
=0; i
<MP_MAX_PLANES
; i
++){
421 src2
[i
] += src_stride
[i
];
422 dst2
[i
] += dst_stride
[i
];
424 sws_scale(sws2
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
426 sws_scale(sws1
, src2
, src_stride
, y
, h
, dst
, dst_stride
);
430 static void draw_slice(struct vf_instance
*vf
,
431 unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
){
432 mp_image_t
*dmpi
=vf
->dmpi
;
434 mp_msg(MSGT_VFILTER
,MSGL_FATAL
,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
437 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
438 scale(vf
->priv
->ctx
, vf
->priv
->ctx2
, src
, stride
, y
, h
, dmpi
->planes
, dmpi
->stride
, vf
->priv
->interlaced
);
441 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
){
442 mp_image_t
*dmpi
=mpi
->priv
;
444 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
445 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
447 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
&& dmpi
)){
449 // hope we'll get DR buffer:
450 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
451 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
452 vf
->priv
->w
, vf
->priv
->h
);
454 scale(vf
->priv
->ctx
, vf
->priv
->ctx
, mpi
->planes
,mpi
->stride
,0,mpi
->h
,dmpi
->planes
,dmpi
->stride
, vf
->priv
->interlaced
);
457 if(vf
->priv
->w
==mpi
->w
&& vf
->priv
->h
==mpi
->h
){
458 // just conversion, no scaling -> keep postprocessing data
459 // this way we can apply pp filter to non-yv12 source using scaler
460 vf_clone_mpi_attributes(dmpi
, mpi
);
463 if(vf
->priv
->palette
) dmpi
->planes
[1]=vf
->priv
->palette
; // export palette!
465 return vf_next_put_image(vf
,dmpi
, pts
);
468 static int control(struct vf_instance
*vf
, int request
, void* data
){
472 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
477 case VFCTRL_GET_EQUALIZER
:
478 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
482 if (!strcmp(eq
->item
,"brightness")) {
483 eq
->value
= ((brightness
*100) + (1<<15))>>16;
485 else if (!strcmp(eq
->item
,"contrast")) {
486 eq
->value
= (((contrast
*100) + (1<<15))>>16) - 100;
488 else if (!strcmp(eq
->item
,"saturation")) {
489 eq
->value
= (((saturation
*100) + (1<<15))>>16) - 100;
494 case VFCTRL_SET_EQUALIZER
:
495 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
497 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
500 if (!strcmp(eq
->item
,"brightness")) {
501 brightness
= (( eq
->value
<<16) + 50)/100;
503 else if (!strcmp(eq
->item
,"contrast")) {
504 contrast
= (((eq
->value
+100)<<16) + 50)/100;
506 else if (!strcmp(eq
->item
,"saturation")) {
507 saturation
= (((eq
->value
+100)<<16) + 50)/100;
512 r
= sws_setColorspaceDetails(vf
->priv
->ctx
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
515 r
= sws_setColorspaceDetails(vf
->priv
->ctx2
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
520 case VFCTRL_SET_YUV_COLORSPACE
: {
521 struct mp_csp_details colorspace
= *(struct mp_csp_details
*)data
;
522 if (mp_sws_set_colorspace(vf
->priv
->ctx
, &colorspace
) >= 0) {
524 mp_sws_set_colorspace(vf
->priv
->ctx2
, &colorspace
);
525 vf
->priv
->colorspace
= colorspace
;
530 case VFCTRL_GET_YUV_COLORSPACE
: {
531 /* This scale filter should never react to colorspace commands if it
532 * doesn't do YUV->RGB conversion. But because finding out whether this
533 * is really YUV->RGB (and not YUV->YUV or anything else) is hard,
534 * react only if the colorspace has been set explicitly before. The
535 * trick is that mp_sws_set_colorspace does not succeed for YUV->YUV
536 * and RGB->YUV conversions, which makes this code correct in "most"
537 * cases. (This would be trivial to do correctly if libswscale exposed
538 * functionality like isYUV()).
540 if (vf
->priv
->colorspace
.format
) {
541 *(struct mp_csp_details
*)data
= vf
->priv
->colorspace
;
550 return vf_next_control(vf
,request
,data
);
553 static const int mp_csp_to_swscale
[MP_CSP_COUNT
] = {
554 [MP_CSP_BT_601
] = SWS_CS_ITU601
,
555 [MP_CSP_BT_709
] = SWS_CS_ITU709
,
556 [MP_CSP_SMPTE_240M
] = SWS_CS_SMPTE240M
,
559 // Adjust the colorspace used for YUV->RGB conversion. On other conversions,
560 // do nothing or return an error.
561 // The csp argument is set to the supported values.
562 // Return 0 on success and -1 on error.
563 int mp_sws_set_colorspace(struct SwsContext
*sws
, struct mp_csp_details
*csp
)
565 int *table
, *inv_table
;
566 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
568 csp
->levels_out
= MP_CSP_LEVELS_PC
;
570 // NOTE: returns an error if the destination format is YUV
571 if (sws_getColorspaceDetails(sws
, &inv_table
, &srcRange
, &table
, &dstRange
,
572 &brightness
, &contrast
, &saturation
) == -1)
575 int sws_csp
= mp_csp_to_swscale
[csp
->format
];
577 // colorspace not supported, go with a reasonable default
578 csp
->format
= SWS_CS_ITU601
;
579 sws_csp
= MP_CSP_BT_601
;
582 /* The swscale API for these is hardly documented.
583 * Apparently table/range only apply to YUV. Thus dstRange has no effect
584 * for YUV->RGB conversions, and conversions to limited-range RGB are
587 srcRange
= csp
->levels_in
== MP_CSP_LEVELS_PC
;
588 const int *new_inv_table
= sws_getCoefficients(sws_csp
);
590 if (sws_setColorspaceDetails(sws
, new_inv_table
, srcRange
, table
, dstRange
,
591 brightness
, contrast
, saturation
) == -1)
597 *csp
= (struct mp_csp_details
){0};
601 //===========================================================================//
603 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
605 static int query_format(struct vf_instance
*vf
, unsigned int fmt
){
606 if (!IMGFMT_IS_HWACCEL(fmt
) && imgfmt2pixfmt(fmt
) != PIX_FMT_NONE
) {
607 unsigned int best
=find_best_out(vf
, fmt
);
609 if(!best
) return 0; // no matching out-fmt
610 flags
=vf_next_query_format(vf
,best
);
611 if(!(flags
&(VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
))) return 0; // huh?
612 if(fmt
!=best
) flags
&=~VFCAP_CSP_SUPPORTED_BY_HW
;
613 // do not allow scaling, if we are before the PP fliter!
614 if(!(flags
&VFCAP_POSTPROC
)) flags
|=VFCAP_SWSCALE
;
617 return 0; // nomatching in-fmt
620 static void uninit(struct vf_instance
*vf
){
621 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
622 if(vf
->priv
->ctx2
) sws_freeContext(vf
->priv
->ctx2
);
623 free(vf
->priv
->palette
);
627 static int vf_open(vf_instance_t
*vf
, char *args
){
629 vf
->start_slice
=start_slice
;
630 vf
->draw_slice
=draw_slice
;
631 vf
->put_image
=put_image
;
632 vf
->query_format
=query_format
;
633 vf
->control
= control
;
635 mp_msg(MSGT_VFILTER
,MSGL_V
,"SwScale params: %d x %d (-1=no scaling)\n",
642 //global sws_flags from the command line
646 static SwsFilter
*src_filter
= NULL
;
648 float sws_lum_gblur
= 0.0;
649 float sws_chr_gblur
= 0.0;
650 int sws_chr_vshift
= 0;
651 int sws_chr_hshift
= 0;
652 float sws_chr_sharpen
= 0.0;
653 float sws_lum_sharpen
= 0.0;
655 int get_sws_cpuflags(void){
657 (gCpuCaps
.hasMMX
? SWS_CPU_CAPS_MMX
: 0)
658 | (gCpuCaps
.hasMMX2
? SWS_CPU_CAPS_MMX2
: 0)
659 | (gCpuCaps
.has3DNow
? SWS_CPU_CAPS_3DNOW
: 0)
660 | (gCpuCaps
.hasAltiVec
? SWS_CPU_CAPS_ALTIVEC
: 0);
663 void sws_getFlagsAndFilterFromCmdLine(int *flags
, SwsFilter
**srcFilterParam
, SwsFilter
**dstFilterParam
)
665 static int firstTime
=1;
670 __asm__
volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
675 *flags
= SWS_PRINT_INFO
;
677 else if( mp_msg_test(MSGT_VFILTER
,MSGL_DBG2
) ) *flags
= SWS_PRINT_INFO
;
679 if(src_filter
) sws_freeFilter(src_filter
);
681 src_filter
= sws_getDefaultFilter(
682 sws_lum_gblur
, sws_chr_gblur
,
683 sws_lum_sharpen
, sws_chr_sharpen
,
684 sws_chr_hshift
, sws_chr_vshift
, verbose
>1);
688 case 0: *flags
|= SWS_FAST_BILINEAR
; break;
689 case 1: *flags
|= SWS_BILINEAR
; break;
690 case 2: *flags
|= SWS_BICUBIC
; break;
691 case 3: *flags
|= SWS_X
; break;
692 case 4: *flags
|= SWS_POINT
; break;
693 case 5: *flags
|= SWS_AREA
; break;
694 case 6: *flags
|= SWS_BICUBLIN
; break;
695 case 7: *flags
|= SWS_GAUSS
; break;
696 case 8: *flags
|= SWS_SINC
; break;
697 case 9: *flags
|= SWS_LANCZOS
; break;
698 case 10:*flags
|= SWS_SPLINE
; break;
699 default:*flags
|= SWS_BILINEAR
; break;
702 *srcFilterParam
= src_filter
;
703 *dstFilterParam
= NULL
;
706 // will use sws_flags & src_filter (from cmd line)
707 struct SwsContext
*sws_getContextFromCmdLine(int srcW
, int srcH
, int srcFormat
, int dstW
, int dstH
, int dstFormat
)
710 SwsFilter
*dstFilterParam
, *srcFilterParam
;
711 enum PixelFormat dfmt
, sfmt
;
713 dfmt
= imgfmt2pixfmt(dstFormat
);
714 sfmt
= imgfmt2pixfmt(srcFormat
);
715 if (srcFormat
== IMGFMT_RGB8
|| srcFormat
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
716 sws_getFlagsAndFilterFromCmdLine(&flags
, &srcFilterParam
, &dstFilterParam
);
718 return sws_getContext(srcW
, srcH
, sfmt
, dstW
, dstH
, dfmt
, flags
| get_sws_cpuflags(), srcFilterParam
, dstFilterParam
, NULL
);
721 /// An example of presets usage
722 static const struct size_preset
{
725 } vf_size_presets_defs
[] = {
726 // TODO add more 'standard' resolutions
727 { "qntsc", 352, 240 },
728 { "qpal", 352, 288 },
729 { "ntsc", 720, 480 },
731 { "sntsc", 640, 480 },
732 { "spal", 768, 576 },
736 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
737 static const m_option_t vf_size_preset_fields
[] = {
738 {"w", ST_OFF(w
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
739 {"h", ST_OFF(h
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
740 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
743 static const m_struct_t vf_size_preset
= {
745 sizeof(struct size_preset
),
747 vf_size_preset_fields
750 static const m_struct_t vf_opts
;
751 static const m_obj_presets_t size_preset
= {
752 &vf_size_preset
, // Input struct desc
753 &vf_opts
, // Output struct desc
754 vf_size_presets_defs
, // The list of presets
755 ST_OFF(name
) // At wich offset is the name field in the preset struct
760 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
761 static const m_option_t vf_opts_fields
[] = {
762 {"w", ST_OFF(cfg_w
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
763 {"h", ST_OFF(cfg_h
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
764 {"interlaced", ST_OFF(interlaced
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 1, NULL
},
765 {"chr-drop", ST_OFF(v_chr_drop
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 3, NULL
},
766 {"param" , ST_OFF(param
[0]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
767 {"param2", ST_OFF(param
[1]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
768 // Note that here the 2 field is NULL (ie 0)
769 // As we want this option to act on the option struct itself
770 {"presize", 0, CONF_TYPE_OBJ_PRESETS
, 0, 0, 0, (void *)&size_preset
},
771 {"noup", ST_OFF(noup
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 2, NULL
},
772 {"arnd", ST_OFF(accurate_rnd
), CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
773 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
776 static const m_struct_t vf_opts
= {
778 sizeof(struct vf_priv_s
),
783 const vf_info_t vf_info_scale
= {
792 //===========================================================================//