Ignore svn changes up to r30324
[mplayer/glamo.git] / libmpcodecs / vf_scale.c
bloba38cf895d94c8999e0c960ed478ef1e564f20555
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_444P16_LE,
53 IMGFMT_444P16_BE,
54 IMGFMT_422P,
55 IMGFMT_422P16_LE,
56 IMGFMT_422P16_BE,
57 IMGFMT_YV12,
58 IMGFMT_I420,
59 IMGFMT_420P16_LE,
60 IMGFMT_420P16_BE,
61 IMGFMT_420A,
62 IMGFMT_IYUV,
63 IMGFMT_YVU9,
64 IMGFMT_IF09,
65 IMGFMT_411P,
66 IMGFMT_NV12,
67 IMGFMT_NV21,
68 IMGFMT_YUY2,
69 IMGFMT_UYVY,
70 IMGFMT_440P,
71 // RGB and grayscale (Y8 and Y800):
72 IMGFMT_BGR32,
73 IMGFMT_RGB32,
74 IMGFMT_BGR24,
75 IMGFMT_RGB24,
76 IMGFMT_RGB48LE,
77 IMGFMT_RGB48BE,
78 IMGFMT_BGR16,
79 IMGFMT_RGB16,
80 IMGFMT_BGR15,
81 IMGFMT_RGB15,
82 IMGFMT_Y800,
83 IMGFMT_Y8,
84 IMGFMT_BGR8,
85 IMGFMT_RGB8,
86 IMGFMT_BGR4,
87 IMGFMT_RGB4,
88 IMGFMT_BG4B,
89 IMGFMT_RG4B,
90 IMGFMT_BGR1,
91 IMGFMT_RGB1,
95 static unsigned int find_best_out(vf_instance_t *vf){
96 unsigned int best=0;
97 int i;
99 // find the best outfmt:
100 for(i=0; i<sizeof(outfmt_list)/sizeof(int)-1; i++){
101 const int format= outfmt_list[i];
102 int ret= vf->priv->query_format_cache[i]-1;
103 if(ret == -1){
104 ret= vf_next_query_format(vf, outfmt_list[i]);
105 vf->priv->query_format_cache[i]= ret+1;
108 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
109 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
110 best=format; // no conversion -> bingo!
111 break;
113 if(ret&VFCAP_CSP_SUPPORTED && !best)
114 best=format; // best with conversion
116 return best;
119 static int config(struct vf_instance* vf,
120 int width, int height, int d_width, int d_height,
121 unsigned int flags, unsigned int outfmt){
122 struct MPOpts *opts = vf->opts;
123 unsigned int best=find_best_out(vf);
124 int vo_flags;
125 int int_sws_flags=0;
126 int round_w=0, round_h=0;
127 int i;
128 SwsFilter *srcFilter, *dstFilter;
129 enum PixelFormat dfmt, sfmt;
131 if(!best){
132 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
133 return 0;
135 sfmt = imgfmt2pixfmt(outfmt);
136 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
137 dfmt = imgfmt2pixfmt(best);
139 vo_flags=vf->next->query_format(vf->next,best);
141 // scaling to dwidth*d_height, if all these TRUE:
142 // - option -zoom
143 // - no other sw/hw up/down scaling avail.
144 // - we're after postproc
145 // - user didn't set w:h
146 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
147 vf->priv->w<0 && vf->priv->h<0){ // -zoom
148 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
149 if(d_width<width || d_height<height){
150 // downscale!
151 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
152 } else {
153 // upscale:
154 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
156 if(x){
157 // user wants sw scaling! (-zoom)
158 vf->priv->w=d_width;
159 vf->priv->h=d_height;
163 if(vf->priv->noup){
164 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
165 vf->priv->w= width;
166 vf->priv->h= height;
170 if (vf->priv->w <= -8) {
171 vf->priv->w += 8;
172 round_w = 1;
174 if (vf->priv->h <= -8) {
175 vf->priv->h += 8;
176 round_h = 1;
179 if (vf->priv->w < -3 || vf->priv->h < -3 ||
180 (vf->priv->w < -1 && vf->priv->h < -1)) {
181 // TODO: establish a direct connection to the user's brain
182 // and find out what the heck he thinks MPlayer should do
183 // with this nonsense.
184 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
185 return 0;
188 if (vf->priv->w == -1)
189 vf->priv->w = width;
190 if (vf->priv->w == 0)
191 vf->priv->w = d_width;
193 if (vf->priv->h == -1)
194 vf->priv->h = height;
195 if (vf->priv->h == 0)
196 vf->priv->h = d_height;
198 if (vf->priv->w == -3)
199 vf->priv->w = vf->priv->h * width / height;
200 if (vf->priv->w == -2)
201 vf->priv->w = vf->priv->h * d_width / d_height;
203 if (vf->priv->h == -3)
204 vf->priv->h = vf->priv->w * height / width;
205 if (vf->priv->h == -2)
206 vf->priv->h = vf->priv->w * d_height / d_width;
208 if (round_w)
209 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
210 if (round_h)
211 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
213 // calculate the missing parameters:
214 switch(best) {
215 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
216 case IMGFMT_I420:
217 case IMGFMT_IYUV:
218 case IMGFMT_NV12:
219 case IMGFMT_NV21:
220 vf->priv->h = (vf->priv->h + 1) & ~1;
221 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
222 case IMGFMT_UYVY:
223 vf->priv->w = (vf->priv->w + 1) & ~1;
226 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
227 width,height,vo_format_name(outfmt),
228 vf->priv->w,vf->priv->h,vo_format_name(best));
230 // free old ctx:
231 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
232 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
234 // new swscaler:
235 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
236 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
237 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
238 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
239 sfmt,
240 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
241 dfmt,
242 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
243 if(vf->priv->interlaced){
244 vf->priv->ctx2=sws_getContext(width, height >> 1,
245 sfmt,
246 vf->priv->w, vf->priv->h >> 1,
247 dfmt,
248 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
250 if(!vf->priv->ctx){
251 // error...
252 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
253 return 0;
255 vf->priv->fmt=best;
257 if(vf->priv->palette){
258 free(vf->priv->palette);
259 vf->priv->palette=NULL;
261 switch(best){
262 case IMGFMT_RGB8: {
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>>6)*21;
267 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
268 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
269 vf->priv->palette[4*i+3]=0;
271 break; }
272 case IMGFMT_BGR8: {
273 /* set 332 palette for 8 bpp */
274 vf->priv->palette=malloc(4*256);
275 for(i=0; i<256; i++){
276 vf->priv->palette[4*i+0]=4*(i&3)*21;
277 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
278 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
279 vf->priv->palette[4*i+3]=0;
281 break; }
282 case IMGFMT_BGR4:
283 case IMGFMT_BG4B: {
284 vf->priv->palette=malloc(4*16);
285 for(i=0; i<16; i++){
286 vf->priv->palette[4*i+0]=4*(i&1)*63;
287 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
288 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
289 vf->priv->palette[4*i+3]=0;
291 break; }
292 case IMGFMT_RGB4:
293 case IMGFMT_RG4B: {
294 vf->priv->palette=malloc(4*16);
295 for(i=0; i<16; i++){
296 vf->priv->palette[4*i+0]=4*(i>>3)*63;
297 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
298 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
299 vf->priv->palette[4*i+3]=0;
301 break; }
304 if (!opts->screen_size_x && !opts->screen_size_y
305 && !(opts->screen_size_xy >= 0.001)) {
306 // Compute new d_width and d_height, preserving aspect
307 // while ensuring that both are >= output size in pixels.
308 if (vf->priv->h * d_width > vf->priv->w * d_height) {
309 d_width = vf->priv->h * d_width / d_height;
310 d_height = vf->priv->h;
311 } else {
312 d_height = vf->priv->w * d_height / d_width;
313 d_width = vf->priv->w;
315 //d_width=d_width*vf->priv->w/width;
316 //d_height=d_height*vf->priv->h/height;
318 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
321 static void start_slice(struct vf_instance* vf, mp_image_t *mpi){
322 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
323 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
324 // they want slices!!! allocate the buffer.
325 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
326 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
327 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
328 vf->priv->w, vf->priv->h);
331 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
332 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
333 uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
334 #if HAVE_BIGENDIAN
335 uint32_t pal2[256];
336 if (src[1] && !src[2]){
337 int i;
338 for(i=0; i<256; i++)
339 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
340 src2[1]= pal2;
342 #endif
344 if(interlaced){
345 int i;
346 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
347 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
348 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
350 sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
351 for(i=0; i<MP_MAX_PLANES; i++){
352 src2[i] += src_stride[i];
353 dst2[i] += dst_stride[i];
355 sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
356 }else{
357 sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
361 static void draw_slice(struct vf_instance* vf,
362 unsigned char** src, int* stride, int w,int h, int x, int y){
363 mp_image_t *dmpi=vf->dmpi;
364 if(!dmpi){
365 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
366 return;
368 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
369 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
372 static int put_image(struct vf_instance* vf, mp_image_t *mpi, double pts){
373 mp_image_t *dmpi=mpi->priv;
375 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
376 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
378 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
380 // hope we'll get DR buffer:
381 dmpi=vf_get_image(vf->next,vf->priv->fmt,
382 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
383 vf->priv->w, vf->priv->h);
385 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
388 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
389 // just conversion, no scaling -> keep postprocessing data
390 // this way we can apply pp filter to non-yv12 source using scaler
391 vf_clone_mpi_attributes(dmpi, mpi);
394 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
396 return vf_next_put_image(vf,dmpi, pts);
399 static int control(struct vf_instance* vf, int request, void* data){
400 int *table;
401 int *inv_table;
402 int r;
403 int brightness, contrast, saturation, srcRange, dstRange;
404 vf_equalizer_t *eq;
406 if(vf->priv->ctx)
407 switch(request){
408 case VFCTRL_GET_EQUALIZER:
409 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
410 if(r<0) break;
412 eq = data;
413 if (!strcmp(eq->item,"brightness")) {
414 eq->value = ((brightness*100) + (1<<15))>>16;
416 else if (!strcmp(eq->item,"contrast")) {
417 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
419 else if (!strcmp(eq->item,"saturation")) {
420 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
422 else
423 break;
424 return CONTROL_TRUE;
425 case VFCTRL_SET_EQUALIZER:
426 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
427 if(r<0) break;
428 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
429 eq = data;
431 if (!strcmp(eq->item,"brightness")) {
432 brightness = (( eq->value <<16) + 50)/100;
434 else if (!strcmp(eq->item,"contrast")) {
435 contrast = (((eq->value+100)<<16) + 50)/100;
437 else if (!strcmp(eq->item,"saturation")) {
438 saturation = (((eq->value+100)<<16) + 50)/100;
440 else
441 break;
443 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
444 if(r<0) break;
445 if(vf->priv->ctx2){
446 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
447 if(r<0) break;
450 return CONTROL_TRUE;
451 default:
452 break;
455 return vf_next_control(vf,request,data);
458 //===========================================================================//
460 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
462 static int query_format(struct vf_instance* vf, unsigned int fmt){
463 switch(fmt){
464 case IMGFMT_YV12:
465 case IMGFMT_I420:
466 case IMGFMT_IYUV:
467 case IMGFMT_UYVY:
468 case IMGFMT_YUY2:
469 case IMGFMT_BGR32:
470 case IMGFMT_BGR24:
471 case IMGFMT_BGR16:
472 case IMGFMT_BGR15:
473 case IMGFMT_RGB32:
474 case IMGFMT_RGB24:
475 case IMGFMT_Y800:
476 case IMGFMT_Y8:
477 case IMGFMT_YVU9:
478 case IMGFMT_IF09:
479 case IMGFMT_444P:
480 case IMGFMT_422P:
481 case IMGFMT_411P:
482 case IMGFMT_440P:
483 case IMGFMT_420A:
484 case IMGFMT_444P16_LE:
485 case IMGFMT_444P16_BE:
486 case IMGFMT_422P16_LE:
487 case IMGFMT_422P16_BE:
488 case IMGFMT_420P16_LE:
489 case IMGFMT_420P16_BE:
490 case IMGFMT_BGR8:
491 case IMGFMT_RGB8:
492 case IMGFMT_BG4B:
493 case IMGFMT_RG4B:
494 case IMGFMT_RGB48LE:
495 case IMGFMT_RGB48BE:
497 unsigned int best=find_best_out(vf);
498 int flags;
499 if(!best) return 0; // no matching out-fmt
500 flags=vf_next_query_format(vf,best);
501 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
502 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
503 // do not allow scaling, if we are before the PP fliter!
504 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
505 return flags;
508 return 0; // nomatching in-fmt
511 static void uninit(struct vf_instance *vf){
512 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
513 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
514 if(vf->priv->palette) free(vf->priv->palette);
515 free(vf->priv);
518 static int open(vf_instance_t *vf, char* args){
519 vf->config=config;
520 vf->start_slice=start_slice;
521 vf->draw_slice=draw_slice;
522 vf->put_image=put_image;
523 vf->query_format=query_format;
524 vf->control= control;
525 vf->uninit=uninit;
526 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
527 vf->priv->w,
528 vf->priv->h);
530 return 1;
533 //global sws_flags from the command line
534 int sws_flags=2;
536 //global srcFilter
537 static SwsFilter *src_filter= NULL;
539 float sws_lum_gblur= 0.0;
540 float sws_chr_gblur= 0.0;
541 int sws_chr_vshift= 0;
542 int sws_chr_hshift= 0;
543 float sws_chr_sharpen= 0.0;
544 float sws_lum_sharpen= 0.0;
546 int get_sws_cpuflags(void){
547 return
548 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
549 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
550 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
551 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
554 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
556 static int firstTime=1;
557 *flags=0;
559 #if ARCH_X86
560 if(gCpuCaps.hasMMX)
561 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
562 #endif
563 if(firstTime)
565 firstTime=0;
566 *flags= SWS_PRINT_INFO;
568 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
570 if(src_filter) sws_freeFilter(src_filter);
572 src_filter= sws_getDefaultFilter(
573 sws_lum_gblur, sws_chr_gblur,
574 sws_lum_sharpen, sws_chr_sharpen,
575 sws_chr_hshift, sws_chr_vshift, verbose>1);
577 switch(sws_flags)
579 case 0: *flags|= SWS_FAST_BILINEAR; break;
580 case 1: *flags|= SWS_BILINEAR; break;
581 case 2: *flags|= SWS_BICUBIC; break;
582 case 3: *flags|= SWS_X; break;
583 case 4: *flags|= SWS_POINT; break;
584 case 5: *flags|= SWS_AREA; break;
585 case 6: *flags|= SWS_BICUBLIN; break;
586 case 7: *flags|= SWS_GAUSS; break;
587 case 8: *flags|= SWS_SINC; break;
588 case 9: *flags|= SWS_LANCZOS; break;
589 case 10:*flags|= SWS_SPLINE; break;
590 default:*flags|= SWS_BILINEAR; break;
593 *srcFilterParam= src_filter;
594 *dstFilterParam= NULL;
597 // will use sws_flags & src_filter (from cmd line)
598 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
600 int flags;
601 SwsFilter *dstFilterParam, *srcFilterParam;
602 enum PixelFormat dfmt, sfmt;
604 dfmt = imgfmt2pixfmt(dstFormat);
605 sfmt = imgfmt2pixfmt(srcFormat);
606 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
607 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
609 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
612 /// An example of presets usage
613 static const struct size_preset {
614 char* name;
615 int w, h;
616 } vf_size_presets_defs[] = {
617 // TODO add more 'standard' resolutions
618 { "qntsc", 352, 240 },
619 { "qpal", 352, 288 },
620 { "ntsc", 720, 480 },
621 { "pal", 720, 576 },
622 { "sntsc", 640, 480 },
623 { "spal", 768, 576 },
624 { NULL, 0, 0}
627 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
628 static const m_option_t vf_size_preset_fields[] = {
629 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
630 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
631 { NULL, NULL, 0, 0, 0, 0, NULL }
634 static const m_struct_t vf_size_preset = {
635 "scale_size_preset",
636 sizeof(struct size_preset),
637 NULL,
638 vf_size_preset_fields
641 static const m_struct_t vf_opts;
642 static const m_obj_presets_t size_preset = {
643 &vf_size_preset, // Input struct desc
644 &vf_opts, // Output struct desc
645 vf_size_presets_defs, // The list of presets
646 ST_OFF(name) // At wich offset is the name field in the preset struct
649 /// Now the options
650 #undef ST_OFF
651 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
652 static const m_option_t vf_opts_fields[] = {
653 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
654 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
655 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
656 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
657 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
658 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
659 // Note that here the 2 field is NULL (ie 0)
660 // As we want this option to act on the option struct itself
661 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},
662 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
663 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
664 { NULL, NULL, 0, 0, 0, 0, NULL }
667 static const m_struct_t vf_opts = {
668 "scale",
669 sizeof(struct vf_priv_s),
670 &vf_priv_dflt,
671 vf_opts_fields
674 const vf_info_t vf_info_scale = {
675 "software scaling",
676 "scale",
677 "A'rpi",
679 open,
680 &vf_opts
683 //===========================================================================//