File: morph_slide.c

package info (click to toggle)
libvisual-plugins 1%3A0.4.0%2Bdfsg1-16
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,656 kB
  • sloc: ansic: 9,358; sh: 8,809; cpp: 871; makefile: 222; sed: 16
file content (255 lines) | stat: -rw-r--r-- 6,990 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
/* Libvisual-plugins - Standard plugins for libvisual
 * 
 * Copyright (C) 2004, 2005, 2006 Dennis Smit <ds@nerds-incorporated.org>
 *
 * Authors: Dennis Smit <ds@nerds-incorporated.org>
 *
 * $Id: morph_slide.c,v 1.16 2006/01/27 20:19:18 synap Exp $
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 */

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#include <libvisual/libvisual.h>

typedef enum {
	SLIDE_LEFT,
	SLIDE_RIGHT,
	SLIDE_BOTTOM,
	SLIDE_UPPER
} SlideType;

typedef struct {
	SlideType	slide_type;
} SlidePrivate;

int lv_morph_slide_init_left (VisPluginData *plugin);
int lv_morph_slide_init_right (VisPluginData *plugin);
int lv_morph_slide_init_bottom (VisPluginData *plugin);
int lv_morph_slide_init_upper (VisPluginData *plugin);
int lv_morph_slide_cleanup (VisPluginData *plugin);
int lv_morph_slide_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2);

VISUAL_PLUGIN_API_VERSION_VALIDATOR

const VisPluginInfo *get_plugin_info (int *count)
{
	static VisMorphPlugin morph[] = {{
		.apply = lv_morph_slide_apply,
		.vidoptions.depth =
			VISUAL_VIDEO_DEPTH_8BIT |
			VISUAL_VIDEO_DEPTH_16BIT |
			VISUAL_VIDEO_DEPTH_24BIT |
			VISUAL_VIDEO_DEPTH_32BIT
	}};

	static VisPluginInfo info[] = {{
		.type = VISUAL_PLUGIN_TYPE_MORPH,

		.plugname = "slide_left",
		.name = "Slide left morph",
		.author = "Dennis Smit <ds@nerds-incorporated.org>",
		.version = "0.1",
		.about = "A slide in/out morph plugin",
		.help = "This morph plugin morphs between two video sources by sliding one in and the other out",
		.license = VISUAL_PLUGIN_LICENSE_LGPL,

		.init = lv_morph_slide_init_left,
		.cleanup = lv_morph_slide_cleanup,

		.plugin = VISUAL_OBJECT (&morph[0])
	},
	{
		.type = VISUAL_PLUGIN_TYPE_MORPH,

		.plugname = "slide_right",
		.name = "Slide right morph",
		.author = "Dennis Smit <ds@nerds-incorporated.org>",
		.version = "0.1",
		.about = "A slide in/out morph plugin",
		.help = "This morph plugin morphs between two video sources by sliding one in and the other out",
		.license = VISUAL_PLUGIN_LICENSE_LGPL,

		.init = lv_morph_slide_init_right,
		.cleanup = lv_morph_slide_cleanup,

		.plugin = VISUAL_OBJECT (&morph[0])
	},
	{
		.type = VISUAL_PLUGIN_TYPE_MORPH,

		.plugname = "slide_bottom",
		.name = "Slide bottom morph",
		.author = "Dennis Smit <ds@nerds-incorporated.org>",
		.version = "0.1",
		.about = "A slide in/out morph plugin",
		.help = "This morph plugin morphs between two video sources by sliding one in and the other out",
		.license = VISUAL_PLUGIN_LICENSE_LGPL,

		.init = lv_morph_slide_init_bottom,
		.cleanup = lv_morph_slide_cleanup,

		.plugin = VISUAL_OBJECT (&morph[0])
	},
	{
		.type = VISUAL_PLUGIN_TYPE_MORPH,

		.plugname = "slide_upper",
		.name = "Slide upper morph",
		.author = "Dennis Smit <ds@nerds-incorporated.org>",
		.version = "0.1",
		.about = "A slide in/out morph plugin",
		.help = "This morph plugin morphs between two video sources by sliding one in and the other out",
		.license = VISUAL_PLUGIN_LICENSE_LGPL,

		.init = lv_morph_slide_init_upper,
		.cleanup = lv_morph_slide_cleanup,

		.plugin = VISUAL_OBJECT (&morph[0])
	}};

	*count = sizeof (info) / sizeof (*info);

	return info;
}

