Mercurial > mplayer.hg
annotate libmpcodecs/vf_cropdetect.c @ 18162:1b4bf0c9ecb3
simplified code to patch the video framerate (removed silly comparisons)
author | nicodvb |
---|---|
date | Thu, 20 Apr 2006 20:38:09 +0000 |
parents | bcd805923554 |
children | 497ebe3ecc2b |
rev | line source |
---|---|
6061 | 1 #include <stdio.h> |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <inttypes.h> | |
5 | |
17012 | 6 #include "config.h" |
7 #include "mp_msg.h" | |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17906
diff
changeset
|
8 #include "help_mp.h" |
6061 | 9 |
10 #include "img_format.h" | |
11 #include "mp_image.h" | |
12 #include "vf.h" | |
13 | |
17012 | 14 #include "libvo/fastmemcpy.h" |
15 #include "postproc/rgb2rgb.h" | |
6061 | 16 |
17 struct vf_priv_s { | |
18 int x1,y1,x2,y2; | |
19 int limit; | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
20 int round; |
6118 | 21 int fno; |
6061 | 22 }; |
23 | |
24 static int checkline(unsigned char* src,int stride,int len,int bpp){ | |
25 int total=0; | |
26 int div=len; | |
27 switch(bpp){ | |
28 case 1: | |
29 while(--len>=0){ | |
30 total+=src[0]; src+=stride; | |
31 } | |
32 break; | |
33 case 3: | |
34 case 4: | |
35 while(--len>=0){ | |
36 total+=src[0]+src[1]+src[2]; src+=stride; | |
37 } | |
38 div*=3; | |
39 break; | |
40 } | |
41 total/=div; | |
42 // printf("total=%d\n",total); | |
43 return total; | |
44 } | |
45 | |
46 //===========================================================================// | |
47 | |
48 static int config(struct vf_instance_s* vf, | |
49 int width, int height, int d_width, int d_height, | |
50 unsigned int flags, unsigned int outfmt){ | |
14588
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
51 vf->priv->x1=width - 1; |
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
52 vf->priv->y1=height - 1; |
6061 | 53 vf->priv->x2=0; |
54 vf->priv->y2=0; | |
6118 | 55 vf->priv->fno=0; |
6061 | 56 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
57 } | |
58 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
59 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts){ |
6061 | 60 mp_image_t *dmpi; |
61 int bpp=mpi->bpp/8; | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
62 int w,h,x,y,shrink_by; |
6061 | 63 |
64 // hope we'll get DR buffer: | |
65 dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
66 MP_IMGTYPE_EXPORT, 0, | |
67 mpi->w, mpi->h); | |
68 | |
69 dmpi->planes[0]=mpi->planes[0]; | |
70 dmpi->planes[1]=mpi->planes[1]; | |
71 dmpi->planes[2]=mpi->planes[2]; | |
72 dmpi->stride[0]=mpi->stride[0]; | |
73 dmpi->stride[1]=mpi->stride[1]; | |
74 dmpi->stride[2]=mpi->stride[2]; | |
75 dmpi->width=mpi->width; | |
76 dmpi->height=mpi->height; | |
77 | |
6118 | 78 if(++vf->priv->fno>2){ // ignore first 2 frames - they may be empty |
6061 | 79 |
80 for(y=0;y<vf->priv->y1;y++){ | |
81 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
82 vf->priv->y1=y; | |
83 break; | |
84 } | |
85 } | |
86 | |
87 for(y=mpi->h-1;y>vf->priv->y2;y--){ | |
88 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
89 vf->priv->y2=y; | |
90 break; | |
91 } | |
92 } | |
93 | |
94 for(y=0;y<vf->priv->x1;y++){ | |
95 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
96 vf->priv->x1=y; | |
97 break; | |
98 } | |
99 } | |
100 | |
101 for(y=mpi->w-1;y>vf->priv->x2;y--){ | |
102 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
103 vf->priv->x2=y; | |
104 break; | |
105 } | |
106 } | |
107 | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
108 // round x and y (up), important for yuv colorspaces |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
109 // make sure they stay rounded! |
6061 | 110 x=(vf->priv->x1+1)&(~1); |
111 y=(vf->priv->y1+1)&(~1); | |
112 | |
14588
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
113 w = vf->priv->x2 - x + 1; |
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
114 h = vf->priv->y2 - y + 1; |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
115 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
116 // w and h must be divisible by 2 as well because of yuv |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
117 // colorspace problems. |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
118 if (vf->priv->round <= 1) |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
119 vf->priv->round = 16; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
120 if (vf->priv->round % 2) |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
121 vf->priv->round *= 2; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
122 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
123 shrink_by = w % vf->priv->round; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
124 w -= shrink_by; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
125 x += (shrink_by / 2 + 1) & ~1; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
126 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
127 shrink_by = h % vf->priv->round; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
128 h -= shrink_by; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
129 y += (shrink_by / 2 + 1) & ~1; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
130 |
18004
bcd805923554
Part2 of several printf2mp_msg changes in patch from Otvos Attila oattila AT chello DOT hu with LOTS of modifications by me
reynaldo
parents:
17906
diff
changeset
|
131 mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea, |
6061 | 132 vf->priv->x1,vf->priv->x2, |
133 vf->priv->y1,vf->priv->y2, | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
134 w,h,x,y); |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
135 |
6061 | 136 |
6118 | 137 } |
138 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
139 return vf_next_put_image(vf,dmpi, pts); |
6061 | 140 } |
141 | |
16107
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
142 static int query_format(struct vf_instance_s* vf, unsigned int fmt) { |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
143 switch(fmt) { |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
144 // the default limit value works only right with YV12 right now. |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
145 case IMGFMT_YV12: |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
146 return vf_next_query_format(vf, fmt); |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
147 } |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
148 return 0; |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
149 } |
6061 | 150 //===========================================================================// |
151 | |
152 static int open(vf_instance_t *vf, char* args){ | |
153 vf->config=config; | |
154 vf->put_image=put_image; | |
16107
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
155 vf->query_format=query_format; |
6061 | 156 vf->priv=malloc(sizeof(struct vf_priv_s)); |
157 vf->priv->limit=24; // should be option | |
13233 | 158 vf->priv->round = 0; |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
159 if(args) sscanf(args, "%d:%d", |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
160 &vf->priv->limit, |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
161 &vf->priv->round); |
6061 | 162 return 1; |
163 } | |
164 | |
165 vf_info_t vf_info_cropdetect = { | |
166 "autodetect crop size", | |
167 "cropdetect", | |
168 "A'rpi", | |
169 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7472
diff
changeset
|
170 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7472
diff
changeset
|
171 NULL |
6061 | 172 }; |
173 | |
174 //===========================================================================// |