Mercurial > mplayer.hg
annotate libmpcodecs/vf_cropdetect.c @ 11681:4204af4b61a1
VAX architecture support (tested on VAXstation 4000/VLC)
author | gabucino |
---|---|
date | Thu, 25 Dec 2003 12:05:28 +0000 |
parents | 835822ce4bb1 |
children | 08bb01a9905a |
rev | line source |
---|---|
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 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; | |
6118 | 53 vf->priv->fno=0; |
6061 | 54 return vf_next_config(vf,width,height,d_width,d_height,flags,outfmt); |
55 } | |
56 | |
7368 | 57 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi){ |
6061 | 58 mp_image_t *dmpi; |
59 int bpp=mpi->bpp/8; | |
60 int x,y; | |
61 | |
62 // hope we'll get DR buffer: | |
63 dmpi=vf_get_image(vf->next,mpi->imgfmt, | |
64 MP_IMGTYPE_EXPORT, 0, | |
65 mpi->w, mpi->h); | |
66 | |
67 dmpi->planes[0]=mpi->planes[0]; | |
68 dmpi->planes[1]=mpi->planes[1]; | |
69 dmpi->planes[2]=mpi->planes[2]; | |
70 dmpi->stride[0]=mpi->stride[0]; | |
71 dmpi->stride[1]=mpi->stride[1]; | |
72 dmpi->stride[2]=mpi->stride[2]; | |
73 dmpi->width=mpi->width; | |
74 dmpi->height=mpi->height; | |
75 | |
6118 | 76 if(++vf->priv->fno>2){ // ignore first 2 frames - they may be empty |
6061 | 77 |
78 for(y=0;y<vf->priv->y1;y++){ | |
79 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
80 vf->priv->y1=y; | |
81 break; | |
82 } | |
83 } | |
84 | |
85 for(y=mpi->h-1;y>vf->priv->y2;y--){ | |
86 if(checkline(mpi->planes[0]+mpi->stride[0]*y,bpp,mpi->w,bpp)>vf->priv->limit){ | |
87 vf->priv->y2=y; | |
88 break; | |
89 } | |
90 } | |
91 | |
92 for(y=0;y<vf->priv->x1;y++){ | |
93 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
94 vf->priv->x1=y; | |
95 break; | |
96 } | |
97 } | |
98 | |
99 for(y=mpi->w-1;y>vf->priv->x2;y--){ | |
100 if(checkline(mpi->planes[0]+bpp*y,mpi->stride[0],mpi->h,bpp)>vf->priv->limit){ | |
101 vf->priv->x2=y; | |
102 break; | |
103 } | |
104 } | |
105 | |
106 x=(vf->priv->x1+1)&(~1); | |
107 y=(vf->priv->y1+1)&(~1); | |
108 | |
11261 | 109 printf("crop area: X: %d..%d Y: %d..%d (-vf crop=%d:%d:%d:%d)\n", |
6061 | 110 vf->priv->x1,vf->priv->x2, |
111 vf->priv->y1,vf->priv->y2, | |
6117 | 112 (vf->priv->x2+1-x)&(~1),(vf->priv->y2+1-y)&(~1),x,y |
6061 | 113 ); |
114 | |
6118 | 115 } |
116 | |
7368 | 117 return vf_next_put_image(vf,dmpi); |
6061 | 118 } |
119 | |
120 //===========================================================================// | |
121 | |
122 static int open(vf_instance_t *vf, char* args){ | |
123 vf->config=config; | |
124 vf->put_image=put_image; | |
125 vf->priv=malloc(sizeof(struct vf_priv_s)); | |
126 vf->priv->limit=24; // should be option | |
6610 | 127 if(args) vf->priv->limit=atoi(args); |
6061 | 128 return 1; |
129 } | |
130 | |
131 vf_info_t vf_info_cropdetect = { | |
132 "autodetect crop size", | |
133 "cropdetect", | |
134 "A'rpi", | |
135 "", | |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7472
diff
changeset
|
136 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
7472
diff
changeset
|
137 NULL |
6061 | 138 }; |
139 | |
140 //===========================================================================// |