5522
|
1 #include <stdio.h>
|
|
2 #include <stdlib.h>
|
|
3 #include <string.h>
|
|
4 #include <inttypes.h>
|
|
5
|
|
6 #include "../config.h"
|
|
7 #include "../mp_msg.h"
|
|
8
|
5523
|
9 #include "../libvo/img_format.h"
|
5522
|
10 #include "../mp_image.h"
|
|
11 #include "vf.h"
|
|
12
|
|
13 #include "../libvo/fastmemcpy.h"
|
|
14 #include "../postproc/swscale.h"
|
|
15
|
|
16 struct vf_priv_s {
|
|
17 int w,h;
|
5523
|
18 unsigned int fmt;
|
5522
|
19 SwsContext *ctx;
|
|
20 };
|
|
21
|
|
22 //===========================================================================//
|
|
23
|
5523
|
24 static unsigned int outfmt_list[]={
|
|
25 IMGFMT_BGR32,
|
|
26 IMGFMT_BGR24,
|
|
27 IMGFMT_BGR16,
|
|
28 IMGFMT_BGR15,
|
|
29 IMGFMT_YV12,
|
|
30 IMGFMT_I420,
|
|
31 IMGFMT_IYUV,
|
|
32 NULL
|
|
33 };
|
|
34
|
5522
|
35 static int config(struct vf_instance_s* vf,
|
|
36 int width, int height, int d_width, int d_height,
|
|
37 unsigned int flags, unsigned int outfmt){
|
5523
|
38 unsigned int* p=outfmt_list;
|
|
39 unsigned int best=0;
|
|
40 // find the best outfmt:
|
|
41 while(*p){
|
|
42 int ret=vf_next_query_format(vf,*p);
|
|
43 mp_msg(MSGT_VFILTER,MSGL_V,"scale: query(%s) -> %d\n",vo_format_name(*p),ret&3);
|
|
44 if(ret&2){ best=*p; break;} // no conversion -> bingo!
|
|
45 if(ret&1 && !best) best=*p; // best with conversion
|
|
46 ++p;
|
|
47 }
|
|
48 if(!best){
|
|
49 printf("SwScale: no supported outfmt found :(\n");
|
|
50 return 0;
|
|
51 }
|
|
52
|
5522
|
53 // calculate the missing parameters:
|
|
54 if(vf->priv->w<=0) vf->priv->w=width;
|
|
55 if(vf->priv->h<=0) vf->priv->h=height;
|
5523
|
56
|
|
57 printf("SwScale scaling %dx%d %s to %dx%d %s \n",
|
|
58 width,height,vo_format_name(outfmt),
|
|
59 vf->priv->w,vf->priv->h,vo_format_name(best));
|
|
60
|
5522
|
61 // new swscaler:
|
|
62 vf->priv->ctx=getSwsContextFromCmdLine(width,height,outfmt,
|
5523
|
63 vf->priv->w,vf->priv->h,best);
|
5522
|
64 if(!vf->priv->ctx){
|
|
65 // error...
|
|
66 printf("Couldn't init SwScaler for this setup\n");
|
|
67 return 0;
|
|
68 }
|
5523
|
69 vf->priv->fmt=best;
|
5525
|
70 return vf_next_config(vf,vf->priv->w,vf->priv->h,d_width,d_height,flags,best);
|
5522
|
71 }
|
|
72
|
|
73 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
|
74 mp_image_t *dmpi;
|
|
75
|
|
76 // hope we'll get DR buffer:
|
5523
|
77 dmpi=vf_get_image(vf->next,vf->priv->fmt,
|
5522
|
78 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
|
|
79 vf->priv->w, vf->priv->h);
|
|
80
|
|
81 vf->priv->ctx->swScale(vf->priv->ctx,mpi->planes,mpi->stride,0,mpi->h,dmpi->planes,dmpi->stride);
|
|
82
|
|
83 vf_next_put_image(vf,dmpi);
|
|
84 }
|
|
85
|
|
86 //===========================================================================//
|
|
87
|
5523
|
88 // supported Input formats: YV12, I420, IYUV, YUY2, BGR32, BGR24, BGR16, BGR15, RGB32, RGB24, Y8, Y800
|
|
89
|
|
90 static int query_format(struct vf_instance_s* vf, unsigned int fmt){
|
|
91 switch(fmt){
|
|
92 case IMGFMT_YV12:
|
|
93 case IMGFMT_I420:
|
|
94 case IMGFMT_IYUV:
|
|
95 case IMGFMT_YUY2:
|
|
96 case IMGFMT_BGR32:
|
|
97 case IMGFMT_BGR24:
|
|
98 case IMGFMT_BGR16:
|
|
99 case IMGFMT_BGR15:
|
|
100 case IMGFMT_RGB32:
|
|
101 case IMGFMT_RGB24:
|
|
102 case IMGFMT_Y800:
|
|
103 return 3; //vf_next_query_format(vf,fmt);
|
|
104 }
|
|
105 return 0;
|
|
106 }
|
|
107
|
5522
|
108 static int open(vf_instance_t *vf, char* args){
|
|
109 vf->config=config;
|
|
110 vf->put_image=put_image;
|
|
111 vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
112 // TODO: parse args ->
|
|
113 vf->priv->ctx=NULL;
|
|
114 vf->priv->w=
|
|
115 vf->priv->h=-1;
|
|
116 if(args) sscanf(args, "%d:%d",
|
|
117 &vf->priv->w,
|
|
118 &vf->priv->h);
|
|
119 printf("SwScale: %d x %d\n",
|
|
120 vf->priv->w,
|
|
121 vf->priv->h);
|
|
122 return 1;
|
|
123 }
|
|
124
|
|
125 vf_info_t vf_info_scale = {
|
|
126 "software scaling",
|
|
127 "scale",
|
|
128 "A'rpi",
|
|
129 "",
|
|
130 open
|
|
131 };
|
|
132
|
|
133 //===========================================================================//
|