Remove the internal GUI
[mplayer/glamo.git] / libmpcodecs / vf_scale.c
blobf1388fb1b00fb6d55bebec738df93b9cb5ab3f67
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <inttypes.h>
6 #include "config.h"
7 #include "mp_msg.h"
8 #include "cpudetect.h"
9 #include "options.h"
11 #include "img_format.h"
12 #include "mp_image.h"
13 #include "vf.h"
14 #include "fmt-conversion.h"
15 #include "mpbswap.h"
17 #include "libswscale/swscale.h"
18 #include "vf_scale.h"
20 #include "m_option.h"
21 #include "m_struct.h"
23 static struct vf_priv_s {
24 int w,h;
25 int v_chr_drop;
26 double param[2];
27 unsigned int fmt;
28 struct SwsContext *ctx;
29 struct SwsContext *ctx2; //for interlaced slices only
30 unsigned char* palette;
31 int interlaced;
32 int noup;
33 int accurate_rnd;
34 int query_format_cache[64];
35 } const vf_priv_dflt = {
36 -1,-1,
38 {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
40 NULL,
41 NULL,
42 NULL
45 //===========================================================================//
47 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
49 static const unsigned int outfmt_list[]={
50 // YUV:
51 IMGFMT_444P,
52 IMGFMT_422P,
53 IMGFMT_YV12,
54 IMGFMT_I420,
55 IMGFMT_IYUV,
56 IMGFMT_YVU9,
57 IMGFMT_IF09,
58 IMGFMT_411P,
59 IMGFMT_NV12,
60 IMGFMT_NV21,
61 IMGFMT_YUY2,
62 IMGFMT_UYVY,
63 // RGB and grayscale (Y8 and Y800):
64 IMGFMT_BGR32,
65 IMGFMT_RGB32,
66 IMGFMT_BGR24,
67 IMGFMT_RGB24,
68 IMGFMT_BGR16,
69 IMGFMT_RGB16,
70 IMGFMT_BGR15,
71 IMGFMT_RGB15,
72 IMGFMT_Y800,
73 IMGFMT_Y8,
74 IMGFMT_BGR8,
75 IMGFMT_RGB8,
76 IMGFMT_BGR4,
77 IMGFMT_RGB4,
78 IMGFMT_BG4B,
79 IMGFMT_RG4B,
80 IMGFMT_BGR1,
81 IMGFMT_RGB1,
85 static unsigned int find_best_out(vf_instance_t *vf){
86 unsigned int best=0;
87 int i;
89 // find the best outfmt:
90 for(i=0; i<sizeof(outfmt_list)/sizeof(int)-1; i++){
91 const int format= outfmt_list[i];
92 int ret= vf->priv->query_format_cache[i]-1;
93 if(ret == -1){
94 ret= vf_next_query_format(vf, outfmt_list[i]);
95 vf->priv->query_format_cache[i]= ret+1;
98 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
99 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
100 best=format; // no conversion -> bingo!
101 break;
103 if(ret&VFCAP_CSP_SUPPORTED && !best)
104 best=format; // best with conversion
106 return best;
109 static int config(struct vf_instance* vf,
110 int width, int height, int d_width, int d_height,
111 unsigned int flags, unsigned int outfmt){
112 struct MPOpts *opts = vf->opts;
113 unsigned int best=find_best_out(vf);
114 int vo_flags;
115 int int_sws_flags=0;
116 int round_w=0, round_h=0;
117 int i;
118 SwsFilter *srcFilter, *dstFilter;
119 enum PixelFormat dfmt, sfmt;
121 if(!best){
122 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
123 return 0;
125 sfmt = imgfmt2pixfmt(outfmt);
126 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
127 dfmt = imgfmt2pixfmt(best);
129 vo_flags=vf->next->query_format(vf->next,best);
131 // scaling to dwidth*d_height, if all these TRUE:
132 // - option -zoom
133 // - no other sw/hw up/down scaling avail.
134 // - we're after postproc
135 // - user didn't set w:h
136 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
137 vf->priv->w<0 && vf->priv->h<0){ // -zoom
138 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
139 if(d_width<width || d_height<height){
140 // downscale!
141 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
142 } else {
143 // upscale:
144 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
146 if(x){
147 // user wants sw scaling! (-zoom)
148 vf->priv->w=d_width;
149 vf->priv->h=d_height;
153 if(vf->priv->noup){
154 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
155 vf->priv->w= width;
156 vf->priv->h= height;
160 if (vf->priv->w <= -8) {
161 vf->priv->w += 8;
162 round_w = 1;
164 if (vf->priv->h <= -8) {
165 vf->priv->h += 8;
166 round_h = 1;
169 if (vf->priv->w < -3 || vf->priv->h < -3 ||
170 (vf->priv->w < -1 && vf->priv->h < -1)) {
171 // TODO: establish a direct connection to the user's brain
172 // and find out what the heck he thinks MPlayer should do
173 // with this nonsense.
174 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
175 return 0;
178 if (vf->priv->w == -1)
179 vf->priv->w = width;
180 if (vf->priv->w == 0)
181 vf->priv->w = d_width;
183 if (vf->priv->h == -1)
184 vf->priv->h = height;
185 if (vf->priv->h == 0)
186 vf->priv->h = d_height;
188 if (vf->priv->w == -3)
189 vf->priv->w = vf->priv->h * width / height;
190 if (vf->priv->w == -2)
191 vf->priv->w = vf->priv->h * d_width / d_height;
193 if (vf->priv->h == -3)
194 vf->priv->h = vf->priv->w * height / width;
195 if (vf->priv->h == -2)
196 vf->priv->h = vf->priv->w * d_height / d_width;
198 if (round_w)
199 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
200 if (round_h)
201 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
203 // calculate the missing parameters:
204 switch(best) {
205 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
206 case IMGFMT_I420:
207 case IMGFMT_IYUV:
208 case IMGFMT_NV12:
209 case IMGFMT_NV21:
210 vf->priv->h = (vf->priv->h + 1) & ~1;
211 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
212 case IMGFMT_UYVY:
213 vf->priv->w = (vf->priv->w + 1) & ~1;
216 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
217 width,height,vo_format_name(outfmt),
218 vf->priv->w,vf->priv->h,vo_format_name(best));
220 // free old ctx:
221 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
222 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
224 // new swscaler:
225 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
226 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
227 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
228 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
229 sfmt,
230 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
231 dfmt,
232 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
233 if(vf->priv->interlaced){
234 vf->priv->ctx2=sws_getContext(width, height >> 1,
235 sfmt,
236 vf->priv->w, vf->priv->h >> 1,
237 dfmt,
238 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
240 if(!vf->priv->ctx){
241 // error...
242 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
243 return 0;
245 vf->priv->fmt=best;
247 if(vf->priv->palette){
248 free(vf->priv->palette);
249 vf->priv->palette=NULL;
251 switch(best){
252 case IMGFMT_RGB8: {
253 /* set 332 palette for 8 bpp */
254 vf->priv->palette=malloc(4*256);
255 for(i=0; i<256; i++){
256 vf->priv->palette[4*i+0]=4*(i>>6)*21;
257 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
258 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
259 vf->priv->palette[4*i+3]=0;
261 break; }
262 case IMGFMT_BGR8: {
263 /* set 332 palette for 8 bpp */
264 vf->priv->palette=malloc(4*256);
265 for(i=0; i<256; i++){
266 vf->priv->palette[4*i+0]=4*(i&3)*21;
267 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
268 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
269 vf->priv->palette[4*i+3]=0;
271 break; }
272 case IMGFMT_BGR4:
273 case IMGFMT_BG4B: {
274 vf->priv->palette=malloc(4*16);
275 for(i=0; i<16; i++){
276 vf->priv->palette[4*i+0]=4*(i&1)*63;
277 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
278 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
279 vf->priv->palette[4*i+3]=0;
281 break; }
282 case IMGFMT_RGB4:
283 case IMGFMT_RG4B: {
284 vf->priv->palette=malloc(4*16);
285 for(i=0; i<16; i++){
286 vf->priv->palette[4*i+0]=4*(i>>3)*63;
287 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
288 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
289 vf->priv->palette[4*i+3]=0;
291 break; }
294 if (!opts->screen_size_x && !opts->screen_size_y
295 && !(opts->screen_size_xy >= 0.001)) {
296 // Compute new d_width and d_height, preserving aspect
297 // while ensuring that both are >= output size in pixels.
298 if (vf->priv->h * d_width > vf->priv->w * d_height) {
299 d_width = vf->priv->h * d_width / d_height;
300 d_height = vf->priv->h;
301 } else {
302 d_height = vf->priv->w * d_height / d_width;
303 d_width = vf->priv->w;
305 //d_width=d_width*vf->priv->w/width;
306 //d_height=d_height*vf->priv->h/height;
308 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
311 static void start_slice(struct vf_instance* vf, mp_image_t *mpi){
312 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
313 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
314 // they want slices!!! allocate the buffer.
315 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
316 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
317 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
318 vf->priv->w, vf->priv->h);
321 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
322 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
323 uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2]};
324 #ifdef WORDS_BIGENDIAN
325 uint32_t pal2[256];
326 if (src[1] && !src[2]){
327 int i;
328 for(i=0; i<256; i++)
329 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
330 src2[1]= pal2;
332 #endif
334 if(interlaced){
335 int i;
336 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2]};
337 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2]};
338 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2]};
340 sws_scale_ordered(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
341 for(i=0; i<3; i++){
342 src2[i] += src_stride[i];
343 dst2[i] += dst_stride[i];
345 sws_scale_ordered(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
346 }else{
347 sws_scale_ordered(sws1, src2, src_stride, y, h, dst, dst_stride);
351 static void draw_slice(struct vf_instance* vf,
352 unsigned char** src, int* stride, int w,int h, int x, int y){
353 mp_image_t *dmpi=vf->dmpi;
354 if(!dmpi){
355 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
356 return;
358 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
359 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
362 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){
363 mp_image_t *dmpi=mpi->priv;
365 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
366 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
368 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
370 // hope we'll get DR buffer:
371 dmpi=vf_get_image(vf->next,vf->priv->fmt,
372 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
373 vf->priv->w, vf->priv->h);
375 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
378 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
379 // just conversion, no scaling -> keep postprocessing data
380 // this way we can apply pp filter to non-yv12 source using scaler
381 vf_clone_mpi_attributes(dmpi, mpi);
384 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
386 return vf_next_put_image(vf,dmpi, pts);
389 static int control(struct vf_instance* vf, int request, void* data){
390 int *table;
391 int *inv_table;
392 int r;
393 int brightness, contrast, saturation, srcRange, dstRange;
394 vf_equalizer_t *eq;
396 if(vf->priv->ctx)
397 switch(request){
398 case VFCTRL_GET_EQUALIZER:
399 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
400 if(r<0) break;
402 eq = data;
403 if (!strcmp(eq->item,"brightness")) {
404 eq->value = ((brightness*100) + (1<<15))>>16;
406 else if (!strcmp(eq->item,"contrast")) {
407 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
409 else if (!strcmp(eq->item,"saturation")) {
410 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
412 else
413 break;
414 return CONTROL_TRUE;
415 case VFCTRL_SET_EQUALIZER:
416 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
417 if(r<0) break;
418 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
419 eq = data;
421 if (!strcmp(eq->item,"brightness")) {
422 brightness = (( eq->value <<16) + 50)/100;
424 else if (!strcmp(eq->item,"contrast")) {
425 contrast = (((eq->value+100)<<16) + 50)/100;
427 else if (!strcmp(eq->item,"saturation")) {
428 saturation = (((eq->value+100)<<16) + 50)/100;
430 else
431 break;
433 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
434 if(r<0) break;
435 if(vf->priv->ctx2){
436 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
437 if(r<0) break;
440 return CONTROL_TRUE;
441 default:
442 break;
445 return vf_next_control(vf,request,data);
448 //===========================================================================//
450 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
452 static int query_format(struct vf_instance* vf, unsigned int fmt){
453 switch(fmt){
454 case IMGFMT_YV12:
455 case IMGFMT_I420:
456 case IMGFMT_IYUV:
457 case IMGFMT_UYVY:
458 case IMGFMT_YUY2:
459 case IMGFMT_BGR32:
460 case IMGFMT_BGR24:
461 case IMGFMT_BGR16:
462 case IMGFMT_BGR15:
463 case IMGFMT_RGB32:
464 case IMGFMT_RGB24:
465 case IMGFMT_Y800:
466 case IMGFMT_Y8:
467 case IMGFMT_YVU9:
468 case IMGFMT_IF09:
469 case IMGFMT_444P:
470 case IMGFMT_422P:
471 case IMGFMT_411P:
472 case IMGFMT_BGR8:
473 case IMGFMT_RGB8:
474 case IMGFMT_BG4B:
475 case IMGFMT_RG4B:
477 unsigned int best=find_best_out(vf);
478 int flags;
479 if(!best) return 0; // no matching out-fmt
480 flags=vf_next_query_format(vf,best);
481 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
482 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
483 // do not allow scaling, if we are before the PP fliter!
484 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
485 return flags;
488 return 0; // nomatching in-fmt
491 static void uninit(struct vf_instance *vf){
492 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
493 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
494 if(vf->priv->palette) free(vf->priv->palette);
495 free(vf->priv);
498 static int open(vf_instance_t *vf, char* args){
499 vf->config=config;
500 vf->start_slice=start_slice;
501 vf->draw_slice=draw_slice;
502 vf->put_image=put_image;
503 vf->query_format=query_format;
504 vf->control= control;
505 vf->uninit=uninit;
506 if(!vf->priv) {
507 vf->priv=malloc(sizeof(struct vf_priv_s));
508 // TODO: parse args ->
509 vf->priv->ctx=NULL;
510 vf->priv->ctx2=NULL;
511 vf->priv->w=
512 vf->priv->h=-1;
513 vf->priv->v_chr_drop=0;
514 vf->priv->accurate_rnd=0;
515 vf->priv->param[0]=
516 vf->priv->param[1]=SWS_PARAM_DEFAULT;
517 vf->priv->palette=NULL;
518 } // if(!vf->priv)
519 if(args) sscanf(args, "%d:%d:%d:%lf:%lf",
520 &vf->priv->w,
521 &vf->priv->h,
522 &vf->priv->v_chr_drop,
523 &vf->priv->param[0],
524 &vf->priv->param[1]);
525 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
526 vf->priv->w,
527 vf->priv->h);
529 return 1;
532 //global sws_flags from the command line
533 int sws_flags=2;
535 //global srcFilter
536 static SwsFilter *src_filter= NULL;
538 float sws_lum_gblur= 0.0;
539 float sws_chr_gblur= 0.0;
540 int sws_chr_vshift= 0;
541 int sws_chr_hshift= 0;
542 float sws_chr_sharpen= 0.0;
543 float sws_lum_sharpen= 0.0;
545 int get_sws_cpuflags(void){
546 return
547 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
548 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
549 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
550 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
553 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
555 static int firstTime=1;
556 *flags=0;
558 #if ARCH_X86
559 if(gCpuCaps.hasMMX)
560 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
561 #endif
562 if(firstTime)
564 firstTime=0;
565 *flags= SWS_PRINT_INFO;
567 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
569 if(src_filter) sws_freeFilter(src_filter);
571 src_filter= sws_getDefaultFilter(
572 sws_lum_gblur, sws_chr_gblur,
573 sws_lum_sharpen, sws_chr_sharpen,
574 sws_chr_hshift, sws_chr_vshift, verbose>1);
576 switch(sws_flags)
578 case 0: *flags|= SWS_FAST_BILINEAR; break;
579 case 1: *flags|= SWS_BILINEAR; break;
580 case 2: *flags|= SWS_BICUBIC; break;
581 case 3: *flags|= SWS_X; break;
582 case 4: *flags|= SWS_POINT; break;
583 case 5: *flags|= SWS_AREA; break;
584 case 6: *flags|= SWS_BICUBLIN; break;
585 case 7: *flags|= SWS_GAUSS; break;
586 case 8: *flags|= SWS_SINC; break;
587 case 9: *flags|= SWS_LANCZOS; break;
588 case 10:*flags|= SWS_SPLINE; break;
589 default:*flags|= SWS_BILINEAR; break;
592 *srcFilterParam= src_filter;
593 *dstFilterParam= NULL;
596 // will use sws_flags & src_filter (from cmd line)
597 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
599 int flags;
600 SwsFilter *dstFilterParam, *srcFilterParam;
601 enum PixelFormat dfmt, sfmt;
603 dfmt = imgfmt2pixfmt(dstFormat);
604 sfmt = imgfmt2pixfmt(srcFormat);
605 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
606 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
608 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
611 /// An example of presets usage
612 static const struct size_preset {
613 char* name;
614 int w, h;
615 } vf_size_presets_defs[] = {
616 // TODO add more 'standard' resolutions
617 { "qntsc", 352, 240 },
618 { "qpal", 352, 288 },
619 { "ntsc", 720, 480 },
620 { "pal", 720, 576 },
621 { "sntsc", 640, 480 },
622 { "spal", 768, 576 },
623 { NULL, 0, 0}
626 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
627 static const m_option_t vf_size_preset_fields[] = {
628 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
629 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
630 { NULL, NULL, 0, 0, 0, 0, NULL }
633 static const m_struct_t vf_size_preset = {
634 "scale_size_preset",
635 sizeof(struct size_preset),
636 NULL,
637 vf_size_preset_fields
640 static const m_struct_t vf_opts;
641 static const m_obj_presets_t size_preset = {
642 &vf_size_preset, // Input struct desc
643 &vf_opts, // Output struct desc
644 vf_size_presets_defs, // The list of presets
645 ST_OFF(name) // At wich offset is the name field in the preset struct
648 /// Now the options
649 #undef ST_OFF
650 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
651 static const m_option_t vf_opts_fields[] = {
652 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
653 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
654 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
655 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
656 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
657 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
658 // Note that here the 2 field is NULL (ie 0)
659 // As we want this option to act on the option struct itself
660 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},
661 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
662 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
663 { NULL, NULL, 0, 0, 0, 0, NULL }
666 static const m_struct_t vf_opts = {
667 "scale",
668 sizeof(struct vf_priv_s),
669 &vf_priv_dflt,
670 vf_opts_fields
673 const vf_info_t vf_info_scale = {
674 "software scaling",
675 "scale",
676 "A'rpi",
678 open,
679 &vf_opts
682 //===========================================================================//