Mercurial > mplayer.hg
annotate libmpcodecs/vf_rectangle.c @ 21555:ababf115f90d
Avoid deprecated _sleep, instead include windows.h and use Sleep just like
osdep/timer-win2.c does.
Patch by Zuxy Meng [zuxy meng (at) gmail com]
author | reimar |
---|---|
date | Sun, 10 Dec 2006 14:04:27 +0000 |
parents | 4a5045cd7c0c |
children | 00fff9a3b735 |
rev | line source |
---|---|
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
1 #include <stdio.h> |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
2 #include <stdlib.h> |
6887 | 3 #include <string.h> |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
4 #include "mp_image.h" |
17012 | 5 #include "mp_msg.h" |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
6 #include "vf.h" |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
7 |
17012 | 8 #include "libvo/fastmemcpy.h" |
21401
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
9 #include "libavutil/common.h" |
7127 | 10 |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
11 struct vf_priv_s { |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
12 int x, y, w, h; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
13 }; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
14 |
6887 | 15 static int |
16 config(struct vf_instance_s* vf, | |
17 int width, int height, int d_width, int d_height, | |
18 unsigned int flags, unsigned int outfmt) | |
19 { | |
20 if (vf->priv->w < 0 || width < vf->priv->w) | |
21 vf->priv->w = width; | |
22 if (vf->priv->h < 0 || height < vf->priv->h) | |
23 vf->priv->h = height; | |
24 if (vf->priv->x < 0) | |
25 vf->priv->x = (width - vf->priv->w) / 2; | |
26 if (vf->priv->y < 0) | |
27 vf->priv->y = (height - vf->priv->h) / 2; | |
28 if (vf->priv->w + vf->priv->x > width | |
29 || vf->priv->h + vf->priv->y > height) { | |
7738 | 30 mp_msg(MSGT_VFILTER,MSGL_WARN,"rectangle: bad position/width/height - rectangle area is out of the original!\n"); |
6887 | 31 return 0; |
32 } | |
33 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
34 } | |
35 | |
36 static int | |
37 control(struct vf_instance_s* vf, int request, void *data) | |
38 { | |
39 const int *const tmp = data; | |
40 switch(request){ | |
41 case VFCTRL_CHANGE_RECTANGLE: | |
42 switch (tmp[0]){ | |
43 case 0: | |
44 vf->priv->w += tmp[1]; | |
45 return 1; | |
46 break; | |
47 case 1: | |
48 vf->priv->h += tmp[1]; | |
49 return 1; | |
50 break; | |
51 case 2: | |
52 vf->priv->x += tmp[1]; | |
53 return 1; | |
54 break; | |
55 case 3: | |
56 vf->priv->y += tmp[1]; | |
57 return 1; | |
58 break; | |
59 default: | |
7738 | 60 mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]); |
6887 | 61 return 0; |
62 } | |
63 } | |
64 return vf_next_control(vf, request, data); | |
65 return 0; | |
66 } | |
7368 | 67 static int |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
68 put_image(struct vf_instance_s* vf, mp_image_t* mpi, double pts){ |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
69 mp_image_t* dmpi; |
8737 | 70 unsigned int bpp = mpi->bpp / 8; |
21401
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
71 int x, y, w, h; |
6887 | 72 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, |
73 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
74 mpi->w, mpi->h); | |
8737 | 75 |
76 memcpy_pic(dmpi->planes[0],mpi->planes[0],mpi->w*bpp, mpi->h, | |
77 dmpi->stride[0],mpi->stride[0]); | |
78 if(mpi->flags&MP_IMGFLAG_PLANAR && mpi->flags&MP_IMGFLAG_YUV){ | |
79 memcpy_pic(dmpi->planes[1],mpi->planes[1], | |
80 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, | |
81 dmpi->stride[1],mpi->stride[1]); | |
82 memcpy_pic(dmpi->planes[2],mpi->planes[2], | |
83 mpi->w>>mpi->chroma_x_shift, mpi->h>>mpi->chroma_y_shift, | |
84 dmpi->stride[2],mpi->stride[2]); | |
85 } | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
86 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
87 /* Draw the rectangle */ |
6887 | 88 |
11261 | 89 mp_msg(MSGT_VFILTER,MSGL_INFO, "rectangle: -vf rectangle=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y); |
6887 | 90 |
21401
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
91 x = FFMIN(vf->priv->x, dmpi->width); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
92 x = FFMAX(x, 0); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
93 |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
94 w = vf->priv->x + vf->priv->w - 1 - x; |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
95 w = FFMIN(w, dmpi->width - x); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
96 w = FFMAX(w, 0); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
97 |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
98 y = FFMIN(vf->priv->y, dmpi->height); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
99 y = FFMAX(y, 0); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
100 |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
101 h = vf->priv->y + vf->priv->h - 1 - y; |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
102 h = FFMIN(h, dmpi->height - y); |
4a5045cd7c0c
Cleanup and fix rectangle size calculation, caused crashes with e.g.
reimar
parents:
17906
diff
changeset
|
103 h = FFMAX(h, 0); |
6887 | 104 |
105 if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) { | |
106 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; | |
107 unsigned int count = w * bpp; | |
108 while (count--) | |
109 p[count] = 0xff - p[count]; | |
110 } | |
111 if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) { | |
112 unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp; | |
113 unsigned int count = w * bpp; | |
114 while (count--) | |
115 p[count] = 0xff - p[count]; | |
116 } | |
117 if (0 <= vf->priv->x && vf->priv->x <= dmpi->width) { | |
118 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; | |
119 unsigned int count = h; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
120 while (count--) { |
6887 | 121 unsigned int i = bpp; |
122 while (i--) | |
123 p[i] = 0xff - p[i]; | |
124 p += dmpi->stride[0]; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
125 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
126 } |
6887 | 127 if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) { |
128 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp; | |
129 unsigned int count = h; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
130 while (count--) { |
6887 | 131 unsigned int i = bpp; |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
132 while (i--) |
6887 | 133 p[i] = 0xff - p[i]; |
134 p += dmpi->stride[0]; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
135 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
136 } |
17906
20aca9baf5d8
passing pts through the filter layer (lets see if pts or cola comes out at the end)
michael
parents:
17012
diff
changeset
|
137 return vf_next_put_image(vf, dmpi, pts); |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
138 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
139 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
140 static int |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
141 open(vf_instance_t* vf, char* args) { |
6887 | 142 vf->config = config; |
143 vf->control = control; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
144 vf->put_image = put_image; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
145 vf->priv = malloc(sizeof(struct vf_priv_s)); |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
146 vf->priv->x = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
147 vf->priv->y = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
148 vf->priv->w = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
149 vf->priv->h = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
150 if (args) |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
151 sscanf(args, "%d:%d:%d:%d", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
152 &vf->priv->w, &vf->priv->h, &vf->priv->x, &vf->priv->y); |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
153 return 1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
154 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
155 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
156 vf_info_t vf_info_rectangle = { |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
157 "draw rectangle", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
158 "rectangle", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
159 "Kim Minh Kaplan", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
160 "", |
9593
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
8737
diff
changeset
|
161 open, |
e9a2af584986
Add the new -vf option wich is the same as vop in reverse order.
albeu
parents:
8737
diff
changeset
|
162 NULL |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
163 }; |