Debian Codegraph @

plugins/morph/tentacle/morph_tentacle.c

raw
1 /* Libvisual-plugins - Standard plugins for libvisual
2 *
3 * Copyright (C) 2004, 2005, 2006 Dennis Smit <[email protected]>
4 *
5 * Authors: Dennis Smit <[email protected]>
6 *
7 * $Id: morph_tentacle.c,v 1.18 2006/01/27 20:19:18 synap Exp $
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2
12 * of the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <math.h>
27 #include <unistd.h>
28 #include <fcntl.h>
29 #include <string.h>
30
31 #include <libvisual/libvisual.h>
32
33 typedef struct {
34 uint16_t b:5, g:6, r:5;
35 } _color16;
36
37 typedef struct {
38 float move;
39 } TentaclePrivate;
40
41 static void sane_coords (VisVideo *dest, int *x, int *y1, int *y2);
42
43 static void vline_from_video_8 (VisVideo *dest, VisVideo *src, int x, int y1, int y2);
44 static void vline_from_video_16 (VisVideo *dest, VisVideo *src, int x, int y1, int y2);
45 static void vline_from_video_24 (VisVideo *dest, VisVideo *src, int x, int y1, int y2);
46 static void vline_from_video_32 (VisVideo *dest, VisVideo *src, int x, int y1, int y2);
47
48 int lv_morph_tentacle_init (VisPluginData *plugin);
49 int lv_morph_tentacle_cleanup (VisPluginData *plugin);
50 int lv_morph_tentacle_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2);
51
52 VISUAL_PLUGIN_API_VERSION_VALIDATOR
53
54 const VisPluginInfo *get_plugin_info (int *count)
55 {
56 static VisMorphPlugin morph[] = {{
57 .apply = lv_morph_tentacle_apply,
58 .vidoptions.depth =
59 VISUAL_VIDEO_DEPTH_8BIT |
60 VISUAL_VIDEO_DEPTH_16BIT |
61 VISUAL_VIDEO_DEPTH_24BIT |
62 VISUAL_VIDEO_DEPTH_32BIT
63 }};
64
65 static VisPluginInfo info[] = {{
66 .type = VISUAL_PLUGIN_TYPE_MORPH,
67
68 .plugname = "tentacle",
69 .name = "tentacle morph",
70 .author = "Dennis Smit <[email protected]>",
71 .version = "0.1",
72 .about = "An sine wave morph plugin",
73 .help = "This morph plugin morphs between two video sources using some sort of wave that grows in size",
74 .license = VISUAL_PLUGIN_LICENSE_LGPL,
75
76 .init = lv_morph_tentacle_init,
77 .cleanup = lv_morph_tentacle_cleanup,
78
79 .plugin = VISUAL_OBJECT (&morph[0])
80 }};
81
82 *count = sizeof (info) / sizeof (*info);
83
84 return info;
85 }
86
87 int lv_morph_tentacle_init (VisPluginData *plugin)
88 {
89 TentaclePrivate *priv;
90
91 priv = visual_mem_new0 (TentaclePrivate, 1);
92 visual_object_set_private (VISUAL_OBJECT (plugin), priv);
93
94 return 0;
95 }
96
97 int lv_morph_tentacle_cleanup (VisPluginData *plugin)
98 {
99 TentaclePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
100
101 visual_mem_free (priv);
102
103 return 0;
104 }
105
106 int lv_morph_tentacle_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2)
107 {
108 TentaclePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
109 uint8_t *destbuf = visual_video_get_pixels (dest);
110 uint8_t *src1buf = visual_video_get_pixels (src1);
111
112 int height1;
113 int height2;
114 int add1;
115 int add2;
116
117 float sinrate = priv->move;
118 float multiplier = 0;
119 float multiadd = 1.000 / dest->width;
120
121 int i;
122
123 visual_mem_copy (destbuf, src1buf, visual_video_get_size (src1));
124
125 for (i = 0; i < dest->width; i++) {
126 add1 = (dest->height / 2) - ((dest->height / 2) * (rate * 1.5));
127 add2 = (dest->height / 2) + ((dest->height / 2) * (rate * 1.5));
128
129 height1 = (sin (sinrate) * ((dest->height / 4) * multiplier)) + add1;
130 height2 = (sin (sinrate) * ((dest->height / 4) * multiplier)) + add2;
131 multiplier += multiadd;
132
133 switch (dest->depth) {
134 case VISUAL_VIDEO_DEPTH_8BIT:
135 vline_from_video_8 (dest, src2, i, height1, height2);
136 break;
137
138 case VISUAL_VIDEO_DEPTH_16BIT:
139 vline_from_video_16 (dest, src2, i, height1, height2);
140 break;
141
142 case VISUAL_VIDEO_DEPTH_24BIT:
143 vline_from_video_24 (dest, src2, i, height1, height2);
144 break;
145
146 case VISUAL_VIDEO_DEPTH_32BIT:
147 vline_from_video_32 (dest, src2, i, height1, height2);
148 break;
149
150 default:
151 break;
152 }
153
154 sinrate += 0.02;
155 priv->move += 0.0002;
156 }
157
158 return 0;
159 }
160
161 static void sane_coords (VisVideo *dest, int *x, int *y1, int *y2)
162 {
163 if (*x > dest->width)
164 *x = dest->width;
165 else if (*x < 0)
166 *x = 0;
167
168 if (*y1 > dest->height)
169 *y1 = dest->height;
170 else if (*y1 < 0)
171 *y1 = 0;
172
173 if (*y2 > dest->height)
174 *y2 = dest->height;
175 else if (*y2 < 0)
176 *y2 = 0;
177 }
178
179 static void vline_from_video_8 (VisVideo *dest, VisVideo *src, int x, int y1, int y2)
180 {
181 uint8_t *destbuf = visual_video_get_pixels (dest);
182 uint8_t *srcbuf = visual_video_get_pixels (src);
183 int i;
184
185 sane_coords (dest, &x, &y1, &y2);
186
187 for (i = y1; i < y2; i++)
188 destbuf[(i * dest->pitch) + x] = srcbuf[(i * src->pitch) + x];
189 }
190
191 static void vline_from_video_16 (VisVideo *dest, VisVideo *src, int x, int y1, int y2)
192 {
193 uint16_t *destbuf = visual_video_get_pixels (dest);
194 uint16_t *srcbuf = visual_video_get_pixels (src);
195 int i;
196
197 sane_coords (dest, &x, &y1, &y2);
198
199 for (i = y1; i < y2; i++)
200 destbuf[(i * (dest->pitch / dest->bpp)) + x] = srcbuf[(i * (src->pitch / src->bpp)) + x];
201 }
202
203 static void vline_from_video_24 (VisVideo *dest, VisVideo *src, int x, int y1, int y2)
204 {
205 uint8_t *destbuf = visual_video_get_pixels (dest);
206 uint8_t *srcbuf = visual_video_get_pixels (src);
207 int i;
208
209 sane_coords (dest, &x, &y1, &y2);
210
211 x *= 3;
212
213 for (i = y1; i < y2; i++) {
214 destbuf[(i * dest->pitch) + x] = srcbuf[(i * src->pitch) + x];
215 destbuf[(i * dest->pitch) + x + 1] = srcbuf[(i * src->pitch) + x + 1];
216 destbuf[(i * dest->pitch) + x + 2] = srcbuf[(i * src->pitch) + x + 2];
217 }
218 }
219
220 static void vline_from_video_32 (VisVideo *dest, VisVideo *src, int x, int y1, int y2)
221 {
222 uint32_t *destbuf = visual_video_get_pixels (dest);
223 uint32_t *srcbuf = visual_video_get_pixels (src);
224 int i;
225
226 sane_coords (dest, &x, &y1, &y2);
227
228 for (i = y1; i < y2; i++) {
229 destbuf[(i * (dest->pitch / dest->bpp)) + x] = srcbuf[(i * (src->pitch / src->bpp)) + x];
230 }
231 }