Mercurial > mplayer.hg
annotate libmpcodecs/vf_rectangle.c @ 6965:f8ea0af8edb0
optimization
author | michael |
---|---|
date | Sun, 11 Aug 2002 10:12:15 +0000 |
parents | 66427e850216 |
children | 1e47c2e7aa8e |
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 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
7 struct vf_priv_s { |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
8 int x, y, w, h; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
9 }; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
10 |
6887 | 11 static int |
12 config(struct vf_instance_s* vf, | |
13 int width, int height, int d_width, int d_height, | |
14 unsigned int flags, unsigned int outfmt) | |
15 { | |
16 if (vf->priv->w < 0 || width < vf->priv->w) | |
17 vf->priv->w = width; | |
18 if (vf->priv->h < 0 || height < vf->priv->h) | |
19 vf->priv->h = height; | |
20 if (vf->priv->x < 0) | |
21 vf->priv->x = (width - vf->priv->w) / 2; | |
22 if (vf->priv->y < 0) | |
23 vf->priv->y = (height - vf->priv->h) / 2; | |
24 if (vf->priv->w + vf->priv->x > width | |
25 || vf->priv->h + vf->priv->y > height) { | |
26 fprintf(stderr, "rectangle: bad position/width/height - rectangle area is out of the original!\n"); | |
27 return 0; | |
28 } | |
29 return vf_next_config(vf, width, height, d_width, d_height, flags, outfmt); | |
30 } | |
31 | |
32 static int | |
33 control(struct vf_instance_s* vf, int request, void *data) | |
34 { | |
35 const int *const tmp = data; | |
36 switch(request){ | |
37 case VFCTRL_CHANGE_RECTANGLE: | |
38 switch (tmp[0]){ | |
39 case 0: | |
40 vf->priv->w += tmp[1]; | |
41 return 1; | |
42 break; | |
43 case 1: | |
44 vf->priv->h += tmp[1]; | |
45 return 1; | |
46 break; | |
47 case 2: | |
48 vf->priv->x += tmp[1]; | |
49 return 1; | |
50 break; | |
51 case 3: | |
52 vf->priv->y += tmp[1]; | |
53 return 1; | |
54 break; | |
55 default: | |
56 fprintf(stderr, "Unknown param %d \n", tmp[0]); | |
57 return 0; | |
58 } | |
59 } | |
60 return vf_next_control(vf, request, data); | |
61 return 0; | |
62 } | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
63 static void |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
64 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
|
65 mp_image_t* dmpi; |
6887 | 66 unsigned int bpp; |
67 unsigned int x, y, w, h; | |
68 dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, | |
69 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_PREFER_ALIGNED_STRIDE, | |
70 mpi->w, mpi->h); | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
71 bpp = dmpi->bpp / 8; |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
72 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
|
73 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
|
74 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
|
75 |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
76 /* Draw the rectangle */ |
6887 | 77 |
78 fprintf(stderr, "rectangle: -vop crop=%d:%d:%d:%d \n", vf->priv->w, vf->priv->h, vf->priv->x, vf->priv->y); | |
79 | |
80 if (vf->priv->x < 0) | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
81 x = 0; |
6887 | 82 else if (dmpi->width < vf->priv->x) |
83 x = dmpi->width; | |
84 else | |
85 x = vf->priv->x; | |
86 if (vf->priv->x + vf->priv->w - 1 < 0) | |
87 w = vf->priv->x + vf->priv->w - 1 - x; | |
88 else if (dmpi->width < vf->priv->x + vf->priv->w - 1) | |
89 w = dmpi->width - x; | |
90 else | |
91 w = vf->priv->x + vf->priv->w - 1 - x; | |
92 if (vf->priv->y < 0) | |
6820
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
93 y = 0; |
6887 | 94 else if (dmpi->height < vf->priv->y) |
95 y = dmpi->height; | |
96 else | |
97 y = vf->priv->y; | |
98 if (vf->priv->y + vf->priv->h - 1 < 0) | |
99 h = vf->priv->y + vf->priv->h - 1 - y; | |
100 else if (dmpi->height < vf->priv->y + vf->priv->h - 1) | |
101 h = dmpi->height - y; | |
102 else | |
103 h = vf->priv->y + vf->priv->h - 1 - y; | |
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 } |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
137 vf_next_put_image(vf, dmpi); |
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 "", |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
161 open |
a99c7700e4f1
New plugin to test crop parameters. Arguments are the same as for the
kmkaplan
parents:
diff
changeset
|
162 }; |