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