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
|
// rotozoom.c
// original code (c) Kentaro Fukuchi (effecTV)
// weed plugin
// (c) G. Finch (salsaman) 2005
//
// released under the GNU GPL 3 or later
// see file COPYING or www.gnu.org for details
#ifdef HAVE_SYSTEM_WEED
#include <weed/weed.h>
#include <weed/weed-palettes.h>
#include <weed/weed-effects.h>
#include <weed/weed-plugin.h>
#else
#include "../../libweed/weed.h"
#include "../../libweed/weed-palettes.h"
#include "../../libweed/weed-effects.h"
#include "../../libweed/weed-plugin.h"
#endif
///////////////////////////////////////////////////////////////////
static int num_versions=2; // number of different weed api versions supported
static int api_versions[]={131,100}; // array of weed api versions supported in plugin, in order of preference (most preferred first)
static int package_version=1; // version of this package
//////////////////////////////////////////////////////////////////
#ifdef HAVE_SYSTEM_WEED
#include <weed/weed-utils.h> // optional
#include <weed/weed-plugin-utils.h> // optional
#else
#include "../../libweed/weed-utils.h" // optional
#include "../../libweed/weed-plugin-utils.h" // optional
#endif
/////////////////////////////////////////////////////////////
#include <math.h>
typedef unsigned int RGB32;
static int roto[256];
static int roto2[256];
/////////////////////////////////////////////////////////////
static void draw_tile(int stepx, int stepy, int zoom,RGB32 *texture,RGB32 *image, int video_width, int video_height)
{
int x, y, xd, yd, a, b, sx, sy;
register int i,j;
int test;
int video_area=video_width*video_height;
sx = sy = 0;
xd = (stepx * zoom) >> 12;
yd = (stepy * zoom) >> 12;
/* Stepping across and down the screen, each screen row has a
* starting coordinate in the texture: (sx, sy). As each screen
* row is traversed, the current texture coordinate (x, y) is
* modified by (xd, yd), which are (sin(rot), cos(rot)) multiplied
* by the current zoom factor. For each vertical step, (xd, yd)
* is rotated 90 degrees, to become (-yd, xd).
*
* More fun can be had by playing around with x, y, xd, and yd as
* you move about the image.
*/
for (j = 0; j < video_height; j++) {
x = sx; y = sy;
for (i = 0; i < video_width; i++) {
a=((x>>12&255)*video_width)>>8;
b=((y>>12&255)*video_height)>>8;
// a*=video_width/64;
// b*=video_height/64;
*image++=((test=b*video_width+a)<video_area)?texture[test]:0;
x += xd; y += yd;
}
sx -= yd; sy += xd;
}
}
//////////////////////////////////////////////////////////
int rotozoom_init (weed_plant_t *inst) {
weed_set_int_value(inst,"plugin_path",0);
weed_set_int_value(inst,"plugin_zpath",0);
return WEED_NO_ERROR;
}
int rotozoom_deinit (weed_plant_t *inst) {
return WEED_NO_ERROR;
}
int rotozoom_process (weed_plant_t *inst, weed_timecode_t timestamp) {
RGB32 *src,*dst;
int width,height;
int zoom;
weed_plant_t *in_channel,*out_channel;
int error;
int path=weed_get_int_value(inst,"plugin_path",&error);
int zpath=weed_get_int_value(inst,"plugin_zpath",&error);
weed_plant_t **in_params=weed_get_plantptr_array(inst,"in_parameters",&error);
int autozoom;
in_channel=weed_get_plantptr_value(inst,"in_channels",&error);
out_channel=weed_get_plantptr_value(inst,"out_channels",&error);
src=weed_get_voidptr_value(in_channel,"pixel_data",&error);
dst=weed_get_voidptr_value(out_channel,"pixel_data",&error);
width = weed_get_int_value(in_channel,"width",&error);
height = weed_get_int_value(in_channel,"height",&error);
autozoom=weed_get_boolean_value(in_params[1],"value",&error);
if (autozoom==WEED_TRUE) {
weed_set_int_value(inst,"plugin_zpath",(zpath + 1) & 255);
}
else {
zpath=weed_get_int_value(in_params[0],"value",&error);
weed_set_int_value(inst,"plugin_zpath",zpath);
}
zoom=roto2[zpath];
draw_tile(roto[path], roto[(path + 128) & 0xFF],zoom,src,dst,width,height);
weed_set_int_value(inst,"plugin_path",(path - 1) & 255);
weed_free(in_params);
return WEED_NO_ERROR;
}
weed_plant_t *weed_setup (weed_bootstrap_f weed_boot) {
weed_plant_t *plugin_info=weed_plugin_info_init(weed_boot,num_versions,api_versions);
if (plugin_info!=NULL) {
int i;
int palette_list[]={WEED_PALETTE_RGBA32,WEED_PALETTE_BGRA32,WEED_PALETTE_ARGB32,WEED_PALETTE_YUVA8888,WEED_PALETTE_END};
weed_plant_t *in_chantmpls[]={weed_channel_template_init("in channel 0",0,palette_list),NULL};
weed_plant_t *out_chantmpls[]={weed_channel_template_init("out channel 0",0,palette_list),NULL};
weed_plant_t *in_params[]={weed_integer_init("zoom","_Zoom value",128,0,255),weed_switch_init("autozoom","_Auto zoom",WEED_TRUE),NULL};
weed_plant_t *filter_class=weed_filter_class_init("rotozoom","effectTV",1,0,&rotozoom_init,&rotozoom_process,&rotozoom_deinit,in_chantmpls,out_chantmpls,in_params,NULL);
weed_plugin_info_add_filter_class (plugin_info,filter_class);
weed_set_int_value(plugin_info,"version",package_version);
// static data for all instances
for (i = 0; i < 256; i++) {
float rad = (float)i * 1.41176 * 0.0174532;
float c = sin(rad);
roto[i] = (c + 0.8) * 4096.0;
roto2[i] = (2.0 * c) * 4096.0;
}
}
return plugin_info;
}
|