Mercurial > mplayer.hg
comparison libmpcodecs/vf_cropdetect.c @ 6061:5343ef6b8c23
new filter, to detect best crop size
author | arpi |
---|---|
date | Sun, 12 May 2002 19:06:54 +0000 |
parents | |
children | 0c33406d2a83 |
comparison
equal
deleted
inserted
replaced
6060:61f39b98ba4d | 6061:5343ef6b8c23 |
---|---|
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; | |
19 }; | |
20 | |
21 static int checkline(unsigned char* src,int stride,int len,int bpp){ | |
22 int total=0; | |
23 int div=len; | |
24 int x; | |
25 switch(bpp){ | |
26 case 1: | |
27 while(--len>=0){ | |
28 total+=src[0]; src+=stride; | |
29 } | |
30 break; | |
31 case 3: | |
32 case 4: | |
33 while(--len>=0){ | |
34 total+=src[0]+src[1]+src[2]; src+=stride; | |
35 } | |
36 div*=3; | |
37 break; | |
38 } | |
39 total/=div; | |
40 // printf("total=%d\n",total); | |
41 return total; | |
42 } | |
43 | |
44 //===========================================================================// | |
45 | |
46 static int config(struct vf_instance_s* vf, | |
47 int width, int height, int d_width, int d_height, | |
48 unsigned int flags, unsigned int outfmt){ | |
49 vf->priv->x1=width; | |
50 vf->priv->y1=height; | |
51 vf->priv->x2=0; | |
52 vf->priv->y2=0; | |
53 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); | |
54 } | |
55 | |
56 static void put_image(struct vf_instance_s* vf, mp_image_t *mpi){ | |
57 mp_image_t *dmpi; | |
58 int bpp=mpi->bpp/8; | |
59 int x,y; | |
60 | |
61 // hope we'll get DR buffer: | |
62 dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
63 MP_IMGTYPE_EXPORT, 0, | |
64 mpi->w, mpi->h); | |
65 | |
66 dmpi->planes[0]=mpi->planes[0]; | |
67 dmpi->planes[1]=mpi->planes[1]; | |
68 dmpi->planes[2]=mpi->planes[2]; | |
69 dmpi->stride[0]=mpi->stride[0]; | |
70 dmpi->stride[1]=mpi->stride[1]; | |
71 dmpi->stride[2]=mpi->stride[2]; | |
72 dmpi->width=mpi->width; | |
73 dmpi->height=mpi->height; | |
74 | |
75 //static int checkline(unsigned char* src,int stride,int len,int bpp){ | |
76 | |
77 for(y=0;y<vf->priv->y1;y++){ | |
78 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
79 vf->priv->y1=y; | |
80 break; | |
81 } | |
82 } | |
83 | |
84 for(y=mpi->h-1;y>vf->priv->y2;y--){ | |
85 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
86 vf->priv->y2=y; | |
87 break; | |
88 } | |
89 } | |
90 | |
91 for(y=0;y<vf->priv->x1;y++){ | |
92 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
93 vf->priv->x1=y; | |
94 break; | |
95 } | |
96 } | |
97 | |
98 for(y=mpi->w-1;y>vf->priv->x2;y--){ | |
99 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
100 vf->priv->x2=y; | |
101 break; | |
102 } | |
103 } | |
104 | |
105 x=(vf->priv->x1+1)&(~1); | |
106 y=(vf->priv->y1+1)&(~1); | |
107 | |
108 printf("crop area: X: %d..%d Y: %d..%d (-vop crop=%d:%d:%d:%d)\n", | |
109 vf->priv->x1,vf->priv->x2, | |
110 vf->priv->y1,vf->priv->y2, | |
111 (vf->priv->x2-x)&(~1),(vf->priv->y2-y)&(~1),x,y | |
112 ); | |
113 | |
114 vf_next_put_image(vf,dmpi); | |
115 } | |
116 | |
117 //===========================================================================// | |
118 | |
119 static int open(vf_instance_t *vf, char* args){ | |
120 vf->config=config; | |
121 vf->put_image=put_image; | |
122 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
123 vf->priv->limit=24; // should be option | |
124 return 1; | |
125 } | |
126 | |
127 vf_info_t vf_info_cropdetect = { | |
128 "autodetect crop size", | |
129 "cropdetect", | |
130 "A'rpi", | |
131 "", | |
132 open | |
133 }; | |
134 | |
135 //===========================================================================// |