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
[]={
107 // RGB and grayscale (Y8 and Y800):
137 * A list of preferred conversions, in order of preference.
138 * This should be used for conversions that e.g. involve no scaling
139 * or to stop vf_scale from choosing a conversion that has no
140 * fast assembler implementation.
142 static int preferred_conversions
[][2] = {
143 {IMGFMT_YUY2
, IMGFMT_UYVY
},
144 {IMGFMT_YUY2
, IMGFMT_422P
},
145 {IMGFMT_UYVY
, IMGFMT_YUY2
},
146 {IMGFMT_UYVY
, IMGFMT_422P
},
147 {IMGFMT_422P
, IMGFMT_YUY2
},
148 {IMGFMT_422P
, IMGFMT_UYVY
},
149 {IMGFMT_GBRP
, IMGFMT_BGR24
},
150 {IMGFMT_GBRP
, IMGFMT_RGB24
},
151 {IMGFMT_GBRP
, IMGFMT_BGR32
},
152 {IMGFMT_GBRP
, IMGFMT_RGB32
},
156 static unsigned int find_best_out(vf_instance_t
*vf
, int in_format
){
162 // find the best outfmt:
169 while (preferred_conversions
[j
][0] &&
170 preferred_conversions
[j
][0] != in_format
)
172 format
= preferred_conversions
[j
++][1];
173 // switch to standard list
178 format
= outfmt_list
[i
++];
181 ret
= vf_next_query_format(vf
, format
);
183 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"scale: query(%s) -> %d\n",vo_format_name(format
),ret
&3);
184 if(ret
&VFCAP_CSP_SUPPORTED_BY_HW
){
185 best
=format
; // no conversion -> bingo!
188 if(ret
&VFCAP_CSP_SUPPORTED
&& !best
)
189 best
=format
; // best with conversion
194 static int config(struct vf_instance
*vf
,
195 int width
, int height
, int d_width
, int d_height
,
196 unsigned int flags
, unsigned int outfmt
){
197 struct MPOpts
*opts
= vf
->opts
;
198 unsigned int best
=find_best_out(vf
, outfmt
);
201 int round_w
=0, round_h
=0;
203 SwsFilter
*srcFilter
, *dstFilter
;
204 enum PixelFormat dfmt
, sfmt
;
206 vf
->priv
->colorspace
= (struct mp_csp_details
) {0};
209 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"SwScale: no supported outfmt found :(\n");
212 sfmt
= imgfmt2pixfmt(outfmt
);
213 if (outfmt
== IMGFMT_RGB8
|| outfmt
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
214 dfmt
= imgfmt2pixfmt(best
);
216 vo_flags
=vf
->next
->query_format(vf
->next
,best
);
218 vf
->priv
->w
= vf
->priv
->cfg_w
;
219 vf
->priv
->h
= vf
->priv
->cfg_h
;
221 // scaling to dwidth*d_height, if all these TRUE:
223 // - no other sw/hw up/down scaling avail.
224 // - we're after postproc
225 // - user didn't set w:h
226 if(!(vo_flags
&VFCAP_POSTPROC
) && (flags
&VOFLAG_SWSCALE
) &&
227 vf
->priv
->w
<0 && vf
->priv
->h
<0){ // -zoom
228 int x
=(vo_flags
&VFCAP_SWSCALE
) ? 0 : 1;
229 if(d_width
<width
|| d_height
<height
){
231 if(vo_flags
&VFCAP_HWSCALE_DOWN
) x
=0;
234 if(vo_flags
&VFCAP_HWSCALE_UP
) x
=0;
237 // user wants sw scaling! (-zoom)
239 vf
->priv
->h
=d_height
;
244 if((vf
->priv
->w
> width
) + (vf
->priv
->h
> height
) >= vf
->priv
->noup
){
250 if (vf
->priv
->w
<= -8) {
254 if (vf
->priv
->h
<= -8) {
259 if (vf
->priv
->w
< -3 || vf
->priv
->h
< -3 ||
260 (vf
->priv
->w
< -1 && vf
->priv
->h
< -1)) {
261 // TODO: establish a direct connection to the user's brain
262 // and find out what the heck he thinks MPlayer should do
263 // with this nonsense.
264 mp_msg(MSGT_VFILTER
, MSGL_ERR
, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
268 if (vf
->priv
->w
== -1)
270 if (vf
->priv
->w
== 0)
271 vf
->priv
->w
= d_width
;
273 if (vf
->priv
->h
== -1)
274 vf
->priv
->h
= height
;
275 if (vf
->priv
->h
== 0)
276 vf
->priv
->h
= d_height
;
278 if (vf
->priv
->w
== -3)
279 vf
->priv
->w
= vf
->priv
->h
* width
/ height
;
280 if (vf
->priv
->w
== -2)
281 vf
->priv
->w
= vf
->priv
->h
* d_width
/ d_height
;
283 if (vf
->priv
->h
== -3)
284 vf
->priv
->h
= vf
->priv
->w
* height
/ width
;
285 if (vf
->priv
->h
== -2)
286 vf
->priv
->h
= vf
->priv
->w
* d_height
/ d_width
;
289 vf
->priv
->w
= ((vf
->priv
->w
+ 8) / 16) * 16;
291 vf
->priv
->h
= ((vf
->priv
->h
+ 8) / 16) * 16;
293 // calculate the missing parameters:
295 case IMGFMT_YV12
: /* YV12 needs w & h rounded to 2 */
300 vf
->priv
->h
= (vf
->priv
->h
+ 1) & ~1;
301 case IMGFMT_YUY2
: /* YUY2 needs w rounded to 2 */
303 vf
->priv
->w
= (vf
->priv
->w
+ 1) & ~1;
306 mp_msg(MSGT_VFILTER
,MSGL_DBG2
,"SwScale: scaling %dx%d %s to %dx%d %s \n",
307 width
,height
,vo_format_name(outfmt
),
308 vf
->priv
->w
,vf
->priv
->h
,vo_format_name(best
));
311 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
312 if(vf
->priv
->ctx2
)sws_freeContext(vf
->priv
->ctx2
);
315 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags
, &srcFilter
, &dstFilter
);
316 int_sws_flags
|= vf
->priv
->v_chr_drop
<< SWS_SRC_V_CHR_DROP_SHIFT
;
317 int_sws_flags
|= vf
->priv
->accurate_rnd
* SWS_ACCURATE_RND
;
318 vf
->priv
->ctx
=sws_getContext(width
, height
>> vf
->priv
->interlaced
,
320 vf
->priv
->w
, vf
->priv
->h
>> vf
->priv
->interlaced
,
322 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
323 if(vf
->priv
->interlaced
){
324 vf
->priv
->ctx2
=sws_getContext(width
, height
>> 1,
326 vf
->priv
->w
, vf
->priv
->h
>> 1,
328 int_sws_flags
| get_sws_cpuflags(), srcFilter
, dstFilter
, vf
->priv
->param
);
332 mp_msg(MSGT_VFILTER
,MSGL_WARN
,"Couldn't init SwScaler for this setup\n");
337 free(vf
->priv
->palette
);
338 vf
->priv
->palette
=NULL
;
341 /* set 332 palette for 8 bpp */
342 vf
->priv
->palette
=malloc(4*256);
343 for(i
=0; i
<256; i
++){
344 vf
->priv
->palette
[4*i
+0]=4*(i
>>6)*21;
345 vf
->priv
->palette
[4*i
+1]=4*((i
>>3)&7)*9;
346 vf
->priv
->palette
[4*i
+2]=4*((i
&7)&7)*9;
347 vf
->priv
->palette
[4*i
+3]=0;
351 /* set 332 palette for 8 bpp */
352 vf
->priv
->palette
=malloc(4*256);
353 for(i
=0; i
<256; i
++){
354 vf
->priv
->palette
[4*i
+0]=4*(i
&3)*21;
355 vf
->priv
->palette
[4*i
+1]=4*((i
>>2)&7)*9;
356 vf
->priv
->palette
[4*i
+2]=4*((i
>>5)&7)*9;
357 vf
->priv
->palette
[4*i
+3]=0;
362 vf
->priv
->palette
=malloc(4*16);
364 vf
->priv
->palette
[4*i
+0]=4*(i
&1)*63;
365 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
366 vf
->priv
->palette
[4*i
+2]=4*((i
>>3)&1)*63;
367 vf
->priv
->palette
[4*i
+3]=0;
372 vf
->priv
->palette
=malloc(4*16);
374 vf
->priv
->palette
[4*i
+0]=4*(i
>>3)*63;
375 vf
->priv
->palette
[4*i
+1]=4*((i
>>1)&3)*21;
376 vf
->priv
->palette
[4*i
+2]=4*((i
&1)&1)*63;
377 vf
->priv
->palette
[4*i
+3]=0;
382 if (!opts
->screen_size_x
&& !opts
->screen_size_y
383 && !(opts
->screen_size_xy
>= 0.001)) {
384 // Compute new d_width and d_height, preserving aspect
385 // while ensuring that both are >= output size in pixels.
386 if (vf
->priv
->h
* d_width
> vf
->priv
->w
* d_height
) {
387 d_width
= vf
->priv
->h
* d_width
/ d_height
;
388 d_height
= vf
->priv
->h
;
390 d_height
= vf
->priv
->w
* d_height
/ d_width
;
391 d_width
= vf
->priv
->w
;
393 //d_width=d_width*vf->priv->w/width;
394 //d_height=d_height*vf->priv->h/height;
396 return vf_next_config(vf
,vf
->priv
->w
,vf
->priv
->h
,d_width
,d_height
,flags
,best
);
399 static void start_slice(struct vf_instance
*vf
, mp_image_t
*mpi
){
400 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
401 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
)) return; // shouldn't happen
402 // they want slices!!! allocate the buffer.
403 mpi
->priv
=vf
->dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
404 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
405 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
406 vf
->priv
->w
, vf
->priv
->h
);
409 static void scale(struct SwsContext
*sws1
, struct SwsContext
*sws2
, uint8_t *src
[MP_MAX_PLANES
], int src_stride
[MP_MAX_PLANES
],
410 int y
, int h
, uint8_t *dst
[MP_MAX_PLANES
], int dst_stride
[MP_MAX_PLANES
], int interlaced
){
411 const uint8_t *src2
[MP_MAX_PLANES
]={src
[0], src
[1], src
[2], src
[3]};
414 if (src
[1] && !src
[2]){
417 pal2
[i
]= bswap_32(((uint32_t*)src
[1])[i
]);
424 uint8_t *dst2
[MP_MAX_PLANES
]={dst
[0], dst
[1], dst
[2], dst
[3]};
425 int src_stride2
[MP_MAX_PLANES
]={2*src_stride
[0], 2*src_stride
[1], 2*src_stride
[2], 2*src_stride
[3]};
426 int dst_stride2
[MP_MAX_PLANES
]={2*dst_stride
[0], 2*dst_stride
[1], 2*dst_stride
[2], 2*dst_stride
[3]};
428 sws_scale(sws1
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
429 for(i
=0; i
<MP_MAX_PLANES
; i
++){
430 src2
[i
] += src_stride
[i
];
431 dst2
[i
] += dst_stride
[i
];
433 sws_scale(sws2
, src2
, src_stride2
, y
>>1, h
>>1, dst2
, dst_stride2
);
435 sws_scale(sws1
, src2
, src_stride
, y
, h
, dst
, dst_stride
);
439 static void draw_slice(struct vf_instance
*vf
,
440 unsigned char** src
, int* stride
, int w
,int h
, int x
, int y
){
441 mp_image_t
*dmpi
=vf
->dmpi
;
443 mp_msg(MSGT_VFILTER
,MSGL_FATAL
,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
446 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
447 scale(vf
->priv
->ctx
, vf
->priv
->ctx2
, src
, stride
, y
, h
, dmpi
->planes
, dmpi
->stride
, vf
->priv
->interlaced
);
450 static int put_image(struct vf_instance
*vf
, mp_image_t
*mpi
, double pts
){
451 mp_image_t
*dmpi
=mpi
->priv
;
453 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
454 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
456 if(!(mpi
->flags
&MP_IMGFLAG_DRAW_CALLBACK
&& dmpi
)){
458 // hope we'll get DR buffer:
459 dmpi
=vf_get_image(vf
->next
,vf
->priv
->fmt
,
460 MP_IMGTYPE_TEMP
, MP_IMGFLAG_ACCEPT_STRIDE
| MP_IMGFLAG_PREFER_ALIGNED_STRIDE
,
461 vf
->priv
->w
, vf
->priv
->h
);
463 scale(vf
->priv
->ctx
, vf
->priv
->ctx
, mpi
->planes
,mpi
->stride
,0,mpi
->h
,dmpi
->planes
,dmpi
->stride
, vf
->priv
->interlaced
);
466 if(vf
->priv
->w
==mpi
->w
&& vf
->priv
->h
==mpi
->h
){
467 // just conversion, no scaling -> keep postprocessing data
468 // this way we can apply pp filter to non-yv12 source using scaler
469 vf_clone_mpi_attributes(dmpi
, mpi
);
472 if(vf
->priv
->palette
) dmpi
->planes
[1]=vf
->priv
->palette
; // export palette!
474 return vf_next_put_image(vf
,dmpi
, pts
);
477 static int control(struct vf_instance
*vf
, int request
, void* data
){
481 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
486 case VFCTRL_GET_EQUALIZER
:
487 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
491 if (!strcmp(eq
->item
,"brightness")) {
492 eq
->value
= ((brightness
*100) + (1<<15))>>16;
494 else if (!strcmp(eq
->item
,"contrast")) {
495 eq
->value
= (((contrast
*100) + (1<<15))>>16) - 100;
497 else if (!strcmp(eq
->item
,"saturation")) {
498 eq
->value
= (((saturation
*100) + (1<<15))>>16) - 100;
503 case VFCTRL_SET_EQUALIZER
:
504 r
= sws_getColorspaceDetails(vf
->priv
->ctx
, &inv_table
, &srcRange
, &table
, &dstRange
, &brightness
, &contrast
, &saturation
);
506 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
509 if (!strcmp(eq
->item
,"brightness")) {
510 brightness
= (( eq
->value
<<16) + 50)/100;
512 else if (!strcmp(eq
->item
,"contrast")) {
513 contrast
= (((eq
->value
+100)<<16) + 50)/100;
515 else if (!strcmp(eq
->item
,"saturation")) {
516 saturation
= (((eq
->value
+100)<<16) + 50)/100;
521 r
= sws_setColorspaceDetails(vf
->priv
->ctx
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
524 r
= sws_setColorspaceDetails(vf
->priv
->ctx2
, inv_table
, srcRange
, table
, dstRange
, brightness
, contrast
, saturation
);
529 case VFCTRL_SET_YUV_COLORSPACE
: {
530 struct mp_csp_details colorspace
= *(struct mp_csp_details
*)data
;
531 if (mp_sws_set_colorspace(vf
->priv
->ctx
, &colorspace
) >= 0) {
533 mp_sws_set_colorspace(vf
->priv
->ctx2
, &colorspace
);
534 vf
->priv
->colorspace
= colorspace
;
539 case VFCTRL_GET_YUV_COLORSPACE
: {
540 /* This scale filter should never react to colorspace commands if it
541 * doesn't do YUV->RGB conversion. But because finding out whether this
542 * is really YUV->RGB (and not YUV->YUV or anything else) is hard,
543 * react only if the colorspace has been set explicitly before. The
544 * trick is that mp_sws_set_colorspace does not succeed for YUV->YUV
545 * and RGB->YUV conversions, which makes this code correct in "most"
546 * cases. (This would be trivial to do correctly if libswscale exposed
547 * functionality like isYUV()).
549 if (vf
->priv
->colorspace
.format
) {
550 *(struct mp_csp_details
*)data
= vf
->priv
->colorspace
;
559 return vf_next_control(vf
,request
,data
);
562 static const int mp_csp_to_swscale
[MP_CSP_COUNT
] = {
563 [MP_CSP_BT_601
] = SWS_CS_ITU601
,
564 [MP_CSP_BT_709
] = SWS_CS_ITU709
,
565 [MP_CSP_SMPTE_240M
] = SWS_CS_SMPTE240M
,
568 // Adjust the colorspace used for YUV->RGB conversion. On other conversions,
569 // do nothing or return an error.
570 // The csp argument is set to the supported values.
571 // Return 0 on success and -1 on error.
572 int mp_sws_set_colorspace(struct SwsContext
*sws
, struct mp_csp_details
*csp
)
574 int *table
, *inv_table
;
575 int brightness
, contrast
, saturation
, srcRange
, dstRange
;
577 csp
->levels_out
= MP_CSP_LEVELS_PC
;
579 // NOTE: returns an error if the destination format is YUV
580 if (sws_getColorspaceDetails(sws
, &inv_table
, &srcRange
, &table
, &dstRange
,
581 &brightness
, &contrast
, &saturation
) == -1)
584 int sws_csp
= mp_csp_to_swscale
[csp
->format
];
586 // colorspace not supported, go with a reasonable default
587 csp
->format
= SWS_CS_ITU601
;
588 sws_csp
= MP_CSP_BT_601
;
591 /* The swscale API for these is hardly documented.
592 * Apparently table/range only apply to YUV. Thus dstRange has no effect
593 * for YUV->RGB conversions, and conversions to limited-range RGB are
596 srcRange
= csp
->levels_in
== MP_CSP_LEVELS_PC
;
597 const int *new_inv_table
= sws_getCoefficients(sws_csp
);
599 if (sws_setColorspaceDetails(sws
, new_inv_table
, srcRange
, table
, dstRange
,
600 brightness
, contrast
, saturation
) == -1)
606 *csp
= (struct mp_csp_details
){0};
610 //===========================================================================//
612 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
614 static int query_format(struct vf_instance
*vf
, unsigned int fmt
){
615 if (!IMGFMT_IS_HWACCEL(fmt
) && imgfmt2pixfmt(fmt
) != PIX_FMT_NONE
) {
616 unsigned int best
=find_best_out(vf
, fmt
);
618 if(!best
) return 0; // no matching out-fmt
619 flags
=vf_next_query_format(vf
,best
);
620 if(!(flags
&(VFCAP_CSP_SUPPORTED
|VFCAP_CSP_SUPPORTED_BY_HW
))) return 0; // huh?
621 if(fmt
!=best
) flags
&=~VFCAP_CSP_SUPPORTED_BY_HW
;
622 // do not allow scaling, if we are before the PP fliter!
623 if(!(flags
&VFCAP_POSTPROC
)) flags
|=VFCAP_SWSCALE
;
626 return 0; // nomatching in-fmt
629 static void uninit(struct vf_instance
*vf
){
630 if(vf
->priv
->ctx
) sws_freeContext(vf
->priv
->ctx
);
631 if(vf
->priv
->ctx2
) sws_freeContext(vf
->priv
->ctx2
);
632 free(vf
->priv
->palette
);
636 static int vf_open(vf_instance_t
*vf
, char *args
){
638 vf
->start_slice
=start_slice
;
639 vf
->draw_slice
=draw_slice
;
640 vf
->put_image
=put_image
;
641 vf
->query_format
=query_format
;
642 vf
->control
= control
;
644 mp_msg(MSGT_VFILTER
,MSGL_V
,"SwScale params: %d x %d (-1=no scaling)\n",
651 //global sws_flags from the command line
655 static SwsFilter
*src_filter
= NULL
;
657 float sws_lum_gblur
= 0.0;
658 float sws_chr_gblur
= 0.0;
659 int sws_chr_vshift
= 0;
660 int sws_chr_hshift
= 0;
661 float sws_chr_sharpen
= 0.0;
662 float sws_lum_sharpen
= 0.0;
664 int get_sws_cpuflags(void){
666 (gCpuCaps
.hasMMX
? SWS_CPU_CAPS_MMX
: 0)
667 | (gCpuCaps
.hasMMX2
? SWS_CPU_CAPS_MMX2
: 0)
668 | (gCpuCaps
.has3DNow
? SWS_CPU_CAPS_3DNOW
: 0)
669 | (gCpuCaps
.hasAltiVec
? SWS_CPU_CAPS_ALTIVEC
: 0);
672 void sws_getFlagsAndFilterFromCmdLine(int *flags
, SwsFilter
**srcFilterParam
, SwsFilter
**dstFilterParam
)
674 static int firstTime
=1;
679 __asm__
volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
684 *flags
= SWS_PRINT_INFO
;
686 else if( mp_msg_test(MSGT_VFILTER
,MSGL_DBG2
) ) *flags
= SWS_PRINT_INFO
;
688 if(src_filter
) sws_freeFilter(src_filter
);
690 src_filter
= sws_getDefaultFilter(
691 sws_lum_gblur
, sws_chr_gblur
,
692 sws_lum_sharpen
, sws_chr_sharpen
,
693 sws_chr_hshift
, sws_chr_vshift
, verbose
>1);
697 case 0: *flags
|= SWS_FAST_BILINEAR
; break;
698 case 1: *flags
|= SWS_BILINEAR
; break;
699 case 2: *flags
|= SWS_BICUBIC
; break;
700 case 3: *flags
|= SWS_X
; break;
701 case 4: *flags
|= SWS_POINT
; break;
702 case 5: *flags
|= SWS_AREA
; break;
703 case 6: *flags
|= SWS_BICUBLIN
; break;
704 case 7: *flags
|= SWS_GAUSS
; break;
705 case 8: *flags
|= SWS_SINC
; break;
706 case 9: *flags
|= SWS_LANCZOS
; break;
707 case 10:*flags
|= SWS_SPLINE
; break;
708 default:*flags
|= SWS_BILINEAR
; break;
711 *srcFilterParam
= src_filter
;
712 *dstFilterParam
= NULL
;
715 // will use sws_flags & src_filter (from cmd line)
716 static struct SwsContext
*sws_getContextFromCmdLine2(int srcW
, int srcH
, int srcFormat
, int dstW
, int dstH
, int dstFormat
, int extraflags
)
719 SwsFilter
*dstFilterParam
, *srcFilterParam
;
720 enum PixelFormat dfmt
, sfmt
;
722 dfmt
= imgfmt2pixfmt(dstFormat
);
723 sfmt
= imgfmt2pixfmt(srcFormat
);
724 if (srcFormat
== IMGFMT_RGB8
|| srcFormat
== IMGFMT_BGR8
) sfmt
= PIX_FMT_PAL8
;
725 sws_getFlagsAndFilterFromCmdLine(&flags
, &srcFilterParam
, &dstFilterParam
);
727 return sws_getContext(srcW
, srcH
, sfmt
, dstW
, dstH
, dfmt
, flags
| extraflags
| get_sws_cpuflags(), srcFilterParam
, dstFilterParam
, NULL
);
730 struct SwsContext
*sws_getContextFromCmdLine(int srcW
, int srcH
, int srcFormat
, int dstW
, int dstH
, int dstFormat
)
732 return sws_getContextFromCmdLine2(srcW
, srcH
, srcFormat
, dstW
, dstH
, dstFormat
, 0);
735 /* These extra flags improve the image visibly in some cases, but also
736 * make conversion a lot slower. For some reason SWS_FULL_CHR_H_INT
737 * also seems to make the overall image slightly brighter.
739 struct SwsContext
*sws_getContextFromCmdLine_hq(int srcW
, int srcH
,
740 int srcFormat
, int dstW
, int dstH
, int dstFormat
)
742 return sws_getContextFromCmdLine2(srcW
, srcH
, srcFormat
,
743 dstW
, dstH
, dstFormat
,
744 SWS_FULL_CHR_H_INT
| SWS_ACCURATE_RND
);
747 /// An example of presets usage
748 static const struct size_preset
{
751 } vf_size_presets_defs
[] = {
752 // TODO add more 'standard' resolutions
753 { "qntsc", 352, 240 },
754 { "qpal", 352, 288 },
755 { "ntsc", 720, 480 },
757 { "sntsc", 640, 480 },
758 { "spal", 768, 576 },
762 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
763 static const m_option_t vf_size_preset_fields
[] = {
764 {"w", ST_OFF(w
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
765 {"h", ST_OFF(h
), CONF_TYPE_INT
, M_OPT_MIN
,1 ,0, NULL
},
766 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
769 static const m_struct_t vf_size_preset
= {
771 sizeof(struct size_preset
),
773 vf_size_preset_fields
776 static const m_struct_t vf_opts
;
777 static const m_obj_presets_t size_preset
= {
778 &vf_size_preset
, // Input struct desc
779 &vf_opts
, // Output struct desc
780 vf_size_presets_defs
, // The list of presets
781 ST_OFF(name
) // At wich offset is the name field in the preset struct
786 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
787 static const m_option_t vf_opts_fields
[] = {
788 {"w", ST_OFF(cfg_w
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
789 {"h", ST_OFF(cfg_h
), CONF_TYPE_INT
, M_OPT_MIN
,-11,0, NULL
},
790 {"interlaced", ST_OFF(interlaced
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 1, NULL
},
791 {"chr-drop", ST_OFF(v_chr_drop
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 3, NULL
},
792 {"param" , ST_OFF(param
[0]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
793 {"param2", ST_OFF(param
[1]), CONF_TYPE_DOUBLE
, M_OPT_RANGE
, 0.0, 100.0, NULL
},
794 // Note that here the 2 field is NULL (ie 0)
795 // As we want this option to act on the option struct itself
796 {"presize", 0, CONF_TYPE_OBJ_PRESETS
, 0, 0, 0, (void *)&size_preset
},
797 {"noup", ST_OFF(noup
), CONF_TYPE_INT
, M_OPT_RANGE
, 0, 2, NULL
},
798 {"arnd", ST_OFF(accurate_rnd
), CONF_TYPE_FLAG
, 0, 0, 1, NULL
},
799 { NULL
, NULL
, 0, 0, 0, 0, NULL
}
802 static const m_struct_t vf_opts
= {
804 sizeof(struct vf_priv_s
),
809 const vf_info_t vf_info_scale
= {
818 //===========================================================================//