Mercurial > mplayer.hg
annotate libmpcodecs/vf_cropdetect.c @ 32072:b793cbb9afd1
swscale: remove unused code
yvu9ToYv12Wrapper() used to support yv12 with the chroma planes either in the
uv order or the vu order. FFmpeg no longer has a pixel format in vu order.
author | ramiro |
---|---|
date | Sat, 11 Sep 2010 14:30:54 +0000 |
parents | a972c1a4a012 |
children | 7af3e6f901fd |
rev | line source |
---|---|
30421
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
1 /* |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
2 * This file is part of MPlayer. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
3 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
4 * MPlayer is free software; you can redistribute it and/or modify |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
6 * the Free Software Foundation; either version 2 of the License, or |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
7 * (at your option) any later version. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
8 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
9 * MPlayer is distributed in the hope that it will be useful, |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
12 * GNU General Public License for more details. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
13 * |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
14 * You should have received a copy of the GNU General Public License along |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
15 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
17 */ |
bbb6ebec87a0
Add missing license headers to all files in the libmpcodecs directory.
diego
parents:
30394
diff
changeset
|
18 |
6061 | 19 #include <stdio.h> |
20 #include <stdlib.h> | |
21 #include <string.h> | |
22 #include <inttypes.h> | |
23 | |
17012 | 24 #include "config.h" |
25 #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
|
26 #include "help_mp.h" |
6061 | 27 |
28 #include "img_format.h" | |
29 #include "mp_image.h" | |
30 #include "vf.h" | |
31 | |
32 struct vf_priv_s { | |
33 int x1,y1,x2,y2; | |
34 int limit; | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
35 int round; |
30394
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
36 int reset_count; |
6118 | 37 int fno; |
6061 | 38 }; |
39 | |
40 static int checkline(unsigned char* src,int stride,int len,int bpp){ | |
41 int total=0; | |
42 int div=len; | |
43 switch(bpp){ | |
44 case 1: | |
45 while(--len>=0){ | |
46 total+=src[0]; src+=stride; | |
47 } | |
48 break; | |
49 case 3: | |
50 case 4: | |
51 while(--len>=0){ | |
52 total+=src[0]+src[1]+src[2]; src+=stride; | |
53 } | |
54 div*=3; | |
55 break; | |
56 } | |
57 total/=div; | |
58 // printf("total=%d\n",total); | |
59 return total; | |
60 } | |
61 | |
62 //===========================================================================// | |
63 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
64 static int config(struct vf_instance *vf, |
6061 | 65 int width, int height, int d_width, int d_height, |
66 unsigned int flags, unsigned int outfmt){ | |
14588
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
67 vf->priv->x1=width - 1; |
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
68 vf->priv->y1=height - 1; |
6061 | 69 vf->priv->x2=0; |
70 vf->priv->y2=0; | |
30394
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
71 vf->priv->fno=-2; |
6061 | 72 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
73 } | |
74 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
75 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts){ |
6061 | 76 mp_image_t *dmpi; |
77 int bpp=mpi->bpp/8; | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
78 int w,h,x,y,shrink_by; |
6061 | 79 |
80 // hope we'll get DR buffer: | |
81 dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
82 MP_IMGTYPE_EXPORT, 0, | |
83 mpi->w, mpi->h); | |
84 | |
85 dmpi->planes[0]=mpi->planes[0]; | |
86 dmpi->planes[1]=mpi->planes[1]; | |
87 dmpi->planes[2]=mpi->planes[2]; | |
88 dmpi->stride[0]=mpi->stride[0]; | |
89 dmpi->stride[1]=mpi->stride[1]; | |
90 dmpi->stride[2]=mpi->stride[2]; | |
91 dmpi->width=mpi->width; | |
92 dmpi->height=mpi->height; | |
93 | |
30394
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
94 if(++vf->priv->fno>0){ // ignore first 2 frames - they may be empty |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
95 |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
96 // Reset the crop area every reset_count frames, if reset_count is > 0 |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
97 if(vf->priv->reset_count > 0 && vf->priv->fno > vf->priv->reset_count){ |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
98 vf->priv->x1=mpi->w-1; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
99 vf->priv->y1=mpi->h-1; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
100 vf->priv->x2=0; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
101 vf->priv->y2=0; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
102 vf->priv->fno=1; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
103 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25221
diff
changeset
|
104 |
6061 | 105 for(y=0;y<vf->priv->y1;y++){ |
106 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
107 vf->priv->y1=y; | |
108 break; | |
109 } | |
110 } | |
111 | |
112 for(y=mpi->h-1;y>vf->priv->y2;y--){ | |
113 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
114 vf->priv->y2=y; | |
115 break; | |
116 } | |
117 } | |
118 | |
119 for(y=0;y<vf->priv->x1;y++){ | |
120 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
121 vf->priv->x1=y; | |
122 break; | |
123 } | |
124 } | |
125 | |
126 for(y=mpi->w-1;y>vf->priv->x2;y--){ | |
127 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
128 vf->priv->x2=y; | |
129 break; | |
130 } | |
131 } | |
132 | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
133 // round x and y (up), important for yuv colorspaces |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
134 // make sure they stay rounded! |
6061 | 135 x=(vf->priv->x1+1)&(~1); |
136 y=(vf->priv->y1+1)&(~1); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
25221
diff
changeset
|
137 |
14588
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
138 w = vf->priv->x2 - x + 1; |
36b24b57ab53
x1 and y1 give last used position, must be < width/height
reimar
parents:
13233
diff
changeset
|
139 h = vf->priv->y2 - y + 1; |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
140 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
141 // 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
|
142 // colorspace problems. |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
143 if (vf->priv->round <= 1) |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
144 vf->priv->round = 16; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
145 if (vf->priv->round % 2) |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
146 vf->priv->round *= 2; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
147 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
148 shrink_by = w % vf->priv->round; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
149 w -= shrink_by; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
150 x += (shrink_by / 2 + 1) & ~1; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
151 |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
152 shrink_by = h % vf->priv->round; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
153 h -= shrink_by; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
154 y += (shrink_by / 2 + 1) & ~1; |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
155 |
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
|
156 mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_CropArea, |
6061 | 157 vf->priv->x1,vf->priv->x2, |
158 vf->priv->y1,vf->priv->y2, | |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
159 w,h,x,y); |
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
160 |
6061 | 161 |
6118 | 162 } |
163 | |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
164 return vf_next_put_image(vf,dmpi, pts); |
6061 | 165 } |
166 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
167 static int query_format(struct vf_instance *vf, unsigned int fmt) { |
16107
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
168 switch(fmt) { |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
169 // 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
|
170 case IMGFMT_YV12: |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
171 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
|
172 } |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
173 return 0; |
8d4a3c9001de
restrict to YV12 since the default limit does not work well for anything else.
reimar
parents:
14588
diff
changeset
|
174 } |
6061 | 175 //===========================================================================// |
176 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
177 static int vf_open(vf_instance_t *vf, char *args){ |
6061 | 178 vf->config=config; |
179 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
|
180 vf->query_format=query_format; |
6061 | 181 vf->priv=malloc(sizeof(struct vf_priv_s)); |
182 vf->priv->limit=24; // should be option | |
13233 | 183 vf->priv->round = 0; |
30394
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
184 vf->priv->reset_count = 0; |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
185 if(args) sscanf(args, "%d:%d:%d", |
13205
08bb01a9905a
Adds rounding parameter for width and height values returned.
reimar
parents:
11261
diff
changeset
|
186 &vf->priv->limit, |
30394
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
187 &vf->priv->round, |
55bf07ab4c89
Add an option to cropdetect to periodically reset the detected area.
reimar
parents:
29263
diff
changeset
|
188 &vf->priv->reset_count); |
6061 | 189 return 1; |
190 } | |
191 | |
25221 | 192 const vf_info_t vf_info_cropdetect = { |
6061 | 193 "autodetect crop size", |
194 "cropdetect", | |
195 "A'rpi", | |
196 "", | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30421
diff
changeset
|
197 vf_open, |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7472
diff
changeset
|
198 NULL |
6061 | 199 }; |
200 | |
201 //===========================================================================// |