sync with en/mplayer.1 rev. 30611
[mplayer/glamo.git] / libmpcodecs / vf_scale.c
blob9f96ad84d942ad2d8ee0cb5399b1d138430fa2a6
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"
28 #include "img_format.h"
29 #include "mp_image.h"
30 #include "vf.h"
31 #include "fmt-conversion.h"
32 #include "mpbswap.h"
34 #include "libswscale/swscale.h"
35 #include "vf_scale.h"
37 #include "m_option.h"
38 #include "m_struct.h"
40 static struct vf_priv_s {
41 int w,h;
42 int v_chr_drop;
43 double param[2];
44 unsigned int fmt;
45 struct SwsContext *ctx;
46 struct SwsContext *ctx2; //for interlaced slices only
47 unsigned char* palette;
48 int interlaced;
49 int noup;
50 int accurate_rnd;
51 } const vf_priv_dflt = {
52 -1,-1,
54 {SWS_PARAM_DEFAULT, SWS_PARAM_DEFAULT},
56 NULL,
57 NULL,
58 NULL
61 extern int opt_screen_size_x;
62 extern int opt_screen_size_y;
63 extern float screen_size_xy;
65 //===========================================================================//
67 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam);
69 static unsigned int outfmt_list[]={
70 // YUV:
71 IMGFMT_444P,
72 IMGFMT_444P16_LE,
73 IMGFMT_444P16_BE,
74 IMGFMT_422P,
75 IMGFMT_422P16_LE,
76 IMGFMT_422P16_BE,
77 IMGFMT_YV12,
78 IMGFMT_I420,
79 IMGFMT_420P16_LE,
80 IMGFMT_420P16_BE,
81 IMGFMT_420A,
82 IMGFMT_IYUV,
83 IMGFMT_YVU9,
84 IMGFMT_IF09,
85 IMGFMT_411P,
86 IMGFMT_NV12,
87 IMGFMT_NV21,
88 IMGFMT_YUY2,
89 IMGFMT_UYVY,
90 IMGFMT_440P,
91 // RGB and grayscale (Y8 and Y800):
92 IMGFMT_BGR32,
93 IMGFMT_RGB32,
94 IMGFMT_BGR24,
95 IMGFMT_RGB24,
96 IMGFMT_RGB48LE,
97 IMGFMT_RGB48BE,
98 IMGFMT_BGR16,
99 IMGFMT_RGB16,
100 IMGFMT_BGR15,
101 IMGFMT_RGB15,
102 IMGFMT_Y800,
103 IMGFMT_Y8,
104 IMGFMT_BGR8,
105 IMGFMT_RGB8,
106 IMGFMT_BGR4,
107 IMGFMT_RGB4,
108 IMGFMT_BG4B,
109 IMGFMT_RG4B,
110 IMGFMT_BGR1,
111 IMGFMT_RGB1,
116 * A list of preferred conversions, in order of preference.
117 * This should be used for conversions that e.g. involve no scaling
118 * or to stop vf_scale from choosing a conversion that has no
119 * fast assembler implementation.
121 static int preferred_conversions[][2] = {
122 {IMGFMT_YUY2, IMGFMT_UYVY},
123 {IMGFMT_YUY2, IMGFMT_422P},
124 {IMGFMT_UYVY, IMGFMT_YUY2},
125 {IMGFMT_UYVY, IMGFMT_422P},
126 {IMGFMT_422P, IMGFMT_YUY2},
127 {IMGFMT_422P, IMGFMT_UYVY},
128 {0, 0}
131 static unsigned int find_best_out(vf_instance_t *vf, int in_format){
132 unsigned int best=0;
133 int i = -1;
134 int j = -1;
135 int format = 0;
137 // find the best outfmt:
138 while (1) {
139 int ret;
140 if (j < 0) {
141 format = in_format;
142 j = 0;
143 } else if (i < 0) {
144 while (preferred_conversions[j][0] &&
145 preferred_conversions[j][0] != in_format)
146 j++;
147 format = preferred_conversions[j++][1];
148 // switch to standard list
149 if (!format)
150 i = 0;
152 if (i >= 0)
153 format = outfmt_list[i++];
154 if (!format)
155 break;
156 ret = vf_next_query_format(vf, format);
158 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
159 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
160 best=format; // no conversion -> bingo!
161 break;
163 if(ret&VFCAP_CSP_SUPPORTED && !best)
164 best=format; // best with conversion
166 return best;
169 static int config(struct vf_instance_s* vf,
170 int width, int height, int d_width, int d_height,
171 unsigned int flags, unsigned int outfmt){
172 unsigned int best=find_best_out(vf, outfmt);
173 int vo_flags;
174 int int_sws_flags=0;
175 int round_w=0, round_h=0;
176 int i;
177 SwsFilter *srcFilter, *dstFilter;
178 enum PixelFormat dfmt, sfmt;
180 if(!best){
181 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
182 return 0;
184 sfmt = imgfmt2pixfmt(outfmt);
185 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
186 dfmt = imgfmt2pixfmt(best);
188 vo_flags=vf->next->query_format(vf->next,best);
190 // scaling to dwidth*d_height, if all these TRUE:
191 // - option -zoom
192 // - no other sw/hw up/down scaling avail.
193 // - we're after postproc
194 // - user didn't set w:h
195 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
196 vf->priv->w<0 && vf->priv->h<0){ // -zoom
197 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
198 if(d_width<width || d_height<height){
199 // downscale!
200 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
201 } else {
202 // upscale:
203 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
205 if(x){
206 // user wants sw scaling! (-zoom)
207 vf->priv->w=d_width;
208 vf->priv->h=d_height;
212 if(vf->priv->noup){
213 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
214 vf->priv->w= width;
215 vf->priv->h= height;
219 if (vf->priv->w <= -8) {
220 vf->priv->w += 8;
221 round_w = 1;
223 if (vf->priv->h <= -8) {
224 vf->priv->h += 8;
225 round_h = 1;
228 if (vf->priv->w < -3 || vf->priv->h < -3 ||
229 (vf->priv->w < -1 && vf->priv->h < -1)) {
230 // TODO: establish a direct connection to the user's brain
231 // and find out what the heck he thinks MPlayer should do
232 // with this nonsense.
233 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
234 return 0;
237 if (vf->priv->w == -1)
238 vf->priv->w = width;
239 if (vf->priv->w == 0)
240 vf->priv->w = d_width;
242 if (vf->priv->h == -1)
243 vf->priv->h = height;
244 if (vf->priv->h == 0)
245 vf->priv->h = d_height;
247 if (vf->priv->w == -3)
248 vf->priv->w = vf->priv->h * width / height;
249 if (vf->priv->w == -2)
250 vf->priv->w = vf->priv->h * d_width / d_height;
252 if (vf->priv->h == -3)
253 vf->priv->h = vf->priv->w * height / width;
254 if (vf->priv->h == -2)
255 vf->priv->h = vf->priv->w * d_height / d_width;
257 if (round_w)
258 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
259 if (round_h)
260 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
262 // calculate the missing parameters:
263 switch(best) {
264 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
265 case IMGFMT_I420:
266 case IMGFMT_IYUV:
267 case IMGFMT_NV12:
268 case IMGFMT_NV21:
269 vf->priv->h = (vf->priv->h + 1) & ~1;
270 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
271 case IMGFMT_UYVY:
272 vf->priv->w = (vf->priv->w + 1) & ~1;
275 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
276 width,height,vo_format_name(outfmt),
277 vf->priv->w,vf->priv->h,vo_format_name(best));
279 // free old ctx:
280 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
281 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
283 // new swscaler:
284 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
285 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
286 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
287 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
288 sfmt,
289 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
290 dfmt,
291 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
292 if(vf->priv->interlaced){
293 vf->priv->ctx2=sws_getContext(width, height >> 1,
294 sfmt,
295 vf->priv->w, vf->priv->h >> 1,
296 dfmt,
297 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
299 if(!vf->priv->ctx){
300 // error...
301 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
302 return 0;
304 vf->priv->fmt=best;
306 if(vf->priv->palette){
307 free(vf->priv->palette);
308 vf->priv->palette=NULL;
310 switch(best){
311 case IMGFMT_RGB8: {
312 /* set 332 palette for 8 bpp */
313 vf->priv->palette=malloc(4*256);
314 for(i=0; i<256; i++){
315 vf->priv->palette[4*i+0]=4*(i>>6)*21;
316 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
317 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
318 vf->priv->palette[4*i+3]=0;
320 break; }
321 case IMGFMT_BGR8: {
322 /* set 332 palette for 8 bpp */
323 vf->priv->palette=malloc(4*256);
324 for(i=0; i<256; i++){
325 vf->priv->palette[4*i+0]=4*(i&3)*21;
326 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
327 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
328 vf->priv->palette[4*i+3]=0;
330 break; }
331 case IMGFMT_BGR4:
332 case IMGFMT_BG4B: {
333 vf->priv->palette=malloc(4*16);
334 for(i=0; i<16; i++){
335 vf->priv->palette[4*i+0]=4*(i&1)*63;
336 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
337 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
338 vf->priv->palette[4*i+3]=0;
340 break; }
341 case IMGFMT_RGB4:
342 case IMGFMT_RG4B: {
343 vf->priv->palette=malloc(4*16);
344 for(i=0; i<16; i++){
345 vf->priv->palette[4*i+0]=4*(i>>3)*63;
346 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
347 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
348 vf->priv->palette[4*i+3]=0;
350 break; }
353 if(!opt_screen_size_x && !opt_screen_size_y && !(screen_size_xy >= 0.001)){
354 // Compute new d_width and d_height, preserving aspect
355 // while ensuring that both are >= output size in pixels.
356 if (vf->priv->h * d_width > vf->priv->w * d_height) {
357 d_width = vf->priv->h * d_width / d_height;
358 d_height = vf->priv->h;
359 } else {
360 d_height = vf->priv->w * d_height / d_width;
361 d_width = vf->priv->w;
363 //d_width=d_width*vf->priv->w/width;
364 //d_height=d_height*vf->priv->h/height;
366 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
369 static void start_slice(struct vf_instance_s* vf, mp_image_t *mpi){
370 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
371 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
372 // they want slices!!! allocate the buffer.
373 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
374 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
375 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
376 vf->priv->w, vf->priv->h);
379 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
380 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
381 uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
382 #if HAVE_BIGENDIAN
383 uint32_t pal2[256];
384 if (src[1] && !src[2]){
385 int i;
386 for(i=0; i<256; i++)
387 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
388 src2[1]= pal2;
390 #endif
392 if(interlaced){
393 int i;
394 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
395 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
396 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
398 sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
399 for(i=0; i<MP_MAX_PLANES; i++){
400 src2[i] += src_stride[i];
401 dst2[i] += dst_stride[i];
403 sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
404 }else{
405 sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
409 static void draw_slice(struct vf_instance_s* vf,
410 unsigned char** src, int* stride, int w,int h, int x, int y){
411 mp_image_t *dmpi=vf->dmpi;
412 if(!dmpi){
413 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
414 return;
416 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
417 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
420 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){
421 mp_image_t *dmpi=mpi->priv;
423 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
424 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
426 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
428 // hope we'll get DR buffer:
429 dmpi=vf_get_image(vf->next,vf->priv->fmt,
430 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
431 vf->priv->w, vf->priv->h);
433 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
436 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
437 // just conversion, no scaling -> keep postprocessing data
438 // this way we can apply pp filter to non-yv12 source using scaler
439 vf_clone_mpi_attributes(dmpi, mpi);
442 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
444 return vf_next_put_image(vf,dmpi, pts);
447 static int control(struct vf_instance_s* vf, int request, void* data){
448 int *table;
449 int *inv_table;
450 int r;
451 int brightness, contrast, saturation, srcRange, dstRange;
452 vf_equalizer_t *eq;
454 if(vf->priv->ctx)
455 switch(request){
456 case VFCTRL_GET_EQUALIZER:
457 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
458 if(r<0) break;
460 eq = data;
461 if (!strcmp(eq->item,"brightness")) {
462 eq->value = ((brightness*100) + (1<<15))>>16;
464 else if (!strcmp(eq->item,"contrast")) {
465 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
467 else if (!strcmp(eq->item,"saturation")) {
468 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
470 else
471 break;
472 return CONTROL_TRUE;
473 case VFCTRL_SET_EQUALIZER:
474 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
475 if(r<0) break;
476 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
477 eq = data;
479 if (!strcmp(eq->item,"brightness")) {
480 brightness = (( eq->value <<16) + 50)/100;
482 else if (!strcmp(eq->item,"contrast")) {
483 contrast = (((eq->value+100)<<16) + 50)/100;
485 else if (!strcmp(eq->item,"saturation")) {
486 saturation = (((eq->value+100)<<16) + 50)/100;
488 else
489 break;
491 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
492 if(r<0) break;
493 if(vf->priv->ctx2){
494 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
495 if(r<0) break;
498 return CONTROL_TRUE;
499 default:
500 break;
503 return vf_next_control(vf,request,data);
506 //===========================================================================//
508 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
510 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
511 switch(fmt){
512 case IMGFMT_YV12:
513 case IMGFMT_I420:
514 case IMGFMT_IYUV:
515 case IMGFMT_UYVY:
516 case IMGFMT_YUY2:
517 case IMGFMT_BGR32:
518 case IMGFMT_BGR24:
519 case IMGFMT_BGR16:
520 case IMGFMT_BGR15:
521 case IMGFMT_RGB32:
522 case IMGFMT_RGB24:
523 case IMGFMT_Y800:
524 case IMGFMT_Y8:
525 case IMGFMT_YVU9:
526 case IMGFMT_IF09:
527 case IMGFMT_444P:
528 case IMGFMT_422P:
529 case IMGFMT_411P:
530 case IMGFMT_440P:
531 case IMGFMT_420A:
532 case IMGFMT_444P16_LE:
533 case IMGFMT_444P16_BE:
534 case IMGFMT_422P16_LE:
535 case IMGFMT_422P16_BE:
536 case IMGFMT_420P16_LE:
537 case IMGFMT_420P16_BE:
538 case IMGFMT_BGR8:
539 case IMGFMT_RGB8:
540 case IMGFMT_BG4B:
541 case IMGFMT_RG4B:
542 case IMGFMT_RGB48LE:
543 case IMGFMT_RGB48BE:
545 unsigned int best=find_best_out(vf, fmt);
546 int flags;
547 if(!best) return 0; // no matching out-fmt
548 flags=vf_next_query_format(vf,best);
549 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
550 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
551 // do not allow scaling, if we are before the PP fliter!
552 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
553 return flags;
556 return 0; // nomatching in-fmt
559 static void uninit(struct vf_instance_s *vf){
560 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
561 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
562 if(vf->priv->palette) free(vf->priv->palette);
563 free(vf->priv);
566 static int open(vf_instance_t *vf, char* args){
567 vf->config=config;
568 vf->start_slice=start_slice;
569 vf->draw_slice=draw_slice;
570 vf->put_image=put_image;
571 vf->query_format=query_format;
572 vf->control= control;
573 vf->uninit=uninit;
574 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
575 vf->priv->w,
576 vf->priv->h);
578 return 1;
581 //global sws_flags from the command line
582 int sws_flags=2;
584 //global srcFilter
585 static SwsFilter *src_filter= NULL;
587 float sws_lum_gblur= 0.0;
588 float sws_chr_gblur= 0.0;
589 int sws_chr_vshift= 0;
590 int sws_chr_hshift= 0;
591 float sws_chr_sharpen= 0.0;
592 float sws_lum_sharpen= 0.0;
594 int get_sws_cpuflags(void){
595 return
596 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
597 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
598 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
599 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
602 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
604 static int firstTime=1;
605 *flags=0;
607 #if ARCH_X86
608 if(gCpuCaps.hasMMX)
609 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
610 #endif
611 if(firstTime)
613 firstTime=0;
614 *flags= SWS_PRINT_INFO;
616 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
618 if(src_filter) sws_freeFilter(src_filter);
620 src_filter= sws_getDefaultFilter(
621 sws_lum_gblur, sws_chr_gblur,
622 sws_lum_sharpen, sws_chr_sharpen,
623 sws_chr_hshift, sws_chr_vshift, verbose>1);
625 switch(sws_flags)
627 case 0: *flags|= SWS_FAST_BILINEAR; break;
628 case 1: *flags|= SWS_BILINEAR; break;
629 case 2: *flags|= SWS_BICUBIC; break;
630 case 3: *flags|= SWS_X; break;
631 case 4: *flags|= SWS_POINT; break;
632 case 5: *flags|= SWS_AREA; break;
633 case 6: *flags|= SWS_BICUBLIN; break;
634 case 7: *flags|= SWS_GAUSS; break;
635 case 8: *flags|= SWS_SINC; break;
636 case 9: *flags|= SWS_LANCZOS; break;
637 case 10:*flags|= SWS_SPLINE; break;
638 default:*flags|= SWS_BILINEAR; break;
641 *srcFilterParam= src_filter;
642 *dstFilterParam= NULL;
645 // will use sws_flags & src_filter (from cmd line)
646 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
648 int flags;
649 SwsFilter *dstFilterParam, *srcFilterParam;
650 enum PixelFormat dfmt, sfmt;
652 dfmt = imgfmt2pixfmt(dstFormat);
653 sfmt = imgfmt2pixfmt(srcFormat);
654 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
655 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
657 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
660 /// An example of presets usage
661 static struct size_preset {
662 char* name;
663 int w, h;
664 } vf_size_presets_defs[] = {
665 // TODO add more 'standard' resolutions
666 { "qntsc", 352, 240 },
667 { "qpal", 352, 288 },
668 { "ntsc", 720, 480 },
669 { "pal", 720, 576 },
670 { "sntsc", 640, 480 },
671 { "spal", 768, 576 },
672 { NULL, 0, 0}
675 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
676 static m_option_t vf_size_preset_fields[] = {
677 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
678 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
679 { NULL, NULL, 0, 0, 0, 0, NULL }
682 static m_struct_t vf_size_preset = {
683 "scale_size_preset",
684 sizeof(struct size_preset),
685 NULL,
686 vf_size_preset_fields
689 static m_struct_t vf_opts;
690 static m_obj_presets_t size_preset = {
691 &vf_size_preset, // Input struct desc
692 &vf_opts, // Output struct desc
693 vf_size_presets_defs, // The list of presets
694 ST_OFF(name) // At wich offset is the name field in the preset struct
697 /// Now the options
698 #undef ST_OFF
699 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
700 static m_option_t vf_opts_fields[] = {
701 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
702 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
703 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
704 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
705 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
706 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
707 // Note that here the 2 field is NULL (ie 0)
708 // As we want this option to act on the option struct itself
709 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},
710 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
711 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
712 { NULL, NULL, 0, 0, 0, 0, NULL }
715 static m_struct_t vf_opts = {
716 "scale",
717 sizeof(struct vf_priv_s),
718 &vf_priv_dflt,
719 vf_opts_fields
722 const vf_info_t vf_info_scale = {
723 "software scaling",
724 "scale",
725 "A'rpi",
727 open,
728 &vf_opts
731 //===========================================================================//