Add webm/VP8 support to native matroska demuxer.
[mplayer/glamo.git] / libmpcodecs / vf_scale.c
blob887bf3d2e254726107221471969ec66c702bd12c
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 "vd.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_422P,
72 IMGFMT_422P16_LE,
73 IMGFMT_422P16_BE,
74 IMGFMT_YV12,
75 IMGFMT_I420,
76 IMGFMT_420P16_LE,
77 IMGFMT_420P16_BE,
78 IMGFMT_420A,
79 IMGFMT_IYUV,
80 IMGFMT_YVU9,
81 IMGFMT_IF09,
82 IMGFMT_411P,
83 IMGFMT_NV12,
84 IMGFMT_NV21,
85 IMGFMT_YUY2,
86 IMGFMT_UYVY,
87 IMGFMT_440P,
88 // RGB and grayscale (Y8 and Y800):
89 IMGFMT_BGR32,
90 IMGFMT_RGB32,
91 IMGFMT_BGR24,
92 IMGFMT_RGB24,
93 IMGFMT_RGB48LE,
94 IMGFMT_RGB48BE,
95 IMGFMT_BGR16,
96 IMGFMT_RGB16,
97 IMGFMT_BGR15,
98 IMGFMT_RGB15,
99 IMGFMT_BGR12,
100 IMGFMT_RGB12,
101 IMGFMT_Y800,
102 IMGFMT_Y8,
103 IMGFMT_BGR8,
104 IMGFMT_RGB8,
105 IMGFMT_BGR4,
106 IMGFMT_RGB4,
107 IMGFMT_BG4B,
108 IMGFMT_RG4B,
109 IMGFMT_BGR1,
110 IMGFMT_RGB1,
115 * A list of preferred conversions, in order of preference.
116 * This should be used for conversions that e.g. involve no scaling
117 * or to stop vf_scale from choosing a conversion that has no
118 * fast assembler implementation.
120 static int preferred_conversions[][2] = {
121 {IMGFMT_YUY2, IMGFMT_UYVY},
122 {IMGFMT_YUY2, IMGFMT_422P},
123 {IMGFMT_UYVY, IMGFMT_YUY2},
124 {IMGFMT_UYVY, IMGFMT_422P},
125 {IMGFMT_422P, IMGFMT_YUY2},
126 {IMGFMT_422P, IMGFMT_UYVY},
127 {0, 0}
130 static unsigned int find_best_out(vf_instance_t *vf, int in_format){
131 unsigned int best=0;
132 int i = -1;
133 int j = -1;
134 int format = 0;
136 // find the best outfmt:
137 while (1) {
138 int ret;
139 if (j < 0) {
140 format = in_format;
141 j = 0;
142 } else if (i < 0) {
143 while (preferred_conversions[j][0] &&
144 preferred_conversions[j][0] != in_format)
145 j++;
146 format = preferred_conversions[j++][1];
147 // switch to standard list
148 if (!format)
149 i = 0;
151 if (i >= 0)
152 format = outfmt_list[i++];
153 if (!format)
154 break;
155 ret = vf_next_query_format(vf, format);
157 mp_msg(MSGT_VFILTER,MSGL_DBG2,"scale: query(%s) -> %d\n",vo_format_name(format),ret&3);
158 if(ret&VFCAP_CSP_SUPPORTED_BY_HW){
159 best=format; // no conversion -> bingo!
160 break;
162 if(ret&VFCAP_CSP_SUPPORTED && !best)
163 best=format; // best with conversion
165 return best;
168 static int config(struct vf_instance *vf,
169 int width, int height, int d_width, int d_height,
170 unsigned int flags, unsigned int outfmt){
171 unsigned int best=find_best_out(vf, outfmt);
172 int vo_flags;
173 int int_sws_flags=0;
174 int round_w=0, round_h=0;
175 int i;
176 SwsFilter *srcFilter, *dstFilter;
177 enum PixelFormat dfmt, sfmt;
179 if(!best){
180 mp_msg(MSGT_VFILTER,MSGL_WARN,"SwScale: no supported outfmt found :(\n");
181 return 0;
183 sfmt = imgfmt2pixfmt(outfmt);
184 if (outfmt == IMGFMT_RGB8 || outfmt == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
185 dfmt = imgfmt2pixfmt(best);
187 vo_flags=vf->next->query_format(vf->next,best);
189 // scaling to dwidth*d_height, if all these TRUE:
190 // - option -zoom
191 // - no other sw/hw up/down scaling avail.
192 // - we're after postproc
193 // - user didn't set w:h
194 if(!(vo_flags&VFCAP_POSTPROC) && (flags&4) &&
195 vf->priv->w<0 && vf->priv->h<0){ // -zoom
196 int x=(vo_flags&VFCAP_SWSCALE) ? 0 : 1;
197 if(d_width<width || d_height<height){
198 // downscale!
199 if(vo_flags&VFCAP_HWSCALE_DOWN) x=0;
200 } else {
201 // upscale:
202 if(vo_flags&VFCAP_HWSCALE_UP) x=0;
204 if(x){
205 // user wants sw scaling! (-zoom)
206 vf->priv->w=d_width;
207 vf->priv->h=d_height;
211 if(vf->priv->noup){
212 if((vf->priv->w > width) + (vf->priv->h > height) >= vf->priv->noup){
213 vf->priv->w= width;
214 vf->priv->h= height;
218 if (vf->priv->w <= -8) {
219 vf->priv->w += 8;
220 round_w = 1;
222 if (vf->priv->h <= -8) {
223 vf->priv->h += 8;
224 round_h = 1;
227 if (vf->priv->w < -3 || vf->priv->h < -3 ||
228 (vf->priv->w < -1 && vf->priv->h < -1)) {
229 // TODO: establish a direct connection to the user's brain
230 // and find out what the heck he thinks MPlayer should do
231 // with this nonsense.
232 mp_msg(MSGT_VFILTER, MSGL_ERR, "SwScale: EUSERBROKEN Check your parameters, they make no sense!\n");
233 return 0;
236 if (vf->priv->w == -1)
237 vf->priv->w = width;
238 if (vf->priv->w == 0)
239 vf->priv->w = d_width;
241 if (vf->priv->h == -1)
242 vf->priv->h = height;
243 if (vf->priv->h == 0)
244 vf->priv->h = d_height;
246 if (vf->priv->w == -3)
247 vf->priv->w = vf->priv->h * width / height;
248 if (vf->priv->w == -2)
249 vf->priv->w = vf->priv->h * d_width / d_height;
251 if (vf->priv->h == -3)
252 vf->priv->h = vf->priv->w * height / width;
253 if (vf->priv->h == -2)
254 vf->priv->h = vf->priv->w * d_height / d_width;
256 if (round_w)
257 vf->priv->w = ((vf->priv->w + 8) / 16) * 16;
258 if (round_h)
259 vf->priv->h = ((vf->priv->h + 8) / 16) * 16;
261 // calculate the missing parameters:
262 switch(best) {
263 case IMGFMT_YV12: /* YV12 needs w & h rounded to 2 */
264 case IMGFMT_I420:
265 case IMGFMT_IYUV:
266 case IMGFMT_NV12:
267 case IMGFMT_NV21:
268 vf->priv->h = (vf->priv->h + 1) & ~1;
269 case IMGFMT_YUY2: /* YUY2 needs w rounded to 2 */
270 case IMGFMT_UYVY:
271 vf->priv->w = (vf->priv->w + 1) & ~1;
274 mp_msg(MSGT_VFILTER,MSGL_DBG2,"SwScale: scaling %dx%d %s to %dx%d %s \n",
275 width,height,vo_format_name(outfmt),
276 vf->priv->w,vf->priv->h,vo_format_name(best));
278 // free old ctx:
279 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
280 if(vf->priv->ctx2)sws_freeContext(vf->priv->ctx2);
282 // new swscaler:
283 sws_getFlagsAndFilterFromCmdLine(&int_sws_flags, &srcFilter, &dstFilter);
284 int_sws_flags|= vf->priv->v_chr_drop << SWS_SRC_V_CHR_DROP_SHIFT;
285 int_sws_flags|= vf->priv->accurate_rnd * SWS_ACCURATE_RND;
286 vf->priv->ctx=sws_getContext(width, height >> vf->priv->interlaced,
287 sfmt,
288 vf->priv->w, vf->priv->h >> vf->priv->interlaced,
289 dfmt,
290 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
291 if(vf->priv->interlaced){
292 vf->priv->ctx2=sws_getContext(width, height >> 1,
293 sfmt,
294 vf->priv->w, vf->priv->h >> 1,
295 dfmt,
296 int_sws_flags | get_sws_cpuflags(), srcFilter, dstFilter, vf->priv->param);
298 if(!vf->priv->ctx){
299 // error...
300 mp_msg(MSGT_VFILTER,MSGL_WARN,"Couldn't init SwScaler for this setup\n");
301 return 0;
303 vf->priv->fmt=best;
305 if(vf->priv->palette){
306 free(vf->priv->palette);
307 vf->priv->palette=NULL;
309 switch(best){
310 case IMGFMT_RGB8: {
311 /* set 332 palette for 8 bpp */
312 vf->priv->palette=malloc(4*256);
313 for(i=0; i<256; i++){
314 vf->priv->palette[4*i+0]=4*(i>>6)*21;
315 vf->priv->palette[4*i+1]=4*((i>>3)&7)*9;
316 vf->priv->palette[4*i+2]=4*((i&7)&7)*9;
317 vf->priv->palette[4*i+3]=0;
319 break; }
320 case IMGFMT_BGR8: {
321 /* set 332 palette for 8 bpp */
322 vf->priv->palette=malloc(4*256);
323 for(i=0; i<256; i++){
324 vf->priv->palette[4*i+0]=4*(i&3)*21;
325 vf->priv->palette[4*i+1]=4*((i>>2)&7)*9;
326 vf->priv->palette[4*i+2]=4*((i>>5)&7)*9;
327 vf->priv->palette[4*i+3]=0;
329 break; }
330 case IMGFMT_BGR4:
331 case IMGFMT_BG4B: {
332 vf->priv->palette=malloc(4*16);
333 for(i=0; i<16; i++){
334 vf->priv->palette[4*i+0]=4*(i&1)*63;
335 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
336 vf->priv->palette[4*i+2]=4*((i>>3)&1)*63;
337 vf->priv->palette[4*i+3]=0;
339 break; }
340 case IMGFMT_RGB4:
341 case IMGFMT_RG4B: {
342 vf->priv->palette=malloc(4*16);
343 for(i=0; i<16; i++){
344 vf->priv->palette[4*i+0]=4*(i>>3)*63;
345 vf->priv->palette[4*i+1]=4*((i>>1)&3)*21;
346 vf->priv->palette[4*i+2]=4*((i&1)&1)*63;
347 vf->priv->palette[4*i+3]=0;
349 break; }
352 if(!opt_screen_size_x && !opt_screen_size_y && !(screen_size_xy >= 0.001)){
353 // Compute new d_width and d_height, preserving aspect
354 // while ensuring that both are >= output size in pixels.
355 if (vf->priv->h * d_width > vf->priv->w * d_height) {
356 d_width = vf->priv->h * d_width / d_height;
357 d_height = vf->priv->h;
358 } else {
359 d_height = vf->priv->w * d_height / d_width;
360 d_width = vf->priv->w;
362 //d_width=d_width*vf->priv->w/width;
363 //d_height=d_height*vf->priv->h/height;
365 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
368 static void start_slice(struct vf_instance *vf, mp_image_t *mpi){
369 // printf("start_slice called! flag=%d\n",mpi->flags&MP_IMGFLAG_DRAW_CALLBACK);
370 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK)) return; // shouldn't happen
371 // they want slices!!! allocate the buffer.
372 mpi->priv=vf->dmpi=vf_get_image(vf->next,vf->priv->fmt,
373 // mpi->type, mpi->flags & (~MP_IMGFLAG_DRAW_CALLBACK),
374 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
375 vf->priv->w, vf->priv->h);
378 static void scale(struct SwsContext *sws1, struct SwsContext *sws2, uint8_t *src[MP_MAX_PLANES], int src_stride[MP_MAX_PLANES],
379 int y, int h, uint8_t *dst[MP_MAX_PLANES], int dst_stride[MP_MAX_PLANES], int interlaced){
380 uint8_t *src2[MP_MAX_PLANES]={src[0], src[1], src[2], src[3]};
381 #if HAVE_BIGENDIAN
382 uint32_t pal2[256];
383 if (src[1] && !src[2]){
384 int i;
385 for(i=0; i<256; i++)
386 pal2[i]= bswap_32(((uint32_t*)src[1])[i]);
387 src2[1]= pal2;
389 #endif
391 if(interlaced){
392 int i;
393 uint8_t *dst2[MP_MAX_PLANES]={dst[0], dst[1], dst[2], dst[3]};
394 int src_stride2[MP_MAX_PLANES]={2*src_stride[0], 2*src_stride[1], 2*src_stride[2], 2*src_stride[3]};
395 int dst_stride2[MP_MAX_PLANES]={2*dst_stride[0], 2*dst_stride[1], 2*dst_stride[2], 2*dst_stride[3]};
397 sws_scale(sws1, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
398 for(i=0; i<MP_MAX_PLANES; i++){
399 src2[i] += src_stride[i];
400 dst2[i] += dst_stride[i];
402 sws_scale(sws2, src2, src_stride2, y>>1, h>>1, dst2, dst_stride2);
403 }else{
404 sws_scale(sws1, src2, src_stride, y, h, dst, dst_stride);
408 static void draw_slice(struct vf_instance *vf,
409 unsigned char** src, int* stride, int w,int h, int x, int y){
410 mp_image_t *dmpi=vf->dmpi;
411 if(!dmpi){
412 mp_msg(MSGT_VFILTER,MSGL_FATAL,"vf_scale: draw_slice() called with dmpi=NULL (no get_image?)\n");
413 return;
415 // printf("vf_scale::draw_slice() y=%d h=%d\n",y,h);
416 scale(vf->priv->ctx, vf->priv->ctx2, src, stride, y, h, dmpi->planes, dmpi->stride, vf->priv->interlaced);
419 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){
420 mp_image_t *dmpi=mpi->priv;
422 // printf("vf_scale::put_image(): processing whole frame! dmpi=%p flag=%d\n",
423 // dmpi, (mpi->flags&MP_IMGFLAG_DRAW_CALLBACK));
425 if(!(mpi->flags&MP_IMGFLAG_DRAW_CALLBACK && dmpi)){
427 // hope we'll get DR buffer:
428 dmpi=vf_get_image(vf->next,vf->priv->fmt,
429 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE,
430 vf->priv->w, vf->priv->h);
432 scale(vf->priv->ctx, vf->priv->ctx, mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride, vf->priv->interlaced);
435 if(vf->priv->w==mpi->w && vf->priv->h==mpi->h){
436 // just conversion, no scaling -> keep postprocessing data
437 // this way we can apply pp filter to non-yv12 source using scaler
438 vf_clone_mpi_attributes(dmpi, mpi);
441 if(vf->priv->palette) dmpi->planes[1]=vf->priv->palette; // export palette!
443 return vf_next_put_image(vf,dmpi, pts);
446 static int control(struct vf_instance *vf, int request, void* data){
447 int *table;
448 int *inv_table;
449 int r;
450 int brightness, contrast, saturation, srcRange, dstRange;
451 vf_equalizer_t *eq;
453 if(vf->priv->ctx)
454 switch(request){
455 case VFCTRL_GET_EQUALIZER:
456 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
457 if(r<0) break;
459 eq = data;
460 if (!strcmp(eq->item,"brightness")) {
461 eq->value = ((brightness*100) + (1<<15))>>16;
463 else if (!strcmp(eq->item,"contrast")) {
464 eq->value = (((contrast *100) + (1<<15))>>16) - 100;
466 else if (!strcmp(eq->item,"saturation")) {
467 eq->value = (((saturation*100) + (1<<15))>>16) - 100;
469 else
470 break;
471 return CONTROL_TRUE;
472 case VFCTRL_SET_EQUALIZER:
473 r= sws_getColorspaceDetails(vf->priv->ctx, &inv_table, &srcRange, &table, &dstRange, &brightness, &contrast, &saturation);
474 if(r<0) break;
475 //printf("set %f %f %f\n", brightness/(float)(1<<16), contrast/(float)(1<<16), saturation/(float)(1<<16));
476 eq = data;
478 if (!strcmp(eq->item,"brightness")) {
479 brightness = (( eq->value <<16) + 50)/100;
481 else if (!strcmp(eq->item,"contrast")) {
482 contrast = (((eq->value+100)<<16) + 50)/100;
484 else if (!strcmp(eq->item,"saturation")) {
485 saturation = (((eq->value+100)<<16) + 50)/100;
487 else
488 break;
490 r= sws_setColorspaceDetails(vf->priv->ctx, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
491 if(r<0) break;
492 if(vf->priv->ctx2){
493 r= sws_setColorspaceDetails(vf->priv->ctx2, inv_table, srcRange, table, dstRange, brightness, contrast, saturation);
494 if(r<0) break;
497 return CONTROL_TRUE;
498 default:
499 break;
502 return vf_next_control(vf,request,data);
505 //===========================================================================//
507 // supported Input formats: YV12, I420, IYUV, YUY2, UYVY, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
509 static int query_format(struct vf_instance *vf, unsigned int fmt){
510 switch(fmt){
511 case IMGFMT_YV12:
512 case IMGFMT_I420:
513 case IMGFMT_IYUV:
514 case IMGFMT_UYVY:
515 case IMGFMT_YUY2:
516 case IMGFMT_BGR32:
517 case IMGFMT_BGR24:
518 case IMGFMT_BGR16:
519 case IMGFMT_BGR15:
520 case IMGFMT_RGB32:
521 case IMGFMT_RGB24:
522 case IMGFMT_Y800:
523 case IMGFMT_Y8:
524 case IMGFMT_YVU9:
525 case IMGFMT_IF09:
526 case IMGFMT_444P:
527 case IMGFMT_422P:
528 case IMGFMT_411P:
529 case IMGFMT_440P:
530 case IMGFMT_420A:
531 case IMGFMT_444P16_LE:
532 case IMGFMT_444P16_BE:
533 case IMGFMT_422P16_LE:
534 case IMGFMT_422P16_BE:
535 case IMGFMT_420P16_LE:
536 case IMGFMT_420P16_BE:
537 case IMGFMT_BGR8:
538 case IMGFMT_RGB8:
539 case IMGFMT_BG4B:
540 case IMGFMT_RG4B:
541 case IMGFMT_RGB48LE:
542 case IMGFMT_RGB48BE:
544 unsigned int best=find_best_out(vf, fmt);
545 int flags;
546 if(!best) return 0; // no matching out-fmt
547 flags=vf_next_query_format(vf,best);
548 if(!(flags&(VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW))) return 0; // huh?
549 if(fmt!=best) flags&=~VFCAP_CSP_SUPPORTED_BY_HW;
550 // do not allow scaling, if we are before the PP fliter!
551 if(!(flags&VFCAP_POSTPROC)) flags|=VFCAP_SWSCALE;
552 return flags;
555 return 0; // nomatching in-fmt
558 static void uninit(struct vf_instance *vf){
559 if(vf->priv->ctx) sws_freeContext(vf->priv->ctx);
560 if(vf->priv->ctx2) sws_freeContext(vf->priv->ctx2);
561 if(vf->priv->palette) free(vf->priv->palette);
562 free(vf->priv);
565 static int vf_open(vf_instance_t *vf, char *args){
566 vf->config=config;
567 vf->start_slice=start_slice;
568 vf->draw_slice=draw_slice;
569 vf->put_image=put_image;
570 vf->query_format=query_format;
571 vf->control= control;
572 vf->uninit=uninit;
573 mp_msg(MSGT_VFILTER,MSGL_V,"SwScale params: %d x %d (-1=no scaling)\n",
574 vf->priv->w,
575 vf->priv->h);
577 return 1;
580 //global sws_flags from the command line
581 int sws_flags=2;
583 //global srcFilter
584 static SwsFilter *src_filter= NULL;
586 float sws_lum_gblur= 0.0;
587 float sws_chr_gblur= 0.0;
588 int sws_chr_vshift= 0;
589 int sws_chr_hshift= 0;
590 float sws_chr_sharpen= 0.0;
591 float sws_lum_sharpen= 0.0;
593 int get_sws_cpuflags(void){
594 return
595 (gCpuCaps.hasMMX ? SWS_CPU_CAPS_MMX : 0)
596 | (gCpuCaps.hasMMX2 ? SWS_CPU_CAPS_MMX2 : 0)
597 | (gCpuCaps.has3DNow ? SWS_CPU_CAPS_3DNOW : 0)
598 | (gCpuCaps.hasAltiVec ? SWS_CPU_CAPS_ALTIVEC : 0);
601 void sws_getFlagsAndFilterFromCmdLine(int *flags, SwsFilter **srcFilterParam, SwsFilter **dstFilterParam)
603 static int firstTime=1;
604 *flags=0;
606 #if ARCH_X86
607 if(gCpuCaps.hasMMX)
608 __asm__ volatile("emms\n\t"::: "memory"); //FIXME this should not be required but it IS (even for non-MMX versions)
609 #endif
610 if(firstTime)
612 firstTime=0;
613 *flags= SWS_PRINT_INFO;
615 else if( mp_msg_test(MSGT_VFILTER,MSGL_DBG2) ) *flags= SWS_PRINT_INFO;
617 if(src_filter) sws_freeFilter(src_filter);
619 src_filter= sws_getDefaultFilter(
620 sws_lum_gblur, sws_chr_gblur,
621 sws_lum_sharpen, sws_chr_sharpen,
622 sws_chr_hshift, sws_chr_vshift, verbose>1);
624 switch(sws_flags)
626 case 0: *flags|= SWS_FAST_BILINEAR; break;
627 case 1: *flags|= SWS_BILINEAR; break;
628 case 2: *flags|= SWS_BICUBIC; break;
629 case 3: *flags|= SWS_X; break;
630 case 4: *flags|= SWS_POINT; break;
631 case 5: *flags|= SWS_AREA; break;
632 case 6: *flags|= SWS_BICUBLIN; break;
633 case 7: *flags|= SWS_GAUSS; break;
634 case 8: *flags|= SWS_SINC; break;
635 case 9: *flags|= SWS_LANCZOS; break;
636 case 10:*flags|= SWS_SPLINE; break;
637 default:*flags|= SWS_BILINEAR; break;
640 *srcFilterParam= src_filter;
641 *dstFilterParam= NULL;
644 // will use sws_flags & src_filter (from cmd line)
645 struct SwsContext *sws_getContextFromCmdLine(int srcW, int srcH, int srcFormat, int dstW, int dstH, int dstFormat)
647 int flags;
648 SwsFilter *dstFilterParam, *srcFilterParam;
649 enum PixelFormat dfmt, sfmt;
651 dfmt = imgfmt2pixfmt(dstFormat);
652 sfmt = imgfmt2pixfmt(srcFormat);
653 if (srcFormat == IMGFMT_RGB8 || srcFormat == IMGFMT_BGR8) sfmt = PIX_FMT_PAL8;
654 sws_getFlagsAndFilterFromCmdLine(&flags, &srcFilterParam, &dstFilterParam);
656 return sws_getContext(srcW, srcH, sfmt, dstW, dstH, dfmt, flags | get_sws_cpuflags(), srcFilterParam, dstFilterParam, NULL);
659 /// An example of presets usage
660 static const struct size_preset {
661 char* name;
662 int w, h;
663 } vf_size_presets_defs[] = {
664 // TODO add more 'standard' resolutions
665 { "qntsc", 352, 240 },
666 { "qpal", 352, 288 },
667 { "ntsc", 720, 480 },
668 { "pal", 720, 576 },
669 { "sntsc", 640, 480 },
670 { "spal", 768, 576 },
671 { NULL, 0, 0}
674 #define ST_OFF(f) M_ST_OFF(struct size_preset,f)
675 static const m_option_t vf_size_preset_fields[] = {
676 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
677 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,1 ,0, NULL},
678 { NULL, NULL, 0, 0, 0, 0, NULL }
681 static const m_struct_t vf_size_preset = {
682 "scale_size_preset",
683 sizeof(struct size_preset),
684 NULL,
685 vf_size_preset_fields
688 static const m_struct_t vf_opts;
689 static const m_obj_presets_t size_preset = {
690 &vf_size_preset, // Input struct desc
691 &vf_opts, // Output struct desc
692 vf_size_presets_defs, // The list of presets
693 ST_OFF(name) // At wich offset is the name field in the preset struct
696 /// Now the options
697 #undef ST_OFF
698 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
699 static const m_option_t vf_opts_fields[] = {
700 {"w", ST_OFF(w), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
701 {"h", ST_OFF(h), CONF_TYPE_INT, M_OPT_MIN,-11,0, NULL},
702 {"interlaced", ST_OFF(interlaced), CONF_TYPE_INT, M_OPT_RANGE, 0, 1, NULL},
703 {"chr-drop", ST_OFF(v_chr_drop), CONF_TYPE_INT, M_OPT_RANGE, 0, 3, NULL},
704 {"param" , ST_OFF(param[0]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
705 {"param2", ST_OFF(param[1]), CONF_TYPE_DOUBLE, M_OPT_RANGE, 0.0, 100.0, NULL},
706 // Note that here the 2 field is NULL (ie 0)
707 // As we want this option to act on the option struct itself
708 {"presize", 0, CONF_TYPE_OBJ_PRESETS, 0, 0, 0, &size_preset},
709 {"noup", ST_OFF(noup), CONF_TYPE_INT, M_OPT_RANGE, 0, 2, NULL},
710 {"arnd", ST_OFF(accurate_rnd), CONF_TYPE_FLAG, 0, 0, 1, NULL},
711 { NULL, NULL, 0, 0, 0, 0, NULL }
714 static const m_struct_t vf_opts = {
715 "scale",
716 sizeof(struct vf_priv_s),
717 &vf_priv_dflt,
718 vf_opts_fields
721 const vf_info_t vf_info_scale = {
722 "software scaling",
723 "scale",
724 "A'rpi",
726 vf_open,
727 &vf_opts
730 //===========================================================================//