| 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_slide.c,v 1.16 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 Lesser General Public License as |
| 11 |
* published by the Free Software Foundation; either version 2.1 |
| 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 Lesser 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 enum { |
| 34 |
SLIDE_LEFT, |
| 35 |
SLIDE_RIGHT, |
| 36 |
SLIDE_BOTTOM, |
| 37 |
SLIDE_UPPER |
| 38 |
} SlideType; |
| 39 |
|
| 40 |
typedef struct { |
| 41 |
SlideType slide_type; |
| 42 |
} SlidePrivate; |
| 43 |
|
| 44 |
int lv_morph_slide_init_left (VisPluginData *plugin); |
| 45 |
int lv_morph_slide_init_right (VisPluginData *plugin); |
| 46 |
int lv_morph_slide_init_bottom (VisPluginData *plugin); |
| 47 |
int lv_morph_slide_init_upper (VisPluginData *plugin); |
| 48 |
int lv_morph_slide_cleanup (VisPluginData *plugin); |
| 49 |
int lv_morph_slide_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2); |
| 50 |
|
| 51 |
VISUAL_PLUGIN_API_VERSION_VALIDATOR |
| 52 |
|
| 53 |
const VisPluginInfo *get_plugin_info (int *count) |
| 54 |
{ |
| 55 |
static VisMorphPlugin morph[] = {{ |
| 56 |
.apply = lv_morph_slide_apply, |
| 57 |
.vidoptions.depth = |
| 58 |
VISUAL_VIDEO_DEPTH_8BIT | |
| 59 |
VISUAL_VIDEO_DEPTH_16BIT | |
| 60 |
VISUAL_VIDEO_DEPTH_24BIT | |
| 61 |
VISUAL_VIDEO_DEPTH_32BIT |
| 62 |
}}; |
| 63 |
|
| 64 |
static VisPluginInfo info[] = {{ |
| 65 |
.type = VISUAL_PLUGIN_TYPE_MORPH, |
| 66 |
|
| 67 |
.plugname = "slide_left", |
| 68 |
.name = "Slide left morph", |
| 69 |
.author = "Dennis Smit <[email protected]>", |
| 70 |
.version = "0.1", |
| 71 |
.about = "A slide in/out morph plugin", |
| 72 |
.help = "This morph plugin morphs between two video sources by sliding one in and the other out", |
| 73 |
.license = VISUAL_PLUGIN_LICENSE_LGPL, |
| 74 |
|
| 75 |
.init = lv_morph_slide_init_left, |
| 76 |
.cleanup = lv_morph_slide_cleanup, |
| 77 |
|
| 78 |
.plugin = VISUAL_OBJECT (&morph[0]) |
| 79 |
}, |
| 80 |
{ |
| 81 |
.type = VISUAL_PLUGIN_TYPE_MORPH, |
| 82 |
|
| 83 |
.plugname = "slide_right", |
| 84 |
.name = "Slide right morph", |
| 85 |
.author = "Dennis Smit <[email protected]>", |
| 86 |
.version = "0.1", |
| 87 |
.about = "A slide in/out morph plugin", |
| 88 |
.help = "This morph plugin morphs between two video sources by sliding one in and the other out", |
| 89 |
.license = VISUAL_PLUGIN_LICENSE_LGPL, |
| 90 |
|
| 91 |
.init = lv_morph_slide_init_right, |
| 92 |
.cleanup = lv_morph_slide_cleanup, |
| 93 |
|
| 94 |
.plugin = VISUAL_OBJECT (&morph[0]) |
| 95 |
}, |
| 96 |
{ |
| 97 |
.type = VISUAL_PLUGIN_TYPE_MORPH, |
| 98 |
|
| 99 |
.plugname = "slide_bottom", |
| 100 |
.name = "Slide bottom morph", |
| 101 |
.author = "Dennis Smit <[email protected]>", |
| 102 |
.version = "0.1", |
| 103 |
.about = "A slide in/out morph plugin", |
| 104 |
.help = "This morph plugin morphs between two video sources by sliding one in and the other out", |
| 105 |
.license = VISUAL_PLUGIN_LICENSE_LGPL, |
| 106 |
|
| 107 |
.init = lv_morph_slide_init_bottom, |
| 108 |
.cleanup = lv_morph_slide_cleanup, |
| 109 |
|
| 110 |
.plugin = VISUAL_OBJECT (&morph[0]) |
| 111 |
}, |
| 112 |
{ |
| 113 |
.type = VISUAL_PLUGIN_TYPE_MORPH, |
| 114 |
|
| 115 |
.plugname = "slide_upper", |
| 116 |
.name = "Slide upper morph", |
| 117 |
.author = "Dennis Smit <[email protected]>", |
| 118 |
.version = "0.1", |
| 119 |
.about = "A slide in/out morph plugin", |
| 120 |
.help = "This morph plugin morphs between two video sources by sliding one in and the other out", |
| 121 |
.license = VISUAL_PLUGIN_LICENSE_LGPL, |
| 122 |
|
| 123 |
.init = lv_morph_slide_init_upper, |
| 124 |
.cleanup = lv_morph_slide_cleanup, |
| 125 |
|
| 126 |
.plugin = VISUAL_OBJECT (&morph[0]) |
| 127 |
}}; |
| 128 |
|
| 129 |
*count = sizeof (info) / sizeof (*info); |
| 130 |
|
| 131 |
return info; |
| 132 |
} |
| 133 |
|
| 134 |
int lv_morph_slide_init_left (VisPluginData *plugin) |
| 135 |
{ |
| 136 |
SlidePrivate *priv; |
| 137 |
|
| 138 |
priv = visual_mem_new0 (SlidePrivate, 1); |
| 139 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 140 |
|
| 141 |
priv->slide_type = SLIDE_LEFT; |
| 142 |
|
| 143 |
return 0; |
| 144 |
} |
| 145 |
|
| 146 |
int lv_morph_slide_init_right (VisPluginData *plugin) |
| 147 |
{ |
| 148 |
SlidePrivate *priv; |
| 149 |
|
| 150 |
priv = visual_mem_new0 (SlidePrivate, 1); |
| 151 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 152 |
|
| 153 |
priv->slide_type = SLIDE_RIGHT; |
| 154 |
|
| 155 |
return 0; |
| 156 |
} |
| 157 |
|
| 158 |
int lv_morph_slide_init_bottom (VisPluginData *plugin) |
| 159 |
{ |
| 160 |
SlidePrivate *priv; |
| 161 |
|
| 162 |
priv = visual_mem_new0 (SlidePrivate, 1); |
| 163 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 164 |
|
| 165 |
priv->slide_type = SLIDE_BOTTOM; |
| 166 |
|
| 167 |
return 0; |
| 168 |
} |
| 169 |
|
| 170 |
int lv_morph_slide_init_upper (VisPluginData *plugin) |
| 171 |
{ |
| 172 |
SlidePrivate *priv; |
| 173 |
|
| 174 |
priv = visual_mem_new0 (SlidePrivate, 1); |
| 175 |
visual_object_set_private (VISUAL_OBJECT (plugin), priv); |
| 176 |
|
| 177 |
priv->slide_type = SLIDE_UPPER; |
| 178 |
|
| 179 |
return 0; |
| 180 |
} |
| 181 |
|
| 182 |
int lv_morph_slide_cleanup (VisPluginData *plugin) |
| 183 |
{ |
| 184 |
SlidePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 185 |
|
| 186 |
visual_mem_free (priv); |
| 187 |
|
| 188 |
return 0; |
| 189 |
} |
| 190 |
|
| 191 |
int lv_morph_slide_apply (VisPluginData *plugin, float rate, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2) |
| 192 |
{ |
| 193 |
SlidePrivate *priv = visual_object_get_private (VISUAL_OBJECT (plugin)); |
| 194 |
uint8_t *destbuf = visual_video_get_pixels (dest); |
| 195 |
uint8_t *srcbuf1 = visual_video_get_pixels (src1); |
| 196 |
uint8_t *srcbuf2 = visual_video_get_pixels (src2); |
| 197 |
int i; |
| 198 |
int diff1; |
| 199 |
int diff2; |
| 200 |
int hadd; |
| 201 |
|
| 202 |
visual_mem_set (destbuf, 0, visual_video_get_size (dest)); |
| 203 |
|
| 204 |
if (priv->slide_type == SLIDE_RIGHT || priv->slide_type == SLIDE_UPPER) |
| 205 |
rate = 1.0 - rate; |
| 206 |
|
| 207 |
diff1 = dest->pitch * rate; |
| 208 |
diff1 -= diff1 % dest->bpp; |
| 209 |
|
| 210 |
if (diff1 > dest->pitch) |
| 211 |
diff1 = dest->pitch; |
| 212 |
|
| 213 |
diff2 = dest->pitch - diff1; |
| 214 |
|
| 215 |
hadd = dest->height * rate; |
| 216 |
|
| 217 |
switch (priv->slide_type) { |
| 218 |
case SLIDE_LEFT: |
| 219 |
for (i = 0; i < dest->height; i++) { |
| 220 |
visual_mem_copy (destbuf + (i * dest->pitch), srcbuf2 + (i * dest->pitch) + diff2, diff1); |
| 221 |
visual_mem_copy (destbuf + (i * dest->pitch) + (diff1), srcbuf1 + (i * dest->pitch), diff2); |
| 222 |
} |
| 223 |
|
| 224 |
break; |
| 225 |
|
| 226 |
case SLIDE_RIGHT: |
| 227 |
for (i = 0; i < dest->height; i++) { |
| 228 |
visual_mem_copy (destbuf + (i * dest->pitch), srcbuf1 + (i * dest->pitch) + diff2, diff1); |
| 229 |
visual_mem_copy (destbuf + (i * dest->pitch) + (diff1), srcbuf2 + (i * dest->pitch), diff2); |
| 230 |
} |
| 231 |
|
| 232 |
break; |
| 233 |
|
| 234 |
case SLIDE_BOTTOM: |
| 235 |
visual_mem_copy (destbuf, srcbuf1 + (hadd * dest->pitch), (dest->height - hadd) * dest->pitch); |
| 236 |
visual_mem_copy (destbuf + ((dest->height - hadd) * dest->pitch), srcbuf2, hadd * dest->pitch); |
| 237 |
|
| 238 |
break; |
| 239 |
|
| 240 |
case SLIDE_UPPER: |
| 241 |
visual_mem_copy (destbuf, srcbuf2 + (hadd * dest->pitch), (dest->height - hadd) * dest->pitch); |
| 242 |
visual_mem_copy (destbuf + ((dest->height - hadd) * dest->pitch), srcbuf1, hadd * dest->pitch); |
| 243 |
|
| 244 |
break; |
| 245 |
|
| 246 |
default: |
| 247 |
visual_log (VISUAL_LOG_WARNING, |
| 248 |
"Slide plugin is initialized with an impossible slide direction, this should never happen"); |
| 249 |
|
| 250 |
break; |
| 251 |
} |
| 252 |
|
| 253 |
return 0; |
| 254 |
} |
| 255 |
|