Mercurial > mplayer.hg
annotate libmpcodecs/vf_rectangle.c @ 8610:097188da10d3
I got colas ready, new options, fixes and a few cosmetics I forgot to remove...
author | jonas |
---|---|
date | Sat, 28 Dec 2002 14:04:56 +0000 |
parents | 5b8df1d63b6d |
children | 8fd62b14cbc0 |
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" |
7738 | 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 |
7127 | 8 #include "../libvo/fastmemcpy.h" |
9 | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
10 struct vf_priv_s { |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
11 int x, y, w, h; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
12 }; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
13 |
6887 | 14 static int |
15 config(struct vf_instance_s* vf, | |
16 int width, int height, int d_width, int d_height, | |
17 unsigned int flags, unsigned int outfmt) | |
18 { | |
19 if (vf->priv->w < 0 || width < vf->priv->w) | |
20 vf->priv->w = width; | |
21 if (vf->priv->h < 0 || height < vf->priv->h) | |
22 vf->priv->h = height; | |
23 if (vf->priv->x < 0) | |
24 vf->priv->x = (width - vf->priv->w) / 2; | |
25 if (vf->priv->y < 0) | |
26 vf->priv->y = (height - vf->priv->h) / 2; | |
27 if (vf->priv->w + vf->priv->x > width | |
28 || vf->priv->h + vf->priv->y > height) { | |
7738 | 29 mp_msg(MSGT_VFILTER,MSGL_WARN,"rectangle: bad position/width/height - rectangle area is out of the original!\n"); |
6887 | 30 return 0; |
31 } | |
32 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
33 } | |
34 | |
35 static int | |
36 control(struct vf_instance_s* vf, int request, void *data) | |
37 { | |
38 const int *const tmp = data; | |
39 switch(request){ | |
40 case VFCTRL_CHANGE_RECTANGLE: | |
41 switch (tmp[0]){ | |
42 case 0: | |
43 vf->priv->w += tmp[1]; | |
44 return 1; | |
45 break; | |
46 case 1: | |
47 vf->priv->h += tmp[1]; | |
48 return 1; | |
49 break; | |
50 case 2: | |
51 vf->priv->x += tmp[1]; | |
52 return 1; | |
53 break; | |
54 case 3: | |
55 vf->priv->y += tmp[1]; | |
56 return 1; | |
57 break; | |
58 default: | |
7738 | 59 mp_msg(MSGT_VFILTER,MSGL_FATAL,"Unknown param %d \n", tmp[0]); |
6887 | 60 return 0; |
61 } | |
62 } | |
63 return vf_next_control(vf, request, data); | |
64 return 0; | |
65 } | |
7368 | 66 static int |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
67 put_image(struct vf_instance_s* vf, mp_image_t* mpi){ |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
68 mp_image_t* dmpi; |
6887 | 69 unsigned int bpp; |
70 unsigned int x, y, w, h; | |
71 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, | |
72 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
73 mpi->w, mpi->h); | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
74 bpp = dmpi->bpp / 8; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
75 memcpy(dmpi->planes[0], mpi->planes[0], dmpi->stride[0] * bpp * mpi->height); |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
76 memcpy(dmpi->planes[1], mpi->planes[1], dmpi->stride[1] * mpi->chroma_height); |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
77 memcpy(dmpi->planes[2], mpi->planes[2], dmpi->stride[2] * mpi->chroma_height); |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
78 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
79 /* Draw the rectangle */ |
6887 | 80 |
7739 | 81 mp_msg(MSGT_VFILTER,MSGL_INFO, "rectangle: -vop crop=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y); |
6887 | 82 |
83 if (vf->priv->x < 0) | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
84 x = 0; |
6887 | 85 else if (dmpi->width < vf->priv->x) |
86 x = dmpi->width; | |
87 else | |
88 x = vf->priv->x; | |
89 if (vf->priv->x + vf->priv->w - 1 < 0) | |
90 w = vf->priv->x + vf->priv->w - 1 - x; | |
91 else if (dmpi->width < vf->priv->x + vf->priv->w - 1) | |
92 w = dmpi->width - x; | |
93 else | |
94 w = vf->priv->x + vf->priv->w - 1 - x; | |
95 if (vf->priv->y < 0) | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
96 y = 0; |
6887 | 97 else if (dmpi->height < vf->priv->y) |
98 y = dmpi->height; | |
99 else | |
100 y = vf->priv->y; | |
101 if (vf->priv->y + vf->priv->h - 1 < 0) | |
102 h = vf->priv->y + vf->priv->h - 1 - y; | |
103 else if (dmpi->height < vf->priv->y + vf->priv->h - 1) | |
104 h = dmpi->height - y; | |
105 else | |
106 h = vf->priv->y + vf->priv->h - 1 - y; | |
107 | |
108 if (0 <= vf->priv->y && vf->priv->y <= dmpi->height) { | |
109 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; | |
110 unsigned int count = w * bpp; | |
111 while (count--) | |
112 p[count] = 0xff - p[count]; | |
113 } | |
114 if (h != 1 && vf->priv->y + vf->priv->h - 1 <= mpi->height) { | |
115 unsigned char *p = dmpi->planes[0] + (vf->priv->y + vf->priv->h - 1) * dmpi->stride[0] + x * bpp; | |
116 unsigned int count = w * bpp; | |
117 while (count--) | |
118 p[count] = 0xff - p[count]; | |
119 } | |
120 if (0 <= vf->priv->x && vf->priv->x <= dmpi->width) { | |
121 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + x * bpp; | |
122 unsigned int count = h; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
123 while (count--) { |
6887 | 124 unsigned int i = bpp; |
125 while (i--) | |
126 p[i] = 0xff - p[i]; | |
127 p += dmpi->stride[0]; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
128 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
129 } |
6887 | 130 if (w != 1 && vf->priv->x + vf->priv->w - 1 <= mpi->width) { |
131 unsigned char *p = dmpi->planes[0] + y * dmpi->stride[0] + (vf->priv->x + vf->priv->w - 1) * bpp; | |
132 unsigned int count = h; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
133 while (count--) { |
6887 | 134 unsigned int i = bpp; |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
135 while (i--) |
6887 | 136 p[i] = 0xff - p[i]; |
137 p += dmpi->stride[0]; | |
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 } |
7368 | 140 return vf_next_put_image(vf, dmpi); |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
141 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
142 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
143 static int |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
144 open(vf_instance_t* vf, char* args) { |
6887 | 145 vf->config = config; |
146 vf->control = control; | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
147 vf->put_image = put_image; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
148 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
|
149 vf->priv->x = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
150 vf->priv->y = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
151 vf->priv->w = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
152 vf->priv->h = -1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
153 if (args) |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
154 sscanf(args, "%d:%d:%d:%d", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
155 &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
|
156 return 1; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
157 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
158 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
159 vf_info_t vf_info_rectangle = { |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
160 "draw rectangle", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
161 "rectangle", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
162 "Kim Minh Kaplan", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
163 "", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
164 open |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
165 }; |