6061
|
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
|
|
9 #include "img_format.h"
|
|
10 #include "mp_image.h"
|
|
11 #include "vf.h"
|
|
12
|
|
13 #include "../libvo/fastmemcpy.h"
|
|
14 #include "../postproc/rgb2rgb.h"
|
|
15
|
|
16 struct vf_priv_s {
|
|
17 int x1,y1,x2,y2;
|
|
18 int limit;
|
6118
|
19 int fno;
|
6061
|
20 };
|
|
21
|
|
22 static int checkline(unsigned char* src,int stride,int len,int bpp){
|
|
23 int total=0;
|
|
24 int div=len;
|
|
25 int x;
|
|
26 switch(bpp){
|
|
27 case 1:
|
|
28 while(--len>=0){
|
|
29 total+=src[0]; src+=stride;
|
|
30 }
|
|
31 break;
|
|
32 case 3:
|
|
33 case 4:
|
|
34 while(--len>=0){
|
|
35 total+=src[0]+src[1]+src[2]; src+=stride;
|
|
36 }
|
|
37 div*=3;
|
|
38 break;
|
|
39 }
|
|
40 total/=div;
|
|
41 // printf("total=%d\n",total);
|
|
42 return total;
|
|
43 }
|
|
44
|
|
45 //===========================================================================//
|
|
46
|
|
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;
|
|
51 vf->priv->y1=height;
|
|
52 vf->priv->x2=0;
|
|
53 vf->priv->y2=0;
|
6118
|
54 vf->priv->fno=0;
|
6061
|
55 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt);
|
|
56 }
|
|
57
|
|
58 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){
|
|
59 mp_image_t *dmpi;
|
|
60 int bpp=mpi->bpp/8;
|
|
61 int x,y;
|
|
62
|
|
63 // hope we'll get DR buffer:
|
|
64 dmpi=vf_get_image(vf->next,mpi->imgfmt,
|
|
65 MP_IMGTYPE_EXPORT, 0,
|
|
66 mpi->w, mpi->h);
|
|
67
|
|
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;
|
|
76
|
6118
|
77 if(++vf->priv->fno>2){ // ignore first 2 frames - they may be empty
|
6061
|
78
|
|
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){
|
|
81 vf->priv->y1=y;
|
|
82 break;
|
|
83 }
|
|
84 }
|
|
85
|
|
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){
|
|
88 vf->priv->y2=y;
|
|
89 break;
|
|
90 }
|
|
91 }
|
|
92
|
|
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){
|
|
95 vf->priv->x1=y;
|
|
96 break;
|
|
97 }
|
|
98 }
|
|
99
|
|
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){
|
|
102 vf->priv->x2=y;
|
|
103 break;
|
|
104 }
|
|
105 }
|
|
106
|
|
107 x=(vf->priv->x1+1)&(~1);
|
|
108 y=(vf->priv->y1+1)&(~1);
|
|
109
|
|
110 printf("crop area: X: %d..%d Y: %d..%d (-vop crop=%d:%d:%d:%d)\n",
|
|
111 vf->priv->x1,vf->priv->x2,
|
|
112 vf->priv->y1,vf->priv->y2,
|
6117
|
113 (vf->priv->x2+1-x)&(~1),(vf->priv->y2+1-y)&(~1),x,y
|
6061
|
114 );
|
|
115
|
6118
|
116 }
|
|
117
|
6061
|
118 vf_next_put_image(vf,dmpi);
|
|
119 }
|
|
120
|
|
121 //===========================================================================//
|
|
122
|
|
123 static int open(vf_instance_t *vf, char* args){
|
|
124 vf->config=config;
|
|
125 vf->put_image=put_image;
|
|
126 vf->priv=malloc(sizeof(struct vf_priv_s));
|
|
127 vf->priv->limit=24; // should be option
|
6610
|
128 if(args) vf->priv->limit=atoi(args);
|
6061
|
129 return 1;
|
|
130 }
|
|
131
|
|
132 vf_info_t vf_info_cropdetect = {
|
|
133 "autodetect crop size",
|
|
134 "cropdetect",
|
|
135 "A'rpi",
|
|
136 "",
|
|
137 open
|
|
138 };
|
|
139
|
|
140 //===========================================================================//
|