etc/mplayer.desktop: revise desktop file
[mplayer.git] / libmpcodecs / vf_scale.c
blob1a2cb28e94c0e0132afa0dc9a2934dce1e4164e9
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_444P10_LE,
72 IMGFMT_444P10_BE,
73 IMGFMT_444P9_LE,
74 IMGFMT_444P9_BE,
75 IMGFMT_422P,
76 IMGFMT_422P16_LE,
77 IMGFMT_422P16_BE,
78 IMGFMT_422P10_LE,
79 IMGFMT_422P10_BE,
80 IMGFMT_YV12,
81 IMGFMT_I420,
82 IMGFMT_420P16_LE,
83 IMGFMT_420P16_BE,
84 IMGFMT_420P10_LE,
85 IMGFMT_420P10_BE,
86 IMGFMT_420P9_LE,
87 IMGFMT_420P9_BE,
88 IMGFMT_420A,
89 IMGFMT_IYUV,
90 IMGFMT_YVU9,
91 IMGFMT_IF09,
92 IMGFMT_411P,
93 IMGFMT_NV12,
94 IMGFMT_NV21,
95 IMGFMT_YUY2,
96 IMGFMT_UYVY,
97 IMGFMT_440P,
98 // RGB and grayscale (Y8 and Y800):
99 IMGFMT_BGR32,
100 IMGFMT_RGB32,
101 IMGFMT_BGR24,
102 IMGFMT_RGB24,
103 IMGFMT_RGB48LE,
104 IMGFMT_RGB48BE,
105 IMGFMT_BGR16,
106 IMGFMT_RGB16,
107 IMGFMT_BGR15,
108 IMGFMT_RGB15,
109 IMGFMT_BGR12,
110 IMGFMT_RGB12,
111 IMGFMT_Y800,
112 IMGFMT_Y8,
113 IMGFMT_BGR8,
114 IMGFMT_RGB8,
115 IMGFMT_BGR4,
116 IMGFMT_RGB4,
117 IMGFMT_BG4B,
118 IMGFMT_RG4B,
119 IMGFMT_BGR1,
120 IMGFMT_RGB1,
125 * A list of preferred conversions, in order of preference.
126 * This should be used for conversions that e.g. involve no scaling
127 * or to stop vf_scale from choosing a conversion that has no
128 * fast assembler implementation.
130 static int preferred_conversions[][2] = {
131 {IMGFMT_YUY2, IMGFMT_UYVY},
132 {IMGFMT_YUY2, IMGFMT_422P},
133 {IMGFMT_UYVY, IMGFMT_YUY2},
134 {IMGFMT_UYVY, IMGFMT_422P},
135 {IMGFMT_422P, IMGFMT_YUY2},
136 {IMGFMT_422P, IMGFMT_UYVY},
137 {0, 0}
140 static unsigned int find_best_out(vf_instance_t *vf, int in_format){
141 unsigned int best=0;
142 int i = -1;
143 int j = -1;
144 int format = 0;
146 // find the best outfmt:
147 while (1) {
148 int ret;
149 if (j < 0) {
150 format = in_format;
151 j = 0;
152 } else if (i < 0) {
153 while (preferred_conversions[j][0] &&
154 preferred_conversions[j][0] != in_format)
155 j++;
156 format = preferred_conversions[j++][1];
157 // switch to standard list
158 if (!format)
159 i = 0;
161 if (i >= 0)
162 format = outfmt_list[i++];
163 if (!format)
164 break;
165 ret = vf_next_query_format(vf, format);
167 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
168 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
169 best=format; // no conversion -> bingo!
170 break;
172 if(ret&VFCAP_CSP_SUPPORTED && !best)
173 best=format; // best with conversion
175 return best;
178 static int config(struct vf_instance *vf,
179 int width, int height, int d_width, int d_height,
180 unsigned int flags, unsigned int outfmt){
181 struct MPOpts *opts = vf->opts;
182 unsigned int best=find_best_out(vf, outfmt);
183 int vo_flags;
184 int int_sws_flags=0;
185 int round_w=0, round_h=0;
186 int i;
187 SwsFilter *srcFilter, *dstFilter;
188 enum PixelFormat dfmt, sfmt;
190 if(!best){
191 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
192 return 0;
194 sfmt = imgfmt2pixfmt(outfmt);
195 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
196 dfmt = imgfmt2pixfmt(best);
198 vo_flags=vf->next->query_format(vf->next,best);
200 // scaling to dwidth*d_height, if all these TRUE:
201 // - option -zoom
202 // - no other sw/hw up/down scaling avail.
203 // - we're after postproc
204 // - user didn't set w:h
205 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
206 vf->priv->w<0 && vf->priv->h<0){ // -zoom
207 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
208 if(d_width<width || d_height<height){
209 // downscale!
210 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
211 } else {
212 // upscale:
213 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
215 if(x){
216 // user wants sw scaling! (-zoom)
217 vf->priv->w=d_width;
218 vf->priv->h=d_height;
222 if(vf->priv->noup){
223 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
224 vf->priv->w= width;
225 vf->priv->h= height;
229 if (vf->priv->w <= -8) {
230 vf->priv->w += 8;
231 round_w = 1;
233 if (vf->priv->h <= -8) {
234 vf->priv->h += 8;
235 round_h = 1;
238 if (vf->priv->w < -3 || vf->priv->h < -3 ||
239 (vf->priv->w < -1 && vf->priv->h < -1)) {
240 // TODO: establish a direct connection to the user's brain
241 // and find out what the heck he thinks MPlayer should do
242 // with this nonsense.
243 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
244 return 0;
247 if (vf->priv->w == -1)
248 vf->priv->w = width;
249 if (vf->priv->w == 0)
250 vf->priv->w = d_width;
252 if (vf->priv->h == -1)
253 vf->priv->h = height;
254 if (vf->priv->h == 0)
255 vf->priv->h = d_height;
257 if (vf->priv->w == -3)
258 vf->priv->w = vf->priv->h * width / height;
259 if (vf->priv->w == -2)
260 vf->priv->w = vf->priv->h * d_width / d_height;
262 if (vf->priv->h == -3)
263 vf->priv->h = vf->priv->w * height / width;
264 if (vf->priv->h == -2)
265 vf->priv->h = vf->priv->w * d_height / d_width;
267 if (round_w)
268 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
269 if (round_h)
270 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
272 // calculate the missing parameters:
273 switch(best) {
274 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
275 case IMGFMT_I420:
276 case IMGFMT_IYUV:
277 case IMGFMT_NV12:
278 case IMGFMT_NV21:
279 vf->priv->h = (vf->priv->h + 1) & ~1;
280 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
281 case IMGFMT_UYVY:
282 vf->priv->w = (vf->priv->w + 1) & ~1;
285 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
286 width,height,vo_format_name(outfmt),
287 vf->priv->w,vf->priv->h,vo_format_name(best));
289 // free old ctx:
290 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
291 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
293 // new swscaler:
294 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
295 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
296 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
297 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
298 sfmt,
299 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
300 dfmt,
301 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
302 if(vf->priv->interlaced){
303 vf->priv->ctx2=sws_getContext(width, height >> 1,
304 sfmt,
305 vf->priv->w, vf->priv->h >> 1,
306 dfmt,
307 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
309 if(!vf->priv->ctx){
310 // error...
311 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
312 return 0;
314 vf->priv->fmt=best;
316 free(vf->priv->palette);
317 vf->priv->palette=NULL;
318 switch(best){
319 case IMGFMT_RGB8: {
320 /* set 332 palette for 8 bpp */
321 vf->priv->palette=malloc(4*256);
322 for(i=0; i<256; i++){
323 vf->priv->palette[4*i+0]=4*(i>>6)*21;
324 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
325 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
326 vf->priv->palette[4*i+3]=0;
328 break; }
329 case IMGFMT_BGR8: {
330 /* set 332 palette for 8 bpp */
331 vf->priv->palette=malloc(4*256);
332 for(i=0; i<256; i++){
333 vf->priv->palette[4*i+0]=4*(i&3)*21;
334 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
335 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
336 vf->priv->palette[4*i+3]=0;
338 break; }
339 case IMGFMT_BGR4:
340 case IMGFMT_BG4B: {
341 vf->priv->palette=malloc(4*16);
342 for(i=0; i<16; i++){
343 vf->priv->palette[4*i+0]=4*(i&1)*63;
344 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
345 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
346 vf->priv->palette[4*i+3]=0;
348 break; }
349 case IMGFMT_RGB4:
350 case IMGFMT_RG4B: {
351 vf->priv->palette=malloc(4*16);
352 for(i=0; i<16; i++){
353 vf->priv->palette[4*i+0]=4*(i>>3)*63;
354 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
355 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
356 vf->priv->palette[4*i+3]=0;
358 break; }
361 if (!opts->screen_size_x && !opts->screen_size_y
362 && !(opts->screen_size_xy >= 0.001)) {
363 // Compute new d_width and d_height, preserving aspect
364 // while ensuring that both are >= output size in pixels.
365 if (vf->priv->h * d_width > vf->priv->w * d_height) {
366 d_width = vf->priv->h * d_width / d_height;
367 d_height = vf->priv->h;
368 } else {
369 d_height = vf->priv->w * d_height / d_width;
370 d_width = vf->priv->w;
372 //d_width=d_width*vf->priv->w/width;
373 //d_height=d_height*vf->priv->h/height;
375 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
378 static void start_slice(struct vf_instance *vf, mp_image_t *mpi){
379 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
380 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
381 // they want slices!!! allocate the buffer.
382 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
383 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
384 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
385 vf->priv->w, vf->priv->h);
388 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
389 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
390 const uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
391 #if HAVE_BIGENDIAN
392 uint32_t pal2[256];
393 if (src[1] && !src[2]){
394 int i;
395 for(i=0; i<256; i++)
396 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
397 src2[1]= pal2;
399 #endif
401 if(interlaced){
402 int i;
403 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
404 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
405 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
407 sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
408 for(i=0; i<MP_MAX_PLANES; i++){
409 src2[i] += src_stride[i];
410 dst2[i] += dst_stride[i];
412 sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
413 }else{
414 sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
418 static void draw_slice(struct vf_instance *vf,
419 unsigned char** src, int* stride, int w,int h, int x, int y){
420 mp_image_t *dmpi=vf->dmpi;
421 if(!dmpi){
422 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
423 return;
425 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
426 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
429 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
430 mp_image_t *dmpi=mpi->priv;
432 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
433 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
435 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
437 // hope we'll get DR buffer:
438 dmpi=vf_get_image(vf->next,vf->priv->fmt,
439 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
440 vf->priv->w, vf->priv->h);
442 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
445 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
446 // just conversion, no scaling -> keep postprocessing data
447 // this way we can apply pp filter to non-yv12 source using scaler
448 vf_clone_mpi_attributes(dmpi, mpi);
451 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
453 return vf_next_put_image(vf,dmpi, pts);
456 static int control(struct vf_instance *vf, int request, void* data){
457 int *table;
458 int *inv_table;
459 int r;
460 int brightness, contrast, saturation, srcRange, dstRange;
461 vf_equalizer_t *eq;
463 if(vf->priv->ctx)
464 switch(request){
465 case VFCTRL_GET_EQUALIZER:
466 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
467 if(r<0) break;
469 eq = data;
470 if (!strcmp(eq->item,"brightness")) {
471 eq->value = ((brightness*100) + (1<<15))>>16;
473 else if (!strcmp(eq->item,"contrast")) {
474 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
476 else if (!strcmp(eq->item,"saturation")) {
477 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
479 else
480 break;
481 return CONTROL_TRUE;
482 case VFCTRL_SET_EQUALIZER:
483 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
484 if(r<0) break;
485 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
486 eq = data;
488 if (!strcmp(eq->item,"brightness")) {
489 brightness = (( eq->value <<16) + 50)/100;
491 else if (!strcmp(eq->item,"contrast")) {
492 contrast = (((eq->value+100)<<16) + 50)/100;
494 else if (!strcmp(eq->item,"saturation")) {
495 saturation = (((eq->value+100)<<16) + 50)/100;
497 else
498 break;
500 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
501 if(r<0) break;
502 if(vf->priv->ctx2){
503 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
504 if(r<0) break;
507 return CONTROL_TRUE;
508 default:
509 break;
512 return vf_next_control(vf,request,data);
515 //===========================================================================//
517 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
519 static int query_format(struct vf_instance *vf, unsigned int fmt){
520 if (!IMGFMT_IS_HWACCEL(fmt) && imgfmt2pixfmt(fmt) != PIX_FMT_NONE) {
521 unsigned int best=find_best_out(vf, fmt);
522 int flags;
523 if(!best) return 0; // no matching out-fmt
524 flags=vf_next_query_format(vf,best);
525 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
526 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
527 // do not allow scaling, if we are before the PP fliter!
528 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
529 return flags;
531 return 0; // nomatching in-fmt
534 static void uninit(struct vf_instance *vf){
535 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
536 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
537 free(vf->priv->palette);
538 free(vf->priv);
541 static int vf_open(vf_instance_t *vf, char *args){
542 vf->config=config;
543 vf->start_slice=start_slice;
544 vf->draw_slice=draw_slice;
545 vf->put_image=put_image;
546 vf->query_format=query_format;
547 vf->control= control;
548 vf->uninit=uninit;
549 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
550 vf->priv->w,
551 vf->priv->h);
553 return 1;
556 //global sws_flags from the command line
557 int sws_flags=2;
559 //global srcFilter
560 static SwsFilter *src_filter= NULL;
562 float sws_lum_gblur= 0.0;
563 float sws_chr_gblur= 0.0;
564 int sws_chr_vshift= 0;
565 int sws_chr_hshift= 0;
566 float sws_chr_sharpen= 0.0;
567 float sws_lum_sharpen= 0.0;
569 int get_sws_cpuflags(void){
570 return
571 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
572 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
573 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
574 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
577 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
579 static int firstTime=1;
580 *flags=0;
582 #if ARCH_X86
583 if(gCpuCaps.hasMMX)
584 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
585 #endif
586 if(firstTime)
588 firstTime=0;
589 *flags= SWS_PRINT_INFO;
591 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
593 if(src_filter) sws_freeFilter(src_filter);
595 src_filter= sws_getDefaultFilter(
596 sws_lum_gblur, sws_chr_gblur,
597 sws_lum_sharpen, sws_chr_sharpen,
598 sws_chr_hshift, sws_chr_vshift, verbose>1);
600 switch(sws_flags)
602 case 0: *flags|= SWS_FAST_BILINEAR; break;
603 case 1: *flags|= SWS_BILINEAR; break;
604 case 2: *flags|= SWS_BICUBIC; break;
605 case 3: *flags|= SWS_X; break;
606 case 4: *flags|= SWS_POINT; break;
607 case 5: *flags|= SWS_AREA; break;
608 case 6: *flags|= SWS_BICUBLIN; break;
609 case 7: *flags|= SWS_GAUSS; break;
610 case 8: *flags|= SWS_SINC; break;
611 case 9: *flags|= SWS_LANCZOS; break;
612 case 10:*flags|= SWS_SPLINE; break;
613 default:*flags|= SWS_BILINEAR; break;
616 *srcFilterParam= src_filter;
617 *dstFilterParam= NULL;
620 // will use sws_flags & src_filter (from cmd line)
621 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
623 int flags;
624 SwsFilter *dstFilterParam, *srcFilterParam;
625 enum PixelFormat dfmt, sfmt;
627 dfmt = imgfmt2pixfmt(dstFormat);
628 sfmt = imgfmt2pixfmt(srcFormat);
629 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
630 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
632 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
635 /// An example of presets usage
636 static const struct size_preset {
637 char* name;
638 int w, h;
639 } vf_size_presets_defs[] = {
640 // TODO add more 'standard' resolutions
641 { "qntsc", 352, 240 },
642 { "qpal", 352, 288 },
643 { "ntsc", 720, 480 },
644 { "pal", 720, 576 },
645 { "sntsc", 640, 480 },
646 { "spal", 768, 576 },
647 { NULL, 0, 0}
650 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
651 static const m_option_t vf_size_preset_fields[] = {
652 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
653 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
654 { NULL, NULL, 0, 0, 0, 0, NULL }
657 static const m_struct_t vf_size_preset = {
658 "scale_size_preset",
659 sizeof(struct size_preset),
660 NULL,
661 vf_size_preset_fields
664 static const m_struct_t vf_opts;
665 static const m_obj_presets_t size_preset = {
666 &vf_size_preset, // Input struct desc
667 &vf_opts, // Output struct desc
668 vf_size_presets_defs, // The list of presets
669 ST_OFF(name) // At wich offset is the name field in the preset struct
672 /// Now the options
673 #undef ST_OFF
674 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
675 static const m_option_t vf_opts_fields[] = {
676 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
677 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
678 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
679 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
680 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
681 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
682 // Note that here the 2 field is NULL (ie 0)
683 // As we want this option to act on the option struct itself
684 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, (void *)&size_preset},
685 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
686 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
687 { NULL, NULL, 0, 0, 0, 0, NULL }
690 static const m_struct_t vf_opts = {
691 "scale",
692 sizeof(struct vf_priv_s),
693 &vf_priv_dflt,
694 vf_opts_fields
697 const vf_info_t vf_info_scale = {
698 "software scaling",
699 "scale",
700 "A'rpi",
702 vf_open,
703 &vf_opts
706 //===========================================================================//