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"
43 static struct vf_priv_s
{
48 struct SwsContext
*ctx
;
49 struct SwsContext
*ctx2
; //for interlaced slices only
50 unsigned char* palette
;
54 struct mp_csp_details colorspace
;
55 } const vf_priv_dflt
= {
58 {SWS_PARAM_DEFAULT
, SWS_PARAM_DEFAULT
},
65 //===========================================================================//
67 void sws_getFlagsAndFilterFromCmdLine(int *flags
, SwsFilter
**srcFilterParam
, SwsFilter
**dstFilterParam
);
69 static const unsigned int outfmt_list
[]={
101 // RGB and grayscale (Y8 and Y800):
128 * A list of preferred conversions, in order of preference.
129 * This should be used for conversions that e.g. involve no scaling
130 * or to stop vf_scale from choosing a conversion that has no
131 * fast assembler implementation.
133 static int preferred_conversions
[][2] = {
134 {IMGFMT_YUY2
, IMGFMT_UYVY
},
135 {IMGFMT_YUY2
, IMGFMT_422P
},
136 {IMGFMT_UYVY
, IMGFMT_YUY2
},
137 {IMGFMT_UYVY
, IMGFMT_422P
},
138 {IMGFMT_422P
, IMGFMT_YUY2
},
139 {IMGFMT_422P
, IMGFMT_UYVY
},
143 static unsigned int find_best_out(vf_instance_t
*vf
, int in_format
){
149 // find the best outfmt:
156 while (preferred_conversions
[j
][0] &&
157 preferred_conversions
[j
][0] != in_format
)
159 format
= preferred_conversions
[j
++][1];
160 // switch to standard list
165 format
= outfmt_list
[i
++];
168 ret
= vf_next_query_format(vf
, format
);
170 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"scale: query(%s) -> %d\n",vo_format_name(format
),ret
&3);
171 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){
172 best
=format
; // no conversion -> bingo!
175 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
)
176 best
=format
; // best with conversion
181 static int config(struct vf_instance
*vf
,
182 int width
, int height
, int d_width
, int d_height
,
183 unsigned int flags
, unsigned int outfmt
){
184 struct MPOpts
*opts
= vf
->opts
;
185 unsigned int best
=find_best_out(vf
, outfmt
);
188 int round_w
=0, round_h
=0;
190 SwsFilter
*srcFilter
, *dstFilter
;
191 enum PixelFormat dfmt
, sfmt
;
193 vf
->priv
->colorspace
= (struct mp_csp_details
) {0};
196 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"SwScale: no supported outfmt found :(\n");
199 sfmt
= imgfmt2pixfmt(outfmt
);
200 if (outfmt
== IMGFMT_RGB8
|| outfmt
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
201 dfmt
= imgfmt2pixfmt(best
);
203 vo_flags
=vf
->next
->query_format(vf
->next
,best
);
205 // scaling to dwidth*d_height, if all these TRUE:
207 // - no other sw/hw up/down scaling avail.
208 // - we're after postproc
209 // - user didn't set w:h
210 if(!(vo_flags
&VFCAP_POSTPROC
) && (flags
&4) &&
211 vf
->priv
->w
<0 && vf
->priv
->h
<0){ // -zoom
212 int x
=(vo_flags
&VFCAP_SWSCALE
) ? 0 : 1;
213 if(d_width
<width
|| d_height
<height
){
215 if(vo_flags
&VFCAP_HWSCALE_DOWN
) x
=0;
218 if(vo_flags
&VFCAP_HWSCALE_UP
) x
=0;
221 // user wants sw scaling! (-zoom)
223 vf
->priv
->h
=d_height
;
228 if((vf
->priv
->w
> width
) + (vf
->priv
->h
> height
) >= vf
->priv
->noup
){
234 if (vf
->priv
->w
<= -8) {
238 if (vf
->priv
->h
<= -8) {
243 if (vf
->priv
->w
< -3 || vf
->priv
->h
< -3 ||
244 (vf
->priv
->w
< -1 && vf
->priv
->h
< -1)) {
245 // TODO: establish a direct connection to the user's brain
246 // and find out what the heck he thinks MPlayer should do
247 // with this nonsense.
248 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
252 if (vf
->priv
->w
== -1)
254 if (vf
->priv
->w
== 0)
255 vf
->priv
->w
= d_width
;
257 if (vf
->priv
->h
== -1)
258 vf
->priv
->h
= height
;
259 if (vf
->priv
->h
== 0)
260 vf
->priv
->h
= d_height
;
262 if (vf
->priv
->w
== -3)
263 vf
->priv
->w
= vf
->priv
->h
* width
/ height
;
264 if (vf
->priv
->w
== -2)
265 vf
->priv
->w
= vf
->priv
->h
* d_width
/ d_height
;
267 if (vf
->priv
->h
== -3)
268 vf
->priv
->h
= vf
->priv
->w
* height
/ width
;
269 if (vf
->priv
->h
== -2)
270 vf
->priv
->h
= vf
->priv
->w
* d_height
/ d_width
;
273 vf
->priv
->w
= ((vf
->priv
->w
+ 8) / 16) * 16;
275 vf
->priv
->h
= ((vf
->priv
->h
+ 8) / 16) * 16;
277 // calculate the missing parameters:
279 case IMGFMT_YV12
: /* YV12 needs w & h rounded to 2 */
284 vf
->priv
->h
= (vf
->priv
->h
+ 1) & ~1;
285 case IMGFMT_YUY2
: /* YUY2 needs w rounded to 2 */
287 vf
->priv
->w
= (vf
->priv
->w
+ 1) & ~1;
290 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"SwScale: scaling %dx%d %s to %dx%d %s \n",
291 width
,height
,vo_format_name(outfmt
),
292 vf
->priv
->w
,vf
->priv
->h
,vo_format_name(best
));
295 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
296 if(vf
->priv
->ctx2
)sws_freeContext(vf
->priv
->ctx2
);
299 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags
, &srcFilter
, &dstFilter
);
300 int_sws_flags
|= vf
->priv
->v_chr_drop
<< SWS_SRC_V_CHR_DROP_SHIFT
;
301 int_sws_flags
|= vf
->priv
->accurate_rnd
* SWS_ACCURATE_RND
;
302 vf
->priv
->ctx
=sws_getContext(width
, height
>> vf
->priv
->interlaced
,
304 vf
->priv
->w
, vf
->priv
->h
>> vf
->priv
->interlaced
,
306 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
307 if(vf
->priv
->interlaced
){
308 vf
->priv
->ctx2
=sws_getContext(width
, height
>> 1,
310 vf
->priv
->w
, vf
->priv
->h
>> 1,
312 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
316 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"Couldn't init SwScaler for this setup\n");
321 free(vf
->priv
->palette
);
322 vf
->priv
->palette
=NULL
;
325 /* set 332 palette for 8 bpp */
326 vf
->priv
->palette
=malloc(4*256);
327 for(i
=0; i
<256; i
++){
328 vf
->priv
->palette
[4*i
+0]=4*(i
>>6)*21;
329 vf
->priv
->palette
[4*i
+1]=4*((i
>>3)&7)*9;
330 vf
->priv
->palette
[4*i
+2]=4*((i
&7)&7)*9;
331 vf
->priv
->palette
[4*i
+3]=0;
335 /* set 332 palette for 8 bpp */
336 vf
->priv
->palette
=malloc(4*256);
337 for(i
=0; i
<256; i
++){
338 vf
->priv
->palette
[4*i
+0]=4*(i
&3)*21;
339 vf
->priv
->palette
[4*i
+1]=4*((i
>>2)&7)*9;
340 vf
->priv
->palette
[4*i
+2]=4*((i
>>5)&7)*9;
341 vf
->priv
->palette
[4*i
+3]=0;
346 vf
->priv
->palette
=malloc(4*16);
348 vf
->priv
->palette
[4*i
+0]=4*(i
&1)*63;
349 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
350 vf
->priv
->palette
[4*i
+2]=4*((i
>>3)&1)*63;
351 vf
->priv
->palette
[4*i
+3]=0;
356 vf
->priv
->palette
=malloc(4*16);
358 vf
->priv
->palette
[4*i
+0]=4*(i
>>3)*63;
359 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
360 vf
->priv
->palette
[4*i
+2]=4*((i
&1)&1)*63;
361 vf
->priv
->palette
[4*i
+3]=0;
366 if (!opts
->screen_size_x
&& !opts
->screen_size_y
367 && !(opts
->screen_size_xy
>= 0.001)) {
368 // Compute new d_width and d_height, preserving aspect
369 // while ensuring that both are >= output size in pixels.
370 if (vf
->priv
->h
* d_width
> vf
->priv
->w
* d_height
) {
371 d_width
= vf
->priv
->h
* d_width
/ d_height
;
372 d_height
= vf
->priv
->h
;
374 d_height
= vf
->priv
->w
* d_height
/ d_width
;
375 d_width
= vf
->priv
->w
;
377 //d_width=d_width*vf->priv->w/width;
378 //d_height=d_height*vf->priv->h/height;
380 return vf_next_config(vf
,vf
->priv
->w
,vf
->priv
->h
,d_width
,d_height
,flags
,best
);
383 static void start_slice(struct vf_instance
*vf
, mp_image_t
*mpi
){
384 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
385 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
)) return; // shouldn't happen
386 // they want slices!!! allocate the buffer.
387 mpi
->priv
=vf
->dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
388 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
389 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
390 vf
->priv
->w
, vf
->priv
->h
);
393 static void scale(struct SwsContext
*sws1
, struct SwsContext
*sws2
, uint8_t *src
[MP_MAX_PLANES
], int src_stride
[MP_MAX_PLANES
],
394 int y
, int h
, uint8_t *dst
[MP_MAX_PLANES
], int dst_stride
[MP_MAX_PLANES
], int interlaced
){
395 const uint8_t *src2
[MP_MAX_PLANES
]={src
[0], src
[1], src
[2], src
[3]};
398 if (src
[1] && !src
[2]){
401 pal2
[i
]= bswap_32(((uint32_t*)src
[1])[i
]);
408 uint8_t *dst2
[MP_MAX_PLANES
]={dst
[0], dst
[1], dst
[2], dst
[3]};
409 int src_stride2
[MP_MAX_PLANES
]={2*src_stride
[0], 2*src_stride
[1], 2*src_stride
[2], 2*src_stride
[3]};
410 int dst_stride2
[MP_MAX_PLANES
]={2*dst_stride
[0], 2*dst_stride
[1], 2*dst_stride
[2], 2*dst_stride
[3]};
412 sws_scale(sws1
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
413 for(i
=0; i
<MP_MAX_PLANES
; i
++){
414 src2
[i
] += src_stride
[i
];
415 dst2
[i
] += dst_stride
[i
];
417 sws_scale(sws2
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
419 sws_scale(sws1
, src2
, src_stride
, y
, h
, dst
, dst_stride
);
423 static void draw_slice(struct vf_instance
*vf
,
424 unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
){
425 mp_image_t
*dmpi
=vf
->dmpi
;
427 mp_msg(MSGT_VFILTER
,MSGL_FATAL
,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
430 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
431 scale(vf
->priv
->ctx
, vf
->priv
->ctx2
, src
, stride
, y
, h
, dmpi
->planes
, dmpi
->stride
, vf
->priv
->interlaced
);
434 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
){
435 mp_image_t
*dmpi
=mpi
->priv
;
437 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
438 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
440 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
&& dmpi
)){
442 // hope we'll get DR buffer:
443 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
444 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
445 vf
->priv
->w
, vf
->priv
->h
);
447 scale(vf
->priv
->ctx
, vf
->priv
->ctx
, mpi
->planes
,mpi
->stride
,0,mpi
->h
,dmpi
->planes
,dmpi
->stride
, vf
->priv
->interlaced
);
450 if(vf
->priv
->w
==mpi
->w
&& vf
->priv
->h
==mpi
->h
){
451 // just conversion, no scaling -> keep postprocessing data
452 // this way we can apply pp filter to non-yv12 source using scaler
453 vf_clone_mpi_attributes(dmpi
, mpi
);
456 if(vf
->priv
->palette
) dmpi
->planes
[1]=vf
->priv
->palette
; // export palette!
458 return vf_next_put_image(vf
,dmpi
, pts
);
461 static int control(struct vf_instance
*vf
, int request
, void* data
){
465 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
470 case VFCTRL_GET_EQUALIZER
:
471 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
475 if (!strcmp(eq
->item
,"brightness")) {
476 eq
->value
= ((brightness
*100) + (1<<15))>>16;
478 else if (!strcmp(eq
->item
,"contrast")) {
479 eq
->value
= (((contrast
*100) + (1<<15))>>16) - 100;
481 else if (!strcmp(eq
->item
,"saturation")) {
482 eq
->value
= (((saturation
*100) + (1<<15))>>16) - 100;
487 case VFCTRL_SET_EQUALIZER
:
488 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
490 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
493 if (!strcmp(eq
->item
,"brightness")) {
494 brightness
= (( eq
->value
<<16) + 50)/100;
496 else if (!strcmp(eq
->item
,"contrast")) {
497 contrast
= (((eq
->value
+100)<<16) + 50)/100;
499 else if (!strcmp(eq
->item
,"saturation")) {
500 saturation
= (((eq
->value
+100)<<16) + 50)/100;
505 r
= sws_setColorspaceDetails(vf
->priv
->ctx
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
508 r
= sws_setColorspaceDetails(vf
->priv
->ctx2
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
513 case VFCTRL_SET_YUV_COLORSPACE
: {
514 struct mp_csp_details colorspace
= *(struct mp_csp_details
*)data
;
515 if (mp_sws_set_colorspace(vf
->priv
->ctx
, &colorspace
) >= 0) {
517 mp_sws_set_colorspace(vf
->priv
->ctx2
, &colorspace
);
518 vf
->priv
->colorspace
= colorspace
;
523 case VFCTRL_GET_YUV_COLORSPACE
: {
524 /* This scale filter should never react to colorspace commands if it
525 * doesn't do YUV->RGB conversion. But because finding out whether this
526 * is really YUV->RGB (and not YUV->YUV or anything else) is hard,
527 * react only if the colorspace has been set explicitly before. The
528 * trick is that mp_sws_set_colorspace does not succeed for YUV->YUV
529 * and RGB->YUV conversions, which makes this code correct in "most"
530 * cases. (This would be trivial to do correctly if libswscale exposed
531 * functionality like isYUV()).
533 if (vf
->priv
->colorspace
.format
) {
534 *(struct mp_csp_details
*)data
= vf
->priv
->colorspace
;
543 return vf_next_control(vf
,request
,data
);
546 static const int mp_csp_to_swscale
[MP_CSP_COUNT
] = {
547 [MP_CSP_BT_601
] = SWS_CS_ITU601
,
548 [MP_CSP_BT_709
] = SWS_CS_ITU709
,
549 [MP_CSP_SMPTE_240M
] = SWS_CS_SMPTE240M
,
552 // Adjust the colorspace used for YUV->RGB conversion. On other conversions,
553 // do nothing or return an error.
554 // The csp argument is set to the supported values.
555 // Return 0 on success and -1 on error.
556 int mp_sws_set_colorspace(struct SwsContext
*sws
, struct mp_csp_details
*csp
)
558 int *table
, *inv_table
;
559 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
561 csp
->levels_out
= MP_CSP_LEVELS_PC
;
563 // NOTE: returns an error if the destination format is YUV
564 if (sws_getColorspaceDetails(sws
, &inv_table
, &srcRange
, &table
, &dstRange
,
565 &brightness
, &contrast
, &saturation
) == -1)
568 int sws_csp
= mp_csp_to_swscale
[csp
->format
];
570 // colorspace not supported, go with a reasonable default
571 csp
->format
= SWS_CS_ITU601
;
572 sws_csp
= MP_CSP_BT_601
;
575 /* The swscale API for these is hardly documented.
576 * Apparently table/range only apply to YUV. Thus dstRange has no effect
577 * for YUV->RGB conversions, and conversions to limited-range RGB are
580 srcRange
= csp
->levels_in
== MP_CSP_LEVELS_PC
;
581 const int *new_inv_table
= sws_getCoefficients(sws_csp
);
583 if (sws_setColorspaceDetails(sws
, new_inv_table
, srcRange
, table
, dstRange
,
584 brightness
, contrast
, saturation
) == -1)
590 *csp
= (struct mp_csp_details
){0};
594 //===========================================================================//
596 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
598 static int query_format(struct vf_instance
*vf
, unsigned int fmt
){
599 if (!IMGFMT_IS_HWACCEL(fmt
) && imgfmt2pixfmt(fmt
) != PIX_FMT_NONE
) {
600 unsigned int best
=find_best_out(vf
, fmt
);
602 if(!best
) return 0; // no matching out-fmt
603 flags
=vf_next_query_format(vf
,best
);
604 if(!(flags
&(VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
))) return 0; // huh?
605 if(fmt
!=best
) flags
&=~VFCAP_CSP_SUPPORTED_BY_HW
;
606 // do not allow scaling, if we are before the PP fliter!
607 if(!(flags
&VFCAP_POSTPROC
)) flags
|=VFCAP_SWSCALE
;
610 return 0; // nomatching in-fmt
613 static void uninit(struct vf_instance
*vf
){
614 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
615 if(vf
->priv
->ctx2
) sws_freeContext(vf
->priv
->ctx2
);
616 free(vf
->priv
->palette
);
620 static int vf_open(vf_instance_t
*vf
, char *args
){
622 vf
->start_slice
=start_slice
;
623 vf
->draw_slice
=draw_slice
;
624 vf
->put_image
=put_image
;
625 vf
->query_format
=query_format
;
626 vf
->control
= control
;
628 mp_msg(MSGT_VFILTER
,MSGL_V
,"SwScale params: %d x %d (-1=no scaling)\n",
635 //global sws_flags from the command line
639 static SwsFilter
*src_filter
= NULL
;
641 float sws_lum_gblur
= 0.0;
642 float sws_chr_gblur
= 0.0;
643 int sws_chr_vshift
= 0;
644 int sws_chr_hshift
= 0;
645 float sws_chr_sharpen
= 0.0;
646 float sws_lum_sharpen
= 0.0;
648 int get_sws_cpuflags(void){
650 (gCpuCaps
.hasMMX
? SWS_CPU_CAPS_MMX
: 0)
651 | (gCpuCaps
.hasMMX2
? SWS_CPU_CAPS_MMX2
: 0)
652 | (gCpuCaps
.has3DNow
? SWS_CPU_CAPS_3DNOW
: 0)
653 | (gCpuCaps
.hasAltiVec
? SWS_CPU_CAPS_ALTIVEC
: 0);
656 void sws_getFlagsAndFilterFromCmdLine(int *flags
, SwsFilter
**srcFilterParam
, SwsFilter
**dstFilterParam
)
658 static int firstTime
=1;
663 __asm__
volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
668 *flags
= SWS_PRINT_INFO
;
670 else if( mp_msg_test(MSGT_VFILTER
,MSGL_DBG2
) ) *flags
= SWS_PRINT_INFO
;
672 if(src_filter
) sws_freeFilter(src_filter
);
674 src_filter
= sws_getDefaultFilter(
675 sws_lum_gblur
, sws_chr_gblur
,
676 sws_lum_sharpen
, sws_chr_sharpen
,
677 sws_chr_hshift
, sws_chr_vshift
, verbose
>1);
681 case 0: *flags
|= SWS_FAST_BILINEAR
; break;
682 case 1: *flags
|= SWS_BILINEAR
; break;
683 case 2: *flags
|= SWS_BICUBIC
; break;
684 case 3: *flags
|= SWS_X
; break;
685 case 4: *flags
|= SWS_POINT
; break;
686 case 5: *flags
|= SWS_AREA
; break;
687 case 6: *flags
|= SWS_BICUBLIN
; break;
688 case 7: *flags
|= SWS_GAUSS
; break;
689 case 8: *flags
|= SWS_SINC
; break;
690 case 9: *flags
|= SWS_LANCZOS
; break;
691 case 10:*flags
|= SWS_SPLINE
; break;
692 default:*flags
|= SWS_BILINEAR
; break;
695 *srcFilterParam
= src_filter
;
696 *dstFilterParam
= NULL
;
699 // will use sws_flags & src_filter (from cmd line)
700 struct SwsContext
*sws_getContextFromCmdLine(int srcW
, int srcH
, int srcFormat
, int dstW
, int dstH
, int dstFormat
)
703 SwsFilter
*dstFilterParam
, *srcFilterParam
;
704 enum PixelFormat dfmt
, sfmt
;
706 dfmt
= imgfmt2pixfmt(dstFormat
);
707 sfmt
= imgfmt2pixfmt(srcFormat
);
708 if (srcFormat
== IMGFMT_RGB8
|| srcFormat
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
709 sws_getFlagsAndFilterFromCmdLine(&flags
, &srcFilterParam
, &dstFilterParam
);
711 return sws_getContext(srcW
, srcH
, sfmt
, dstW
, dstH
, dfmt
, flags
| get_sws_cpuflags(), srcFilterParam
, dstFilterParam
, NULL
);
714 /// An example of presets usage
715 static const struct size_preset
{
718 } vf_size_presets_defs
[] = {
719 // TODO add more 'standard' resolutions
720 { "qntsc", 352, 240 },
721 { "qpal", 352, 288 },
722 { "ntsc", 720, 480 },
724 { "sntsc", 640, 480 },
725 { "spal", 768, 576 },
729 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
730 static const m_option_t vf_size_preset_fields
[] = {
731 {"w", ST_OFF(w
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
732 {"h", ST_OFF(h
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
733 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
736 static const m_struct_t vf_size_preset
= {
738 sizeof(struct size_preset
),
740 vf_size_preset_fields
743 static const m_struct_t vf_opts
;
744 static const m_obj_presets_t size_preset
= {
745 &vf_size_preset
, // Input struct desc
746 &vf_opts
, // Output struct desc
747 vf_size_presets_defs
, // The list of presets
748 ST_OFF(name
) // At wich offset is the name field in the preset struct
753 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
754 static const m_option_t vf_opts_fields
[] = {
755 {"w", ST_OFF(w
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
756 {"h", ST_OFF(h
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
757 {"interlaced", ST_OFF(interlaced
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 1, NULL
},
758 {"chr-drop", ST_OFF(v_chr_drop
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 3, NULL
},
759 {"param" , ST_OFF(param
[0]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
760 {"param2", ST_OFF(param
[1]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
761 // Note that here the 2 field is NULL (ie 0)
762 // As we want this option to act on the option struct itself
763 {"presize", 0, CONF_TYPE_OBJ_PRESETS
, 0, 0, 0, (void *)&size_preset
},
764 {"noup", ST_OFF(noup
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 2, NULL
},
765 {"arnd", ST_OFF(accurate_rnd
), CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
766 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
769 static const m_struct_t vf_opts
= {
771 sizeof(struct vf_priv_s
),
776 const vf_info_t vf_info_scale
= {
785 //===========================================================================//