10 #include "img_format.h"
14 #include "libvo/fastmemcpy.h"
23 static int checkline(unsigned char* src
,int stride
,int len
,int bpp
){
29 total
+=src
[0]; src
+=stride
;
35 total
+=src
[0]+src
[1]+src
[2]; src
+=stride
;
41 // printf("total=%d\n",total);
45 //===========================================================================//
47 static int config(struct vf_instance_s
* vf
,
48 int width
, int height
, int d_width
, int d_height
,
49 unsigned int flags
, unsigned int outfmt
){
50 vf
->priv
->x1
=width
- 1;
51 vf
->priv
->y1
=height
- 1;
55 return vf_next_config(vf
,width
,height
,d_width
,d_height
,flags
,outfmt
);
58 static int put_image(struct vf_instance_s
* vf
, mp_image_t
*mpi
, double pts
){
61 int w
,h
,x
,y
,shrink_by
;
63 // hope we'll get DR buffer:
64 dmpi
=vf_get_image(vf
->next
,mpi
->imgfmt
,
68 dmpi
->planes
[0]=mpi
->planes
[0];
69 dmpi
->planes
[1]=mpi
->planes
[1];
70 dmpi
->planes
[2]=mpi
->planes
[2];
71 dmpi
->stride
[0]=mpi
->stride
[0];
72 dmpi
->stride
[1]=mpi
->stride
[1];
73 dmpi
->stride
[2]=mpi
->stride
[2];
74 dmpi
->width
=mpi
->width
;
75 dmpi
->height
=mpi
->height
;
77 if(++vf
->priv
->fno
>2){ // ignore first 2 frames - they may be empty
79 for(y
=0;y
<vf
->priv
->y1
;y
++){
80 if(checkline(mpi
->planes
[0]+mpi
->stride
[0]*y
,bpp
,mpi
->w
,bpp
)>vf
->priv
->limit
){
86 for(y
=mpi
->h
-1;y
>vf
->priv
->y2
;y
--){
87 if(checkline(mpi
->planes
[0]+mpi
->stride
[0]*y
,bpp
,mpi
->w
,bpp
)>vf
->priv
->limit
){
93 for(y
=0;y
<vf
->priv
->x1
;y
++){
94 if(checkline(mpi
->planes
[0]+bpp
*y
,mpi
->stride
[0],mpi
->h
,bpp
)>vf
->priv
->limit
){
100 for(y
=mpi
->w
-1;y
>vf
->priv
->x2
;y
--){
101 if(checkline(mpi
->planes
[0]+bpp
*y
,mpi
->stride
[0],mpi
->h
,bpp
)>vf
->priv
->limit
){
107 // round x and y (up), important for yuv colorspaces
108 // make sure they stay rounded!
109 x
=(vf
->priv
->x1
+1)&(~1);
110 y
=(vf
->priv
->y1
+1)&(~1);
112 w
= vf
->priv
->x2
- x
+ 1;
113 h
= vf
->priv
->y2
- y
+ 1;
115 // w and h must be divisible by 2 as well because of yuv
116 // colorspace problems.
117 if (vf
->priv
->round
<= 1)
118 vf
->priv
->round
= 16;
119 if (vf
->priv
->round
% 2)
120 vf
->priv
->round
*= 2;
122 shrink_by
= w
% vf
->priv
->round
;
124 x
+= (shrink_by
/ 2 + 1) & ~1;
126 shrink_by
= h
% vf
->priv
->round
;
128 y
+= (shrink_by
/ 2 + 1) & ~1;
130 mp_msg(MSGT_VFILTER
, MSGL_INFO
, MSGTR_MPCODECS_CropArea
,
131 vf
->priv
->x1
,vf
->priv
->x2
,
132 vf
->priv
->y1
,vf
->priv
->y2
,
138 return vf_next_put_image(vf
,dmpi
, pts
);
141 static int query_format(struct vf_instance_s
* vf
, unsigned int fmt
) {
143 // the default limit value works only right with YV12 right now.
145 return vf_next_query_format(vf
, fmt
);
149 //===========================================================================//
151 static int open(vf_instance_t
*vf
, char* args
){
153 vf
->put_image
=put_image
;
154 vf
->query_format
=query_format
;
155 vf
->priv
=malloc(sizeof(struct vf_priv_s
));
156 vf
->priv
->limit
=24; // should be option
158 if(args
) sscanf(args
, "%d:%d",
164 vf_info_t vf_info_cropdetect
= {
165 "autodetect crop size",
173 //===========================================================================//