int lv_morph_slide_init_left (VisPluginData *plugin)
{
	SlidePrivate *priv;

	priv = visual_mem_new0 (SlidePrivate, 1);
	visual_object_set_private (VISUAL_OBJECT (plugin), priv);

	priv->slide_type = SLIDE_LEFT;

	return 0;
}

int lv_morph_slide_init_right (VisPluginData *plugin)
{
	SlidePrivate *priv;

	priv = visual_mem_new0 (SlidePrivate, 1);
	visual_object_set_private (VISUAL_OBJECT (plugin), priv);

	priv->slide_type = SLIDE_RIGHT;

	return 0;
}

int lv_morph_slide_init_bottom (VisPluginData *plugin)
{
	SlidePrivate *priv;

	priv = visual_mem_new0 (SlidePrivate, 1);
	visual_object_set_private (VISUAL_OBJECT (plugin), priv);

	priv->slide_type = SLIDE_BOTTOM;

	return 0;
}

int lv_morph_slide_init_upper (VisPluginData *plugin)
{
	SlidePrivate *priv;

	priv = visual_mem_new0 (SlidePrivate, 1);
	visual_object_set_private (VISUAL_OBJECT (plugin), priv);

	priv->slide_type = SLIDE_UPPER;

	return 0;
}

int lv_morph_slide_cleanup (VisPluginData *plugin)
{
	SlidePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));

	visual_mem_free (priv);

	return 0;
}

int lv_morph_slide_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2)
{
	SlidePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin));
	uint8_t *destbuf = visual_video_get_pixels (dest);
	uint8_t *srcbuf1 = visual_video_get_pixels (src1);
	uint8_t *srcbuf2 = visual_video_get_pixels (src2);
	int i;
	int diff1;
	int diff2;
	int hadd;

	visual_mem_set (destbuf, 0, visual_video_get_size (dest));

	if (priv->slide_type == SLIDE_RIGHT || priv->slide_type == SLIDE_UPPER)
		rate = 1.0 - rate;

	diff1 = dest->pitch * rate;
	diff1 -= diff1 % dest->bpp;

	if (diff1 > dest->pitch)
		diff1 = dest->pitch;

	diff2 = dest->pitch - diff1;

	hadd = dest->height * rate;

	switch (priv->slide_type) {
		case SLIDE_LEFT:
			for (i = 0; i < dest->height; i++) {
				visual_mem_copy (destbuf + (i * dest->pitch), srcbuf2 + (i * dest->pitch) + diff2, diff1);
				visual_mem_copy (destbuf + (i * dest->pitch) + (diff1), srcbuf1 + (i * dest->pitch), diff2);
			}

			break;

		case SLIDE_RIGHT:
			for (i = 0; i < dest->height; i++) {
				visual_mem_copy (destbuf + (i * dest->pitch), srcbuf1 + (i * dest->pitch) + diff2, diff1);
				visual_mem_copy (destbuf + (i * dest->pitch) + (diff1), srcbuf2 + (i * dest->pitch), diff2);
			}

			break;

		case SLIDE_BOTTOM:
			visual_mem_copy (destbuf, srcbuf1 + (hadd * dest->pitch), (dest->height - hadd) * dest->pitch);
			visual_mem_copy (destbuf + ((dest->height - hadd) * dest->pitch), srcbuf2, hadd * dest->pitch);

			break;

		case SLIDE_UPPER:
			visual_mem_copy (destbuf, srcbuf2 + (hadd * dest->pitch), (dest->height - hadd) * dest->pitch);
			visual_mem_copy (destbuf + ((dest->height - hadd) * dest->pitch), srcbuf1, hadd * dest->pitch);

			break;

		default:
			visual_log (VISUAL_LOG_WARNING,
					"Slide plugin is initialized with an impossible slide direction, this should never happen");

			break;
	}

	return 0;
}