From 90f730ca714fb53f47ee16be46fcb06bd98d53ed Mon Sep 17 00:00:00 2001 From: Michael Roitzsch Date: Sun, 27 Jun 2004 11:58:47 +0000 Subject: include the new goom version 2k4-dev15 everybody: test, test, test CVS patchset: 6756 CVS date: 2004/06/27 11:58:47 --- CREDITS | 2 +- ChangeLog | 1 + src/post/goom/Makefile.am | 51 +- src/post/goom/config_param.c | 108 ++ src/post/goom/convolve_fx.c | 134 ++ src/post/goom/cpu_info.c | 63 + src/post/goom/cpu_info.h | 32 + src/post/goom/default_scripts.h | 6 + src/post/goom/drawmethods.c | 203 +++ src/post/goom/drawmethods.h | 242 +-- src/post/goom/filters.c | 1483 +++++++++---------- src/post/goom/filters.h | 77 - src/post/goom/flying_stars_fx.c | 280 ++++ src/post/goom/gfontlib.c | 71 +- src/post/goom/gfontlib.h | 9 +- src/post/goom/gfontrle.c | 3 +- src/post/goom/gfontrle.h | 7 + src/post/goom/goom.h | 27 + src/post/goom/goom_config.h | 44 +- src/post/goom/goom_config_param.h | 106 ++ src/post/goom/goom_core.c | 1860 +++++++++++------------ src/post/goom/goom_core.h | 40 - src/post/goom/goom_filters.h | 52 + src/post/goom/goom_fx.h | 10 + src/post/goom/goom_graphic.h | 66 + src/post/goom/goom_hash.c | 100 ++ src/post/goom/goom_hash.h | 34 + src/post/goom/goom_plugin_info.h | 176 +++ src/post/goom/goom_script.c | 107 ++ src/post/goom/goom_script.h | 16 + src/post/goom/goom_script_scanner.c | 2463 +++++++++++++++++++++++++++++++ src/post/goom/goom_script_scanner.h | 197 +++ src/post/goom/goom_script_scanner.tab.c | 1644 +++++++++++++++++++++ src/post/goom/goom_script_scanner.tab.h | 69 + src/post/goom/goom_tools.c | 21 + src/post/goom/goom_tools.h | 44 +- src/post/goom/goom_typedefs.h | 12 + src/post/goom/goom_visual_fx.h | 26 + src/post/goom/graphic.c | 32 +- src/post/goom/graphic.h | 24 - src/post/goom/ifs.c | 623 +++++--- src/post/goom/ifs.h | 32 +- src/post/goom/ifs_display.c | 268 ---- src/post/goom/lines.c | 36 +- src/post/goom/lines.h | 54 +- src/post/goom/mathtools.c | 84 ++ src/post/goom/mathtools.h | 24 +- src/post/goom/mmx.c | 272 ++++ src/post/goom/mmx.h | 183 ++- src/post/goom/plugin_info.c | 214 +++ src/post/goom/ppc_drawings.h | 18 + src/post/goom/ppc_drawings.s | 370 +++++ src/post/goom/ppc_zoom_ultimate.h | 14 + src/post/goom/ppc_zoom_ultimate.s | 432 +++--- src/post/goom/sound_tester.c | 135 ++ src/post/goom/sound_tester.h | 11 + src/post/goom/surf3d.c | 41 +- src/post/goom/surf3d.h | 4 +- src/post/goom/surface.c | 19 - src/post/goom/surface.h | 16 - src/post/goom/tentacle3d.c | 278 ++-- src/post/goom/tentacle3d.h | 7 +- src/post/goom/v3d.c | 15 + src/post/goom/v3d.h | 12 +- src/post/goom/xine_goom.c | 18 +- src/post/goom/xmmx.c | 395 +++++ src/post/goom/xmmx.h | 354 ----- src/post/goom/zoom_filter_mmx.c | 114 -- src/post/goom/zoom_filter_mmx.h | 9 - src/post/goom/zoom_filter_xmmx.c | 243 --- 70 files changed, 10269 insertions(+), 3968 deletions(-) create mode 100644 src/post/goom/config_param.c create mode 100644 src/post/goom/convolve_fx.c create mode 100644 src/post/goom/cpu_info.c create mode 100644 src/post/goom/cpu_info.h create mode 100644 src/post/goom/default_scripts.h create mode 100644 src/post/goom/drawmethods.c delete mode 100644 src/post/goom/filters.h create mode 100644 src/post/goom/flying_stars_fx.c create mode 100644 src/post/goom/gfontrle.h create mode 100644 src/post/goom/goom.h create mode 100644 src/post/goom/goom_config_param.h delete mode 100644 src/post/goom/goom_core.h create mode 100644 src/post/goom/goom_filters.h create mode 100644 src/post/goom/goom_fx.h create mode 100644 src/post/goom/goom_graphic.h create mode 100644 src/post/goom/goom_hash.c create mode 100644 src/post/goom/goom_hash.h create mode 100644 src/post/goom/goom_plugin_info.h create mode 100644 src/post/goom/goom_script.c create mode 100644 src/post/goom/goom_script.h create mode 100644 src/post/goom/goom_script_scanner.c create mode 100644 src/post/goom/goom_script_scanner.h create mode 100644 src/post/goom/goom_script_scanner.tab.c create mode 100644 src/post/goom/goom_script_scanner.tab.h create mode 100644 src/post/goom/goom_tools.c create mode 100644 src/post/goom/goom_typedefs.h create mode 100644 src/post/goom/goom_visual_fx.h delete mode 100644 src/post/goom/graphic.h delete mode 100644 src/post/goom/ifs_display.c create mode 100644 src/post/goom/mathtools.c create mode 100644 src/post/goom/mmx.c create mode 100644 src/post/goom/plugin_info.c create mode 100644 src/post/goom/ppc_drawings.h create mode 100644 src/post/goom/ppc_drawings.s create mode 100644 src/post/goom/ppc_zoom_ultimate.h create mode 100644 src/post/goom/sound_tester.c create mode 100644 src/post/goom/sound_tester.h delete mode 100755 src/post/goom/surface.c delete mode 100755 src/post/goom/surface.h create mode 100644 src/post/goom/v3d.c create mode 100644 src/post/goom/xmmx.c delete mode 100755 src/post/goom/xmmx.h delete mode 100644 src/post/goom/zoom_filter_mmx.c delete mode 100644 src/post/goom/zoom_filter_mmx.h delete mode 100755 src/post/goom/zoom_filter_xmmx.c diff --git a/CREDITS b/CREDITS index c802453f0..e45981bd8 100644 --- a/CREDITS +++ b/CREDITS @@ -13,7 +13,7 @@ project version mediator ----------------------------------------------------------------------- ffmpeg build 4715 Mike Melanson -goom 1.9dev5 +goom 2k4-dev15 gsm610 1.0.10 Mike Melanson liba52 0.7.4 libcdio 0.68 diff --git a/ChangeLog b/ChangeLog index c147fbb37..82eb985aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,7 @@ xine-lib (1-rc6) * remove XInitThreads() call from some video out plugins, because it might lead to undefined behaviour; calling XInitThreads() is entirely the frontend's job + * include goom2k4-dev15 xine-lib (1-rc5) * add support for ejecting removable media on Solaris diff --git a/src/post/goom/Makefile.am b/src/post/goom/Makefile.am index 41a5eb7ae..4b6fe9862 100644 --- a/src/post/goom/Makefile.am +++ b/src/post/goom/Makefile.am @@ -1,40 +1,35 @@ include $(top_srcdir)/misc/Makefile.common -EXTRA_DIST = zoom_filter_mmx.c zoom_filter_xmmx.c ppc_zoom_ultimate.s - libdir = $(XINE_PLUGINDIR)/post +EXTRA_DIST = mmx.c xmmx.c ppc_drawings.s ppc_zoom_ultimate.s + +## -fomit-frame-pointer segfaults here +CFLAGS = `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-Os//g'` + lib_LTLIBRARIES = xineplug_post_goom.la -if PPC_ARCH -## DON T WORK extra_files = ppc_zoom_ultimate.s -else -## only compile if MMX is supported. +## doesn't work +#if PPC_ARCH +#extra_files = ppc_drawings.s ppc_zoom_ultimate.s +#AM_CPPFLAGS = -DCPU_POWERPC +#endif + if HAVE_FFMMX -extra_files = zoom_filter_mmx.c zoom_filter_xmmx.c -MMX_CFLAG = -DHAVE_MMX +extra_files = mmx.c xmmx.c +AM_CPPFLAGS = -DHAVE_MMX endif -endif - -## -fomit-frame-pointer segfaults here -CFLAGS = $(MMX_CFLAG) `echo @CFLAGS@ | sed -e 's/-fomit-frame-pointer//g;s/-Os//g'` xineplug_post_goom_la_SOURCES = $(extra_files) xine_goom.c \ - goom_core.c \ - filters.c \ - lines.c \ - ifs_display.c \ - ifs.c \ - graphic.c \ - gfontlib.c \ - gfontrle.c \ - surf3d.c \ - surface.c \ - tentacle3d.c - + config_param.c convolve_fx.c cpu_info.c drawmethods.c filters.c flying_stars_fx.c \ + gfontlib.c gfontrle.c goom_core.c goom_hash.c goom_script.c goom_script_scanner.c \ + goom_script_scanner.tab.c goom_tools.c graphic.c ifs.c lines.c mathtools.c \ + plugin_info.c sound_tester.c surf3d.c tentacle3d.c v3d.c xineplug_post_goom_la_LIBADD = $(XINE_LIB) -xineplug_post_goom_la_LDFLAGS = -avoid-version -module @XINE_PLUGIN_MIN_SYMS@ +xineplug_post_goom_la_LDFLAGS = -avoid-version -module $(XINE_PLUGIN_MIN_SYMS) -noinst_HEADERS = drawmethods.h goom_config.h graphic.h mathtools.h surface.h xmmx.h \ - filters.h goom_core.h ifs.h mmx.h tentacle3d.h zoom_filter_mmx.h gfontlib.h \ - goom_tools.h lines.h surf3d.h v3d.h +noinst_HEADERS = cpu_info.h default_scripts.h drawmethods.h gfontlib.h gfontrle.h goom.h \ + goom_config.h goom_config_param.h goom_filters.h goom_fx.h goom_graphic.h goom_hash.h \ + goom_plugin_info.h goom_script.h goom_script_scanner.h goom_script_scanner.tab.h \ + goom_tools.h goom_typedefs.h goom_visual_fx.h ifs.h lines.h mathtools.h mmx.h \ + ppc_drawings.h ppc_zoom_ultimate.h sound_tester.h surf3d.h tentacle3d.h v3d.h diff --git a/src/post/goom/config_param.c b/src/post/goom/config_param.c new file mode 100644 index 000000000..a88adec39 --- /dev/null +++ b/src/post/goom/config_param.c @@ -0,0 +1,108 @@ +/*---------------------------------------------------------------------------*/ +/* +** config_param.c +** Goom Project +** +** Created by Jean-Christophe Hoelt on Sat Jul 19 2003 +** Copyright (c) 2003 iOS. All rights reserved. +*/ +/*---------------------------------------------------------------------------*/ + +#include "goom_config_param.h" +#include + +void empty_fct() { +} + +PluginParam secure_param() { + PluginParam p; + p.changed = empty_fct; + p.change_listener = empty_fct; + p.user_data = 0; + p.name = p.desc = 0; + p.rw = 1; + return p; +} + +PluginParam secure_f_param(char *name) { + PluginParam p = secure_param(); + p.name = name; + p.type = PARAM_FLOATVAL; + FVAL(p) = 0.5f; + FMIN(p) = 0.0f; + FMAX(p) = 1.0f; + FSTEP(p) = 0.01f; + return p; +} + +PluginParam secure_f_feedback(char *name) { + PluginParam p = secure_f_param(name); + p.rw = 0; + return p; +} + +PluginParam secure_s_param(char *name) { + PluginParam p = secure_param(); + p.name = name; + p.type = PARAM_STRVAL; + SVAL(p) = 0; + return p; +} + +PluginParam secure_b_param(char *name, int value) { + PluginParam p = secure_param(); + p.name = name; + p.type = PARAM_BOOLVAL; + BVAL(p) = value; + return p; +} + +PluginParam secure_i_param(char *name) { + PluginParam p = secure_param(); + p.name = name; + p.type = PARAM_INTVAL; + IVAL(p) = 50; + IMIN(p) = 0; + IMAX(p) = 100; + ISTEP(p) = 1; + return p; +} + +PluginParam secure_i_feedback(char *name) { + PluginParam p = secure_i_param(name); + p.rw = 0; + return p; +} + +PluginParameters plugin_parameters(const char *name, int nb) { + PluginParameters p; + p.name = (char *)name; + p.desc = ""; + p.nbParams = nb; + p.params = (PluginParam**)malloc(nb*sizeof(PluginParam*)); + return p; +} + +/*---------------------------------------------------------------------------*/ + +void set_str_param_value(PluginParam *p, const char *str) { + int len = strlen(str); + if (SVAL(*p)) + SVAL(*p) = (char*)realloc(SVAL(*p), len+1); + else + SVAL(*p) = (char*)malloc(len+1); + memcpy(SVAL(*p), str, len+1); +} + +void set_list_param_value(PluginParam *p, const char *str) { + int len = strlen(str); +#ifdef VERBOSE + printf("%s: %d\n", str, len); +#endif + if (LVAL(*p)) + LVAL(*p) = (char*)realloc(LVAL(*p), len+1); + else + LVAL(*p) = (char*)malloc(len+1); + memcpy(LVAL(*p), str, len+1); +} + diff --git a/src/post/goom/convolve_fx.c b/src/post/goom/convolve_fx.c new file mode 100644 index 000000000..518875824 --- /dev/null +++ b/src/post/goom/convolve_fx.c @@ -0,0 +1,134 @@ +#include "goom_fx.h" +#include "goom_plugin_info.h" +#include "goom_script_scanner.h" +#include "goom_config.h" +#include +#include +#include +#include + +static const char DEF_SCRIPT[] = +"float goom = Sound.Goom_Detection;\n" +"float factor = Bright_Flash.Factor;\n" +"(0.8 < goom)? factor = factor + Sound.Goom_Power * 1.5;\n" +"Bright_Flash.Factor = factor * 0.96;\n"; + +#define MAX 2.0f + +typedef struct _CONV_DATA{ +/* float factor; + int lock; + int started; + float curPower;*/ + PluginParam light; + PluginParam factor_adj_p; + PluginParam factor_p; + PluginParam script_p; + PluginParam compile_p; + PluginParameters params; + + GoomScriptScanner *script; + +} ConvData; + +static void convolve_init(VisualFX *_this) { + ConvData *data; + data = (ConvData*)malloc(sizeof(ConvData)); + + data->light = secure_f_param("Screen Brightness"); + data->light.param.fval.max = 300.0f; + data->light.param.fval.step = 1.0f; + data->light.param.fval.value = 100.0f; + + data->factor_adj_p = secure_f_param("Flash Intensity"); + data->factor_adj_p.param.fval.max = 200.0f; + data->factor_adj_p.param.fval.step = 1.0f; + data->factor_adj_p.param.fval.value = 100.0f; + + data->factor_p = secure_f_feedback("Factor"); +/* FVAL(data->factor_p) = data->factor / MAX;*/ + + data->script_p = secure_s_param("Script"); + set_str_param_value(&data->script_p, DEF_SCRIPT); + data->compile_p = secure_b_param("Compile", 0); + + data->params = plugin_parameters ("Bright Flash", 7); + data->params.params[0] = &data->light; + data->params.params[1] = &data->factor_adj_p; + data->params.params[2] = 0; + data->params.params[3] = &data->factor_p; + data->params.params[4] = 0; + data->params.params[5] = &data->script_p; + data->params.params[6] = &data->compile_p; + + data->script = goom_script_scanner_new(); + + _this->params = &data->params; + _this->fx_data = (void*)data; +} + +static void convolve_free(VisualFX *_this) { + free (_this->fx_data); +} + +void create_output_with_brightness(Pixel *src, Pixel *dest, int screensize, int iff) { + + int i; + + if (iff-256 == 0) { + memcpy(dest,src,screensize*sizeof(Pixel)); + return; + } + for (i=screensize-1;i--;) { + unsigned int f,h,m,n; + + f = (src[i].cop[0] * iff) >> 8; + h = (src[i].cop[1] * iff) >> 8; + m = (src[i].cop[2] * iff) >> 8; + n = (src[i].cop[3] * iff) >> 8; + + dest[i].cop[0] = (f & 0xffffff00) ? 0xff : (unsigned char)f; + dest[i].cop[1] = (h & 0xffffff00) ? 0xff : (unsigned char)h; + dest[i].cop[2] = (m & 0xffffff00) ? 0xff : (unsigned char)m; + dest[i].cop[3] = (n & 0xffffff00) ? 0xff : (unsigned char)n; + } +} + +static void convolve_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *info) { + + ConvData *data = (ConvData*)_this->fx_data; + float ff; + int iff; + + ff = (FVAL(data->factor_p) * FVAL(data->factor_adj_p) + FVAL(data->light) ) / 100.0f; + iff = (unsigned int)(ff * 256); + + if (!goom_script_scanner_is_compiled(data->script)) { +#ifdef VERBOSE + printf("setting default script for dynamic brightness\n"); +#endif + goom_script_scanner_compile(data->script, info, DEF_SCRIPT); + } + + if (BVAL(data->compile_p)) { /* le bouton du pauvre ... */ + goom_script_scanner_compile(data->script, info, SVAL(data->script_p)); + BVAL(data->compile_p) = 0; + data->compile_p.change_listener(&data->compile_p); + } + + if (goom_script_scanner_is_compiled(data->script)) { + goom_script_scanner_execute(data->script); + } + + info->methods.create_output_with_brightness(src,dest,info->screen.size,iff); +} + +VisualFX convolve_create() { + VisualFX vfx = { + init: convolve_init, + free: convolve_free, + apply: convolve_apply, + fx_data: 0 + }; + return vfx; +} diff --git a/src/post/goom/cpu_info.c b/src/post/goom/cpu_info.c new file mode 100644 index 000000000..d392ee3d3 --- /dev/null +++ b/src/post/goom/cpu_info.c @@ -0,0 +1,63 @@ +/* + * cpu_info.c + * Goom + * + * Created by Guillaume Borios on Sun Dec 28 2003. + * Copyright (c) 2003 iOS. All rights reserved. + * + */ + +#include "cpu_info.h" + + +static unsigned int CPU_FLAVOUR = 0; +static unsigned int CPU_NUMBER = 1; +static unsigned int CPU_DETECTED = 0; + +static void autoset_cpu_info (void) +{ + CPU_DETECTED = 1; + +#ifdef CPU_POWERPC + int result; + size_t size; + + result = 0; + size = 4; + if (sysctlbyname("hw.optional.altivec",&result,&size,NULL,NULL) == 0) + { + if (result != 0) CPU_FLAVOUR |= CPU_OPTION_ALTIVEC; + } + + result = 0; + size = 4; + if (sysctlbyname("hw.optional.64bitops",&result,&size,NULL,NULL) == 0) + { + if (result != 0) CPU_FLAVOUR |= CPU_OPTION_64_BITS; + } + + result = 0; + size = 4; + if (sysctlbyname("hw.ncpu",&result,&size,NULL,NULL) == 0) + { + if (result != 0) CPU_NUMBER = result; + } +#endif /* CPU_POWERPC */ + +#ifdef CPU_X86 + if (mmx_supported()) CPU_FLAVOUR |= CPU_OPTION_MMX; + if (xmmx_supported()) CPU_FLAVOUR |= CPU_OPTION_XMMX; +#endif /* CPU_X86 */ +} + +unsigned int cpu_flavour (void) +{ + if (CPU_DETECTED == 0) autoset_cpu_info(); + return CPU_FLAVOUR; +} + +unsigned int cpu_number (void) +{ + if (CPU_DETECTED == 0) autoset_cpu_info(); + return CPU_NUMBER; +} diff --git a/src/post/goom/cpu_info.h b/src/post/goom/cpu_info.h new file mode 100644 index 000000000..184cb5102 --- /dev/null +++ b/src/post/goom/cpu_info.h @@ -0,0 +1,32 @@ +#ifndef CPU_INFO_H +#define CPU_INFO_H + +/* + * cpu_info.h + * Goom + * + * Created by Guillaume Borios on Sun Dec 28 2003. + * Copyright (c) 2003 iOS. All rights reserved. + * + */ + +#ifdef HAVE_MMX +#define CPU_X86 +#endif + +/* Returns the CPU flavour described with the constants below */ +unsigned int cpu_flavour (void); + +#define CPU_OPTION_ALTIVEC 0x1 +#define CPU_OPTION_64_BITS 0x2 +#define CPU_OPTION_MMX 0x4 +#define CPU_OPTION_XMMX 0x8 +#define CPU_OPTION_SSE 0x10 +#define CPU_OPTION_SSE2 0x20 +#define CPU_OPTION_3DNOW 0x40 + + +/* Returns the CPU number */ +unsigned int cpu_number (void); + +#endif diff --git a/src/post/goom/default_scripts.h b/src/post/goom/default_scripts.h new file mode 100644 index 000000000..5984d7055 --- /dev/null +++ b/src/post/goom/default_scripts.h @@ -0,0 +1,6 @@ +#ifndef _DEFAULT_SCRIPTS_H +#define _DEFAULT_SCRIPTS_H + +#define GOOM_MAIN_SCRIPT "" + +#endif diff --git a/src/post/goom/drawmethods.c b/src/post/goom/drawmethods.c new file mode 100644 index 000000000..f5cdec4fd --- /dev/null +++ b/src/post/goom/drawmethods.c @@ -0,0 +1,203 @@ +#include "drawmethods.h" + +#define DRAWMETHOD_PLUS(_out,_backbuf,_col) \ +{\ + int tra=0,i=0;\ + unsigned char *bra = (unsigned char*)&(_backbuf);\ + unsigned char *dra = (unsigned char*)&(_out);\ + unsigned char *cra = (unsigned char*)&(_col);\ + for (;i<4;i++) {\ + tra = *cra;\ + tra += *bra;\ + if (tra>255) tra=255;\ + *dra = tra;\ + ++dra;++cra;++bra;\ + }\ +} + +#define DRAWMETHOD DRAWMETHOD_PLUS(*p,*p,col) + +void draw_line (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) +{ + int x, y, dx, dy, yy, xx; + Pixel *p; + + if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx)) return; + + /* clip to top edge + if ((y1 < 0) && (y2 < 0)) + return; + + if (y1 < 0) { + x1 += (y1 * (x1 - x2)) / (y2 - y1); + y1 = 0; + } + if (y2 < 0) { + x2 += (y2 * (x1 - x2)) / (y2 - y1); + y2 = 0; + } + + clip to bottom edge + if ((y1 >= screeny) && (y2 >= screeny)) + return; + if (y1 >= screeny) { + x1 -= ((screeny - y1) * (x1 - x2)) / (y2 - y1); + y1 = screeny - 1; + } + if (y2 >= screeny) { + x2 -= ((screeny - y2) * (x1 - x2)) / (y2 - y1); + y2 = screeny - 1; + } + clip to left edge + if ((x1 < 0) && (x2 < 0)) + return; + if (x1 < 0) { + y1 += (x1 * (y1 - y2)) / (x2 - x1); + x1 = 0; + } + if (x2 < 0) { + y2 += (x2 * (y1 - y2)) / (x2 - x1); + x2 = 0; + } + clip to right edge + if ((x1 >= screenx) && (x2 >= screenx)) + return; + if (x1 >= screenx) { + y1 -= ((screenx - x1) * (y1 - y2)) / (x2 - x1); + x1 = screenx - 1; + } + if (x2 >= screenx) { + y2 -= ((screenx - x2) * (y1 - y2)) / (x2 - x1); + x2 = screenx - 1; + } + */ + + dx = x2 - x1; + dy = y2 - y1; + if (x1 > x2) { + int tmp; + + tmp = x1; + x1 = x2; + x2 = tmp; + tmp = y1; + y1 = y2; + y2 = tmp; + dx = x2 - x1; + dy = y2 - y1; + } + + /* vertical line */ + if (dx == 0) { + if (y1 < y2) { + p = &(data[(screenx * y1) + x1]); + for (y = y1; y <= y2; y++) { + DRAWMETHOD; + p += screenx; + } + } + else { + p = &(data[(screenx * y2) + x1]); + for (y = y2; y <= y1; y++) { + DRAWMETHOD; + p += screenx; + } + } + return; + } + /* horizontal line */ + if (dy == 0) { + if (x1 < x2) { + p = &(data[(screenx * y1) + x1]); + for (x = x1; x <= x2; x++) { + DRAWMETHOD; + p++; + } + return; + } + else { + p = &(data[(screenx * y1) + x2]); + for (x = x2; x <= x1; x++) { + DRAWMETHOD; + p++; + } + return; + } + } + /* 1 */ + /* \ */ + /* \ */ + /* 2 */ + if (y2 > y1) { + /* steep */ + if (dy > dx) { + dx = ((dx << 16) / dy); + x = x1 << 16; + for (y = y1; y <= y2; y++) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p++; + /* DRAWMETHOD; */ + } + x += dx; + } + return; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + } + } + /* 2 */ + /* / */ + /* / */ + /* 1 */ + else { + /* steep */ + if (-dy > dx) { + dx = ((dx << 16) / -dy); + x = (x1 + 1) << 16; + for (y = y1; y >= y2; y--) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p--; + /* DRAWMETHOD; */ + } + x += dx; + } + return; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + return; + } + } +} + diff --git a/src/post/goom/drawmethods.h b/src/post/goom/drawmethods.h index 408dbc2c5..76ad6ca09 100644 --- a/src/post/goom/drawmethods.h +++ b/src/post/goom/drawmethods.h @@ -1,243 +1,9 @@ #ifndef _DRAWMETHODS_H #define _DRAWMETHODS_H -#include "config.h" +#include "goom_config.h" +#include "goom_graphic.h" -#define DRAWMETHOD_NORMAL(adr,col) {*(adr) = (col);} +void draw_line (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); -#ifdef HAVE_MMX -#include "mmx.h" - -#define DRAWMETHOD_PLUS(_out,_backbuf,_col) \ -{\ -movd_m2r (_backbuf, mm0); \ -paddusb_m2r (_col, mm0); \ -movd_r2m (mm0, _out); \ -} - -/* -paddusb (_out -__asm__ ("movd %%eax,%%mm0\n movd %%edx,%%mm1\n paddusb %%mm1,%%mm0\n movd %%mm0,%%eax"\ -:"=eax"(_out):"eax"(_backbuf),"edx"(_col));\ -} -*/ - -#else -#define DRAWMETHOD_PLUS(_out,_backbuf,_col) \ -{\ - int tra=0,i=0;\ - unsigned char *bra = (unsigned char*)&(_backbuf);\ - unsigned char *dra = (unsigned char*)&(_out);\ - unsigned char *cra = (unsigned char*)&(_col);\ - for (;i<4;i++) {\ - tra = *cra;\ - tra += *bra;\ - if (tra>255) tra=255;\ - *dra = tra;\ - ++dra;++cra;++bra;\ - }\ -} -#endif - -#define DRAWMETHOD_OR(adr,col) {*(adr)|=(col);} - -#ifdef HAVE_MMX -#define DRAWMETHOD_DONE() {__asm__ __volatile__ ("emms");} -#else -#define DRAWMETHOD_DONE() {} -#endif - -#ifndef DRAWMETHOD -#define DRAWMETHOD DRAWMETHOD_PLUS(*p,*p,col) -//#define DRAWMETHOD *p=col - -static void -inline draw_line (int *data, int x1, int y1, int x2, int y2, int col, int screenx, - int screeny) -{ - int x, y, dx, dy, yy, xx;// am, tmp; - int *p; - -// DATA32 *p; -// DATA8 aaa, nr, ng, nb, rr, gg, bb, aa, na; - - if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx)) return; - - /* clip to top edge - if ((y1 < 0) && (y2 < 0)) - return; - - if (y1 < 0) { - x1 += (y1 * (x1 - x2)) / (y2 - y1); - y1 = 0; - } - if (y2 < 0) { - x2 += (y2 * (x1 - x2)) / (y2 - y1); - y2 = 0; - } - - /* clip to bottom edge - if ((y1 >= screeny) && (y2 >= screeny)) - return; - if (y1 >= screeny) { - x1 -= ((screeny - y1) * (x1 - x2)) / (y2 - y1); - y1 = screeny - 1; - } - if (y2 >= screeny) { - x2 -= ((screeny - y2) * (x1 - x2)) / (y2 - y1); - y2 = screeny - 1; - } - /* clip to left edge - if ((x1 < 0) && (x2 < 0)) - return; - if (x1 < 0) { - y1 += (x1 * (y1 - y2)) / (x2 - x1); - x1 = 0; - } - if (x2 < 0) { - y2 += (x2 * (y1 - y2)) / (x2 - x1); - x2 = 0; - } - /* clip to right edge - if ((x1 >= screenx) && (x2 >= screenx)) - return; - if (x1 >= screenx) { - y1 -= ((screenx - x1) * (y1 - y2)) / (x2 - x1); - x1 = screenx - 1; - } - if (x2 >= screenx) { - y2 -= ((screenx - x2) * (y1 - y2)) / (x2 - x1); - x2 = screenx - 1; - } - */ - dx = x2 - x1; - dy = y2 - y1; - if (x1 > x2) { - int tmp; - - tmp = x1; - x1 = x2; - x2 = tmp; - tmp = y1; - y1 = y2; - y2 = tmp; - dx = x2 - x1; - dy = y2 - y1; - } - - /* vertical line */ - if (dx == 0) { - if (y1 < y2) { - p = &(data[(screenx * y1) + x1]); - for (y = y1; y <= y2; y++) { - DRAWMETHOD; - p += screenx; - } - } - else { - p = &(data[(screenx * y2) + x1]); - for (y = y2; y <= y1; y++) { - DRAWMETHOD; - p += screenx; - } - } - return; - } - /* horizontal line */ - if (dy == 0) { - if (x1 < x2) { - p = &(data[(screenx * y1) + x1]); - for (x = x1; x <= x2; x++) { - DRAWMETHOD; - p++; - } - return; - } - else { - p = &(data[(screenx * y1) + x2]); - for (x = x2; x <= x1; x++) { - DRAWMETHOD; - p++; - } - return; - } - } - /* 1 */ - /* \ */ - /* \ */ - /* 2 */ - if (y2 > y1) { - /* steep */ - if (dy > dx) { - dx = ((dx << 16) / dy); - x = x1 << 16; - for (y = y1; y <= y2; y++) { - xx = x >> 16; - p = &(data[(screenx * y) + xx]); - DRAWMETHOD; - if (xx < (screenx - 1)) { - p++; -// DRAWMETHOD; - } - x += dx; - } - return; - } - /* shallow */ - else { - dy = ((dy << 16) / dx); - y = y1 << 16; - for (x = x1; x <= x2; x++) { - yy = y >> 16; - p = &(data[(screenx * yy) + x]); - DRAWMETHOD; - if (yy < (screeny - 1)) { - p += screeny; -// DRAWMETHOD; - } - y += dy; - } - } - } - /* 2 */ - /* / */ - /* / */ - /* 1 */ - else { - /* steep */ - if (-dy > dx) { - dx = ((dx << 16) / -dy); - x = (x1 + 1) << 16; - for (y = y1; y >= y2; y--) { - xx = x >> 16; - p = &(data[(screenx * y) + xx]); - DRAWMETHOD; - if (xx < (screenx - 1)) { - p--; -// DRAWMETHOD; - } - x += dx; - } - return; - } - /* shallow */ - else { - dy = ((dy << 16) / dx); - y = y1 << 16; - for (x = x1; x <= x2; x++) { - yy = y >> 16; - p = &(data[(screenx * yy) + x]); - DRAWMETHOD; - if (yy < (screeny - 1)) { - p += screeny; -// DRAWMETHOD; - } - y += dy; - } - return; - } - } -} -#endif - -#endif +#endif /* _DRAWMETHODS_H */ diff --git a/src/post/goom/filters.c b/src/post/goom/filters.c index 9ba2be3dc..d4633ed2b 100644 --- a/src/post/goom/filters.c +++ b/src/post/goom/filters.c @@ -1,854 +1,767 @@ +// --- CHUI EN TRAIN DE SUPPRIMER LES EXTERN RESOLX ET C_RESOLY --- + /* filter.c version 0.7 * contient les filtres applicable a un buffer * creation : 01/10/2000 * -ajout de sinFilter() * -ajout de zoomFilter() -* -copie de zoomFilter() en zoomFilterRGB(), gérant les 3 couleurs +* -copie de zoomFilter() en zoomFilterRGB(), gerant les 3 couleurs * -optimisation de sinFilter (utilisant une table de sin) * -asm -* -optimisation de la procedure de génération du buffer de transformation +* -optimisation de la procedure de generation du buffer de transformation * la vitesse est maintenant comprise dans [0..128] au lieu de [0..100] */ -//#define _DEBUG_PIXEL; +/* #define _DEBUG_PIXEL */ +#include #include -#include #include +#include +#include -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif - -#include "filters.h" -#include "graphic.h" +#include "goom_filters.h" +#include "goom_graphic.h" #include "goom_tools.h" +#include "goom_plugin_info.h" +#include "v3d.h" -#ifdef HAVE_MMX -#define USE_ASM -#endif -#ifdef POWERPC -#define USE_ASM -#endif - -#define EFFECT_DISTORS 4 -#define EFFECT_DISTORS_SL 2 - -extern volatile guint32 resolx; -extern volatile guint32 c_resoly; - -void c_zoom (unsigned int *expix1, unsigned int *expix2, unsigned int prevX, unsigned int prevY, signed int *brutS, signed int *brutD); - -#ifdef HAVE_MMX -//#include "mmx.h" - -void zoom_filter_xmmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, - int *brutS, int *brutD, int buffratio, - int precalCoef[16][16]); -int zoom_filter_xmmx_supported (void); - -void zoom_filter_mmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, - int *brutS, int *brutD, int buffratio, - int precalCoef[16][16]); -int zoom_filter_mmx_supported (void); - -static int zf_use_xmmx = 0; -static int zf_use_mmx = 0; - -static void select_zoom_filter (void) { - static int firsttime = 1; - if (firsttime){ - if (zoom_filter_xmmx_supported()) { - zf_use_xmmx = 1; - /* printf ("Extented MMX detected. Using the fastest method !\n"); */ - } - else if (zoom_filter_mmx_supported()) { - zf_use_mmx = 1; - /* printf ("MMX detected. Using fast method !\n"); */ - } - else { - /* printf ("Too bad ! No MMX detected.\n"); */ - } - firsttime = 0; - } +/* TODO : MOVE THIS AWAY !!! */ +/* jeko: j'ai essayer de le virer, mais si on veut les laisser inline c'est un peu lourdo... */ +inline void setPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color c) +{ + Pixel i; + + i.channels.b = c.b; + i.channels.g = c.v; + i.channels.r = c.r; + *(buffer + (x + y * goomInfo->screen.width)) = i; } -#endif /* MMX */ - - -guint32 mmx_zoom_size; - -#ifdef USE_ASM - -#ifdef POWERPC -#include "altivec.h" -extern unsigned int useAltivec; -extern const void ppc_zoom (unsigned int *frompixmap, unsigned int *topixmap, unsigned int sizex, unsigned int sizey, unsigned int *brutS, unsigned int *brutD, unsigned int buffratio, int precalCoef[16][16]); - -#endif /* PowerPC */ - -#endif /* ASM */ - - -unsigned int *coeffs = 0, *freecoeffs = 0; - -signed int *brutS = 0, *freebrutS = 0; // source -signed int *brutD = 0, *freebrutD = 0; // dest -signed int *brutT = 0, *freebrutT = 0; // temp (en cours de génération) - -// TODO : virer -guint32 *expix1 = 0; // pointeur exporte vers p1 -guint32 *expix2 = 0; // pointeur exporte vers p2 -// fin TODO - -guint32 zoom_width; +inline void setPixelRGB_ (Pixel *buffer, Uint x, Color c) +{ + buffer[x].channels.r = c.r; + buffer[x].channels.g = c.v; + buffer[x].channels.b = c.b; +} -unsigned int prevX = 0, prevY = 0; +inline void getPixelRGB (PluginInfo *goomInfo, Pixel *buffer, Uint x, Uint y, Color * c) +{ + Pixel i = *(buffer + (x + y * goomInfo->screen.width)); + c->b = i.channels.b; + c->v = i.channels.g; + c->r = i.channels.r; +} -static int sintable[0x10000]; -static int vitesse = 127; -static char theMode = AMULETTE_MODE; -static int waveEffect = 0; -static int hypercosEffect = 0; -static int vPlaneEffect = 0; -static int hPlaneEffect = 0; -static char noisify = 2; -static int middleX, middleY; +inline void getPixelRGB_ (Pixel *buffer, Uint x, Color * c) +{ + Pixel i = *(buffer + x); + c->b = i.channels.b; + c->v = i.channels.g; + c->r = i.channels.r; +} +/* END TODO */ -//static unsigned char sqrtperte = 16 ; -/** modif by jeko : fixedpoint : buffration = (16:16) (donc 0<=buffration<=2^16) */ -//static int buffratio = 0; -int buffratio = 0; +/* DEPRECATED */ +// retourne x>>s , en testant le signe de x +//#define ShiftRight(_x,_s) (((_x)<0) ? -(-(_x)>>(_s)) : ((_x)>>(_s))) +//#define EFFECT_DISTORS 4 +//#define EFFECT_DISTORS_SL 2 +//#define INTERLACE_ADD 9 +//#define INTERLACE_AND 0xf +/* END DEPRECATED */ #define BUFFPOINTNB 16 +#define BUFFPOINTNBF 16.0f #define BUFFPOINTMASK 0xffff -#define BUFFINCR 0xff #define sqrtperte 16 -// faire : a % sqrtperte <=> a & pertemask +/* faire : a % sqrtperte <=> a & pertemask */ #define PERTEMASK 0xf -// faire : a / sqrtperte <=> a >> PERTEDEC +/* faire : a / sqrtperte <=> a >> PERTEDEC */ #define PERTEDEC 4 -static int *firedec = 0; - - -// retourne x>>s , en testant le signe de x -#define ShiftRight(_x,_s) (((_x)<0) ? -(-(_x)>>(_s)) : ((_x)>>(_s))) +/* pure c version of the zoom filter */ +static void c_zoom (Pixel *expix1, Pixel *expix2, unsigned int prevX, unsigned int prevY, signed int *brutS, signed int *brutD, int buffratio, int precalCoef[BUFFPOINTNB][BUFFPOINTNB]); -/** modif d'optim by Jeko : precalcul des 4 coefs résultant des 2 pos */ -int precalCoef[16][16]; +/* simple wrapper to give it the same proto than the others */ +void zoom_filter_c (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]) { + c_zoom(src, dest, sizeX, sizeY, brutS, brutD, buffratio, precalCoef); +} -void -generatePrecalCoef (void) +static void generatePrecalCoef (int precalCoef[BUFFPOINTNB][BUFFPOINTNB]); + + +typedef struct _ZOOM_FILTER_FX_WRAPPER_DATA { + + PluginParam enabled_bp; + PluginParameters params; + + unsigned int *coeffs, *freecoeffs; + + signed int *brutS, *freebrutS; /* source */ + signed int *brutD, *freebrutD; /* dest */ + signed int *brutT, *freebrutT; /* temp (en cours de generation) */ + + guint32 zoom_width; + + unsigned int prevX, prevY; + + float general_speed; + int reverse; /* reverse the speed */ + char theMode; + int waveEffect; + int hypercosEffect; + int vPlaneEffect; + int hPlaneEffect; + char noisify; + int middleX, middleY; + + int mustInitBuffers; + int interlace_start; + + /** modif by jeko : fixedpoint : buffration = (16:16) (donc 0<=buffration<=2^16) */ + int buffratio; + int *firedec; + + /** modif d'optim by Jeko : precalcul des 4 coefs resultant des 2 pos */ + int precalCoef[BUFFPOINTNB][BUFFPOINTNB]; + + /** calculatePXandPY statics */ + int wave; + int wavesp; + +} ZoomFilterFXWrapperData; + + + + +inline v2g zoomVector(ZoomFilterFXWrapperData *data, float X, float Y) { - static int firstime = 1; - - if (firstime) { - int coefh, coefv; - - firstime = 0; - - for (coefh = 0; coefh < 16; coefh++) { - - for (coefv = 0; coefv < 16; coefv++) { - int i; - int diffcoeffh; - int diffcoeffv; - - diffcoeffh = sqrtperte - coefh; - diffcoeffv = sqrtperte - coefv; - - // coeffs[myPos] = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC)) << - // 2; - if (!(coefh || coefv)) - i = 255; - else { - int i1, i2, i3, i4; - - i1 = diffcoeffh * diffcoeffv; - i2 = coefh * diffcoeffv; - i3 = diffcoeffh * coefv; - i4 = coefh * coefv; - if (i1) - i1--; - if (i2) - i2--; - if (i3) - i3--; - if (i4) - i4--; - - i = (i1) | (i2 << 8) | (i3 << 16) | (i4 << 24); - } - precalCoef[coefh][coefv] = i; - } - } - } + v2g vecteur; + float vx, vy; + float sq_dist = X*X + Y*Y; + + /* sx = (X < 0.0f) ? -1.0f : 1.0f; + sy = (Y < 0.0f) ? -1.0f : 1.0f; + */ + float coefVitesse = (1.0f+ data->general_speed) / 50.0f; + + // Effects + + /* Centralized FX */ + + switch (data->theMode) { + case CRYSTAL_BALL_MODE: + coefVitesse -= (sq_dist-0.3f)/15.0f; + break; + case AMULETTE_MODE: + coefVitesse += sq_dist * 3.5f; + break; + case WAVE_MODE: + coefVitesse += sin(sq_dist*20.0f) / 100.0f; + break; + case SCRUNCH_MODE: + coefVitesse += sq_dist / 10.0f; + break; + //case HYPERCOS1_MODE: + break; + //case HYPERCOS2_MODE: + break; + //case YONLY_MODE: + break; + case SPEEDWAY_MODE: + coefVitesse *= 4.0f * Y; + break; + default: + break; + } + + if (coefVitesse < -2.01f) + coefVitesse = -2.01f; + if (coefVitesse > 2.01f) + coefVitesse = 2.01f; + + vx = coefVitesse * X; + vy = coefVitesse * Y; + + /* Amulette 2 */ + // vx = X * tan(dist); + // vy = Y * tan(dist); + + /* Rotate */ + //vx = (X+Y)*0.1; + //vy = (Y-X)*0.1; + + + // Effects adds-on + + /* Noise */ + if (data->noisify) + { + vx += (((float)random()) / ((float)RAND_MAX) - 0.5f) / 50.0f; + vy += (((float)random()) / ((float)RAND_MAX) - 0.5f) / 50.0f; + } + + /* Hypercos */ + if (data->hypercosEffect) + { + vx += sin(Y*10.0f)/120.0f; + vy += sin(X*10.0f)/120.0f; + } + + /* H Plane */ + if (data->hPlaneEffect) vx += Y * 0.0025f * data->hPlaneEffect; + + /* V Plane */ + if (data->vPlaneEffect) vy += X * 0.0025f * data->vPlaneEffect; + + /* TODO : Water Mode */ + // if (data->waveEffect) + + vecteur.x = vx; + vecteur.y = vy; + + return vecteur; } + /* - calculer px et py en fonction de x,y,middleX,middleY et theMode - px et py indique la nouvelle position (en sqrtperte ieme de pixel) - (valeur * 16) + * Makes a stripe of a transform buffer (brutT) + * + * The transform is (in order) : + * Translation (-data->middleX, -data->middleY) + * Homothetie (Center : 0,0 Coeff : 2/data->prevX) */ -inline void -calculatePXandPY (int x, int y, int *px, int *py) +void makeZoomBufferStripe(ZoomFilterFXWrapperData * data, int INTERLACE_INCR) { - if (theMode == WATER_MODE) { - static int wave = 0; - static int wavesp = 0; - int yy; - - yy = y + RAND () % 4 - RAND () % 4 + wave / 10; - if (yy < 0) - yy = 0; - if (yy >= c_resoly) - yy = c_resoly - 1; - - *px = (x << 4) + firedec[yy] + (wave / 10); - *py = (y << 4) + 132 - ((vitesse < 131) ? vitesse : 130); - - wavesp += RAND () % 3 - RAND () % 3; - if (wave < -10) - wavesp += 2; - if (wave > 10) - wavesp -= 2; - wave += (wavesp / 10) + RAND () % 3 - RAND () % 3; - if (wavesp > 100) - wavesp = (wavesp * 9) / 10; - } - else { - int dist = 0, vx9, vy9; - int vx, vy; - int ppx, ppy; - int fvitesse = vitesse << 4; - - if (noisify) { - x += RAND () % noisify - RAND () % noisify; - y += RAND () % noisify - RAND () % noisify; - } - vx = (x - middleX) << 9; - vy = (y - middleY) << 9; - - if (hPlaneEffect) - vx += hPlaneEffect * (y - middleY); - // else vx = (x - middleX) << 9 ; - - if (vPlaneEffect) - vy += vPlaneEffect * (x - middleX); - // else vy = (y - middleY) << 9 ; - - if (waveEffect) { - fvitesse *= - 1024 + - ShiftRight (sintable - [(unsigned short) (dist * 0xffff + EFFECT_DISTORS)], 6); - fvitesse /= 1024; - } - - if (hypercosEffect) { - vx += ShiftRight (sintable[(-vy + dist) & 0xffff], 1); - vy += ShiftRight (sintable[(vx + dist) & 0xffff], 1); - } - - vx9 = ShiftRight (vx, 9); - vy9 = ShiftRight (vy, 9); - dist = vx9 * vx9 + vy9 * vy9; - - switch (theMode) { - case WAVE_MODE: - fvitesse *= - 1024 + - ShiftRight (sintable - [(unsigned short) (dist * 0xffff * EFFECT_DISTORS)], 6); - fvitesse>>=10;///=1024; - break; - case CRYSTAL_BALL_MODE: - fvitesse += (dist >> (10-EFFECT_DISTORS_SL)); - break; - case AMULETTE_MODE: - fvitesse -= (dist >> (4 - EFFECT_DISTORS_SL)); - break; - case SCRUNCH_MODE: - fvitesse -= (dist >> (10 - EFFECT_DISTORS_SL)); - break; - case HYPERCOS1_MODE: - vx = vx + ShiftRight (sintable[(-vy + dist) & 0xffff], 1); - vy = vy + ShiftRight (sintable[(vx + dist) & 0xffff], 1); - break; - case HYPERCOS2_MODE: - vx = - vx + ShiftRight (sintable[(-ShiftRight (vy, 1) + dist) & 0xffff], 0); - vy = - vy + ShiftRight (sintable[(ShiftRight (vx, 1) + dist) & 0xffff], 0); - fvitesse = 128 << 4; - break; - case YONLY_MODE: - fvitesse *= 1024 + ShiftRight (sintable[vy & 0xffff], 6); - fvitesse >>= 10; - break; - case SPEEDWAY_MODE: - fvitesse -= (ShiftRight(vy,10-EFFECT_DISTORS_SL)); - break; - } - - if (fvitesse < -3024) - fvitesse = -3024; - - if (vx < 0) // pb avec decalage sur nb negatif - ppx = -(-(vx * fvitesse) >> 16); - /* 16 = 9 + 7 (7 = nb chiffre virgule de vitesse * (v = 128 => immobile) - * * * * * 9 = nb chiffre virgule de vx) */ - else - ppx = ((vx * fvitesse) >> 16); - - if (vy < 0) - ppy = -(-(vy * fvitesse) >> 16); - else - ppy = ((vy * fvitesse) >> 16); - - *px = (middleX << 4) + ppx; - *py = (middleY << 4) + ppy; - } + // Position of the pixel to compute in pixmap coordinates + Uint x, y; + // Where (verticaly) to stop generating the buffer stripe + int maxEnd = (data->interlace_start + INTERLACE_INCR); + // Ratio from pixmap to normalized coordinates + float ratio = 2.0f/((float)data->prevX); + // Ratio from normalized to virtual pixmap coordinates + float inv_ratio = BUFFPOINTNBF/ratio; + float min = ratio/BUFFPOINTNBF; + // Y position of the pixel to compute in normalized coordinates + float Y = ((float)(data->interlace_start - data->middleY)) * ratio; + + maxEnd = data->prevY; + if (maxEnd > (data->interlace_start + INTERLACE_INCR)) + maxEnd = (data->interlace_start + INTERLACE_INCR); + + for (y = data->interlace_start; (y < data->prevY) && ((signed int)yprevX * 2; + float X = - ((float)data->middleX) * ratio; + for (x = 0; x < data->prevX; x++) + { + v2g vector = zoomVector (data, X, Y); + + /* Finish and avoid null displacement */ + if (fabs(vector.x) < min) vector.x = (vector.x < 0.0f) ? -min : min; + if (fabs(vector.y) < min) vector.y = (vector.y < 0.0f) ? -min : min; + + data->brutT[premul_y_prevX] = ((int)((X-vector.x)*inv_ratio)+((int)(data->middleX*BUFFPOINTNB))); + data->brutT[premul_y_prevX+1] = ((int)((Y-vector.y)*inv_ratio)+((int)(data->middleY*BUFFPOINTNB))); + premul_y_prevX += 2; + X += ratio; + } + Y += ratio; + } + data->interlace_start += INTERLACE_INCR; + if (y >= data->prevY-1) data->interlace_start = -1; } -//#define _DEBUG -inline void -setPixelRGB (Uint * buffer, Uint x, Uint y, Color c) -{ - // buffer[ y*WIDTH + x ] = (c.r<<16)|(c.v<<8)|c.b -#ifdef _DEBUG_PIXEL - if (x + y * resolx >= resolx * resoly) { - fprintf (stderr, "setPixel ERROR : hors du tableau... %i, %i\n", x, y); - // exit (1) ; - } -#endif - - buffer[y * resolx + x] = - (c.b << (BLEU * 8)) | (c.v << (VERT * 8)) | (c.r << (ROUGE * 8)); -} +/* + * calculer px et py en fonction de x,y,middleX,middleY et theMode + * px et py indique la nouvelle position (en sqrtperte ieme de pixel) + * (valeur * 16) + + inline void calculatePXandPY (PluginInfo *goomInfo, ZoomFilterFXWrapperData *data, int x, int y, int *px, int *py) + { + if (data->theMode == WATER_MODE) { + int yy; + + yy = y + goom_irand(goomInfo->gRandom, 4) - goom_irand(goomInfo->gRandom, 4) + data->wave / 10; + if (yy < 0) + yy = 0; + if (yy >= (signed int)goomInfo->screen.height) + yy = goomInfo->screen.height - 1; + + *px = (x << 4) + data->firedec[yy] + (data->wave / 10); + *py = (y << 4) + 132 - ((data->vitesse < 131) ? data->vitesse : 130); + + data->wavesp += goom_irand(goomInfo->gRandom, 3) - goom_irand(goomInfo->gRandom, 3); + if (data->wave < -10) + data->wavesp += 2; + if (data->wave > 10) + data->wavesp -= 2; + data->wave += (data->wavesp / 10) + goom_irand(goomInfo->gRandom, 3) - goom_irand(goomInfo->gRandom, 3); + if (data->wavesp > 100) + data->wavesp = (data->wavesp * 9) / 10; + } + else { + int dist = 0, vx9, vy9; + int vx, vy; + int ppx, ppy; + int fvitesse = data->vitesse << 4; + + if (data->noisify) { + x += goom_irand(goomInfo->gRandom, data->noisify) - goom_irand(goomInfo->gRandom, data->noisify); + y += goom_irand(goomInfo->gRandom, data->noisify) - goom_irand(goomInfo->gRandom, data->noisify); + } + vx = (x - data->middleX) << 9; + vy = (y - data->middleY) << 9; + + if (data->hPlaneEffect) + vx += data->hPlaneEffect * (y - data->middleY); + + if (data->vPlaneEffect) + vy += data->vPlaneEffect * (x - data->middleX); + + if (data->waveEffect) { + fvitesse *= + 1024 + + ShiftRight (goomInfo->sintable + [(unsigned short) (dist * 0xffff + EFFECT_DISTORS)], 6); + fvitesse /= 1024; + } + + if (data->hypercosEffect) { + vx += ShiftRight (goomInfo->sintable[(-vy + dist) & 0xffff], 1); + vy += ShiftRight (goomInfo->sintable[(vx + dist) & 0xffff], 1); + } + + vx9 = ShiftRight (vx, 9); + vy9 = ShiftRight (vy, 9); + dist = vx9 * vx9 + vy9 * vy9; + + switch (data->theMode) { + case WAVE_MODE: + fvitesse *= + 1024 + + ShiftRight (goomInfo->sintable + [(unsigned short) (dist * 0xffff * EFFECT_DISTORS)], 6); + fvitesse>>=10; + break; + case CRYSTAL_BALL_MODE: + fvitesse += (dist >> (10-EFFECT_DISTORS_SL)); + break; + case AMULETTE_MODE: + fvitesse -= (dist >> (4 - EFFECT_DISTORS_SL)); + break; + case SCRUNCH_MODE: + fvitesse -= (dist >> (10 - EFFECT_DISTORS_SL)); + break; + case HYPERCOS1_MODE: + vx = vx + ShiftRight (goomInfo->sintable[(-vy + dist) & 0xffff], 1); + vy = vy + ShiftRight (goomInfo->sintable[(vx + dist) & 0xffff], 1); + break; + case HYPERCOS2_MODE: + vx = + vx + ShiftRight (goomInfo->sintable[(-ShiftRight (vy, 1) + dist) & 0xffff], 0); + vy = + vy + ShiftRight (goomInfo->sintable[(ShiftRight (vx, 1) + dist) & 0xffff], 0); + fvitesse = 128 << 4; + break; + case YONLY_MODE: + fvitesse *= 1024 + ShiftRight (goomInfo->sintable[vy & 0xffff], 6); + fvitesse >>= 10; + break; + case SPEEDWAY_MODE: + fvitesse -= (ShiftRight(vy,10-EFFECT_DISTORS_SL)); + break; + } + + if (fvitesse < -3024) + fvitesse = -3024; + + if (vx < 0) // pb avec decalage sur nb negatif + ppx = -(-(vx * fvitesse) >> 16); + // 16 = 9 + 7 (7 = nb chiffre virgule de vitesse * (v = 128 => immobile) + // * * * * * 9 = nb chiffre virgule de vx) + else + ppx = ((vx * fvitesse) >> 16); + + if (vy < 0) + ppy = -(-(vy * fvitesse) >> 16); + else + ppy = ((vy * fvitesse) >> 16); + + *px = (data->middleX << 4) + ppx; + *py = (data->middleY << 4) + ppy; + } + } + */ + -inline void -setPixelRGB_ (Uint * buffer, Uint x, Color c) +static void c_zoom (Pixel *expix1, Pixel *expix2, unsigned int prevX, unsigned int prevY, signed int *brutS, signed int *brutD, + int buffratio, int precalCoef[16][16]) { -#ifdef _DEBUG - if (x >= resolx * c_resoly) { - printf ("setPixel ERROR : hors du tableau... %i\n", x); - // exit (1) ; - } -#endif - - buffer[x] = (c.r << (ROUGE * 8)) | (c.v << (VERT * 8)) | c.b << (BLEU * 8); + int myPos, myPos2; + Color couleur; + + unsigned int ax = (prevX - 1) << PERTEDEC, ay = (prevY - 1) << PERTEDEC; + + int bufsize = prevX * prevY * 2; + int bufwidth = prevX; + + expix1[0].val=expix1[prevX-1].val=expix1[prevX*prevY-1].val=expix1[prevX*prevY-prevX].val=0; + + for (myPos = 0; myPos < bufsize; myPos += 2) { + Color col1, col2, col3, col4; + int c1, c2, c3, c4, px, py; + int pos; + int coeffs; + + int brutSmypos = brutS[myPos]; + + myPos2 = myPos + 1; + + px = brutSmypos + (((brutD[myPos] - brutSmypos) * buffratio) >> BUFFPOINTNB); + brutSmypos = brutS[myPos2]; + py = brutSmypos + (((brutD[myPos2] - brutSmypos) * buffratio) >> BUFFPOINTNB); + + pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC)); + /* coef en modulo 15 */ + coeffs = precalCoef[px & PERTEMASK][py & PERTEMASK]; + + if ((py >= (signed int)ay) || (px >= (signed int)ax)) { + pos = coeffs = 0; + } + + getPixelRGB_ (expix1, pos, &col1); + getPixelRGB_ (expix1, pos + 1, &col2); + getPixelRGB_ (expix1, pos + bufwidth, &col3); + getPixelRGB_ (expix1, pos + bufwidth + 1, &col4); + + c1 = coeffs; + c2 = (c1 >> 8) & 0xFF; + c3 = (c1 >> 16) & 0xFF; + c4 = (c1 >> 24) & 0xFF; + c1 = c1 & 0xff; + + couleur.r = col1.r * c1 + col2.r * c2 + col3.r * c3 + col4.r * c4; + if (couleur.r > 5) + couleur.r -= 5; + couleur.r >>= 8; + + couleur.v = col1.v * c1 + col2.v * c2 + col3.v * c3 + col4.v * c4; + if (couleur.v > 5) + couleur.v -= 5; + couleur.v >>= 8; + + couleur.b = col1.b * c1 + col2.b * c2 + col3.b * c3 + col4.b * c4; + if (couleur.b > 5) + couleur.b -= 5; + couleur.b >>= 8; + + setPixelRGB_ (expix2, myPos >> 1, couleur); + } +} + +/** generate the water fx horizontal direction buffer */ +static void generateTheWaterFXHorizontalDirectionBuffer(PluginInfo *goomInfo, ZoomFilterFXWrapperData *data) { + + int loopv; + int decc = goom_irand(goomInfo->gRandom, 8) - 4; + int spdc = goom_irand(goomInfo->gRandom, 8) - 4; + int accel = goom_irand(goomInfo->gRandom, 8) - 4; + + for (loopv = data->prevY; loopv != 0;) { + + loopv--; + data->firedec[loopv] = decc; + decc += spdc / 10; + spdc += goom_irand(goomInfo->gRandom, 3) - goom_irand(goomInfo->gRandom, 3); + + if (decc > 4) + spdc -= 1; + if (decc < -4) + spdc += 1; + + if (spdc > 30) + spdc = spdc - goom_irand(goomInfo->gRandom, 3) + accel / 10; + if (spdc < -30) + spdc = spdc + goom_irand(goomInfo->gRandom, 3) + accel / 10; + + if (decc > 8 && spdc > 1) + spdc -= goom_irand(goomInfo->gRandom, 3) - 2; + + if (decc < -8 && spdc < -1) + spdc += goom_irand(goomInfo->gRandom, 3) + 2; + + if (decc > 8 || decc < -8) + decc = decc * 8 / 9; + + accel += goom_irand(goomInfo->gRandom, 2) - goom_irand(goomInfo->gRandom, 2); + if (accel > 20) + accel -= 2; + if (accel < -20) + accel += 2; + } } -inline void -getPixelRGB (Uint * buffer, Uint x, Uint y, Color * c) +/** +* Main work for the dynamic displacement map. + * + * Reads data from pix1, write to pix2. + * + * Useful datas for this FX are stored in ZoomFilterData. + * + * If you think that this is a strange function name, let me say that a long time ago, + * there has been a slow version and a gray-level only one. Then came these function, + * fast and workin in RGB colorspace ! nice but it only was applying a zoom to the image. + * So that is why you have this name, for the nostalgy of the first days of goom + * when it was just a tiny program writen in Turbo Pascal on my i486... + */ +void zoomFilterFastRGB (PluginInfo *goomInfo, Pixel * pix1, Pixel * pix2, ZoomFilterData * zf, Uint resx, Uint resy, int switchIncr, float switchMult) { -// register unsigned char *tmp8; - unsigned int i; - -#ifdef _DEBUG - if (x + y * resolx >= resolx * c_resoly) { - printf ("getPixel ERROR : hors du tableau... %i, %i\n", x, y); - // exit (1) ; - } -#endif - - /* ATTENTION AU PETIT INDIEN */ - i = *(buffer + (x + y * resolx)); - c->b = (i >> (BLEU * 8)) & 0xff; - c->v = (i >> (VERT * 8)) & 0xff; - c->r = (i >> (ROUGE * 8)) & 0xff; + Uint x, y; + + ZoomFilterFXWrapperData *data = (ZoomFilterFXWrapperData*)goomInfo->zoomFilter_fx.fx_data; + + if (!BVAL(data->enabled_bp)) return; + + /** changement de taille **/ + if ((data->prevX != resx) || (data->prevY != resy)) { + data->prevX = resx; + data->prevY = resy; + + if (data->brutS) free (data->freebrutS); + data->brutS = 0; + if (data->brutD) free (data->freebrutD); + data->brutD = 0; + if (data->brutT) free (data->freebrutT); + data->brutT = 0; + + data->middleX = resx / 2; + data->middleY = resy / 2; + data->mustInitBuffers = 1; + if (data->firedec) free (data->firedec); + data->firedec = 0; + } + + if (data->interlace_start != -2) + zf = NULL; + + /** changement de config **/ + if (zf) { + data->reverse = zf->reverse; + data->general_speed = (float)(zf->vitesse-128)/128.0f; + if (data->reverse) data->general_speed = -data->general_speed; + data->middleX = zf->middleX; + data->middleY = zf->middleY; + data->theMode = zf->mode; + data->hPlaneEffect = zf->hPlaneEffect; + data->vPlaneEffect = zf->vPlaneEffect; + data->waveEffect = zf->waveEffect; + data->hypercosEffect = zf->hypercosEffect; + data->noisify = zf->noisify; + data->interlace_start = 0; + } + + + if (data->mustInitBuffers) { + + data->mustInitBuffers = 0; + data->freebrutS = (signed int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); + data->brutS = (gint32 *) ((1 + ((uintptr_t) (data->freebrutS)) / 128) * 128); + + data->freebrutD = (signed int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); + data->brutD = (gint32 *) ((1 + ((uintptr_t) (data->freebrutD)) / 128) * 128); + + data->freebrutT = (signed int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); + data->brutT = (gint32 *) ((1 + ((uintptr_t) (data->freebrutT)) / 128) * 128); + + data->buffratio = 0; + + data->firedec = (int *) malloc (data->prevY * sizeof (int)); + generateTheWaterFXHorizontalDirectionBuffer(goomInfo, data); + + data->interlace_start = 0; + makeZoomBufferStripe(data,resy); + + /* Copy the data from temp to dest and source */ + memcpy(data->brutS,data->brutT,resx * resy * 2 * sizeof(int)); + memcpy(data->brutD,data->brutT,resx * resy * 2 * sizeof(int)); + } + + /* generation du buffer de trans */ + if (data->interlace_start == -1) { + + /* sauvegarde de l'etat actuel dans la nouvelle source + * TODO: write that in MMX (has been done in previous version, but did not follow some new fonctionnalities) */ + y = data->prevX * data->prevY * 2; + for (x = 0; x < y; x += 2) { + int brutSmypos = data->brutS[x]; + int x2 = x + 1; + + data->brutS[x] = brutSmypos + (((data->brutD[x] - brutSmypos) * data->buffratio) >> BUFFPOINTNB); + brutSmypos = data->brutS[x2]; + data->brutS[x2] = brutSmypos + (((data->brutD[x2] - brutSmypos) * data->buffratio) >> BUFFPOINTNB); + } + data->buffratio = 0; + } + + if (data->interlace_start == -1) { + signed int * tmp; + tmp = data->brutD; + data->brutD=data->brutT; + data->brutT=tmp; + tmp = data->freebrutD; + data->freebrutD=data->freebrutT; + data->freebrutT=tmp; + data->interlace_start = -2; + } + + if (data->interlace_start>=0) + { + /* creation de la nouvelle destination */ + makeZoomBufferStripe(data,resy/16); + } + + if (switchIncr != 0) { + data->buffratio += switchIncr; + if (data->buffratio > BUFFPOINTMASK) + data->buffratio = BUFFPOINTMASK; + } + + if (switchMult != 1.0f) { + data->buffratio = (int) ((float) BUFFPOINTMASK * (1.0f - switchMult) + + (float) data->buffratio * switchMult); + } + + data->zoom_width = data->prevX; + + goomInfo->methods.zoom_filter (data->prevX, data->prevY, pix1, pix2, + data->brutS, data->brutD, data->buffratio, data->precalCoef); } - -inline void -getPixelRGB_ (Uint * buffer, Uint x, Color * c) +static void generatePrecalCoef (int precalCoef[16][16]) { - register unsigned char *tmp8; - -#ifdef _DEBUG - if (x >= resolx * c_resoly) { - printf ("getPixel ERROR : hors du tableau... %i\n", x); - // exit (1) ; - } -#endif - -#ifdef __BIG_ENDIAN__ - c->b = *(unsigned char *) (tmp8 = (unsigned char *) (buffer + x)); - c->r = *(unsigned char *) (++tmp8); - c->v = *(unsigned char *) (++tmp8); - c->b = *(unsigned char *) (++tmp8); - -#else - /* ATTENTION AU PETIT INDIEN */ - c->b = *(unsigned char *) (tmp8 = (unsigned char *) (buffer + x)); - c->v = *(unsigned char *) (++tmp8); - c->r = *(unsigned char *) (++tmp8); - // *c = (Color) buffer[x+y*WIDTH] ; -#endif + int coefh, coefv; + + for (coefh = 0; coefh < 16; coefh++) { + for (coefv = 0; coefv < 16; coefv++) { + + int i; + int diffcoeffh; + int diffcoeffv; + + diffcoeffh = sqrtperte - coefh; + diffcoeffv = sqrtperte - coefv; + + if (!(coefh || coefv)) { + i = 255; + } + else { + int i1, i2, i3, i4; + + i1 = diffcoeffh * diffcoeffv; + i2 = coefh * diffcoeffv; + i3 = diffcoeffh * coefv; + i4 = coefh * coefv; + + // TODO: faire mieux... + if (i1) i1--; + if (i2) i2--; + if (i3) i3--; + if (i4) i4--; + + i = (i1) | (i2 << 8) | (i3 << 16) | (i4 << 24); + } + precalCoef[coefh][coefv] = i; + } + } } +/* VisualFX Wrapper */ -void c_zoom (unsigned int *expix1, unsigned int *expix2, unsigned int prevX, unsigned int prevY, signed int *brutS, signed int *brutD) +void zoomFilterVisualFXWrapper_init (struct _VISUAL_FX *_this) { - int myPos, myPos2; - Color couleur; -// unsigned int coefv, coefh; - - unsigned int ax = (prevX - 1) << PERTEDEC, ay = (prevY - 1) << PERTEDEC; - - int bufsize = prevX * prevY * 2; - int bufwidth = prevX; - - expix1[0]=expix1[prevX-1]=expix1[prevX*prevY-1]=expix1[prevX*prevY-prevX]=0; - - for (myPos = 0; myPos < bufsize; myPos += 2) { - Color col1, col2, col3, col4; - int c1, c2, c3, c4, px, py; - int pos; - int coeffs; - - int brutSmypos = brutS[myPos]; - - myPos2 = myPos + 1; - - px = - brutSmypos + (((brutD[myPos] - brutSmypos) * buffratio) >> BUFFPOINTNB); - brutSmypos = brutS[myPos2]; - py = - brutSmypos + - (((brutD[myPos2] - brutSmypos) * buffratio) >> BUFFPOINTNB); - - pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC)); - // coef en modulo 15 - coeffs = precalCoef[px & PERTEMASK][py & PERTEMASK]; - - if ((py >= ay) || (px >= ax)) { - pos = coeffs = 0; - } - - getPixelRGB_ (expix1, pos, &col1); - getPixelRGB_ (expix1, pos + 1, &col2); - getPixelRGB_ (expix1, pos + bufwidth, &col3); - getPixelRGB_ (expix1, pos + bufwidth + 1, &col4); - - c1 = coeffs; - c2 = (c1 & 0x0000ff00) >> 8; - c3 = (c1 & 0x00ff0000) >> 16; - c4 = (c1 & 0xff000000) >> 24; - c1 = c1 & 0xff; - - couleur.r = col1.r * c1 + col2.r * c2 + col3.r * c3 + col4.r * c4; - if (couleur.r > 5) - couleur.r -= 5; - couleur.r >>= 8; - - couleur.v = col1.v * c1 + col2.v * c2 + col3.v * c3 + col4.v * c4; - if (couleur.v > 5) - couleur.v -= 5; - couleur.v >>= 8; - - couleur.b = col1.b * c1 + col2.b * c2 + col3.b * c3 + col4.b * c4; - if (couleur.b > 5) - couleur.b -= 5; - couleur.b >>= 8; - - setPixelRGB_ (expix2, myPos >> 1, couleur); - } + ZoomFilterFXWrapperData *data = (ZoomFilterFXWrapperData*)malloc(sizeof(ZoomFilterFXWrapperData)); + + data->coeffs = 0; + data->freecoeffs = 0; + data->brutS = 0; + data->freebrutS = 0; + data->brutD = 0; + data->freebrutD = 0; + data->brutT = 0; + data->freebrutT = 0; + data->prevX = 0; + data->prevY = 0; + + data->mustInitBuffers = 1; + data->interlace_start = -2; + + data->general_speed = 0.0f; + data->reverse = 0; + data->theMode = AMULETTE_MODE; + data->waveEffect = 0; + data->hypercosEffect = 0; + data->vPlaneEffect = 0; + data->hPlaneEffect = 0; + data->noisify = 2; + + /** modif by jeko : fixedpoint : buffration = (16:16) (donc 0<=buffration<=2^16) */ + data->buffratio = 0; + data->firedec = 0; + + data->wave = data->wavesp = 0; + + data->enabled_bp = secure_b_param("Enabled", 1); + + data->params = plugin_parameters ("Zoom Filter", 1); + data->params.params[0] = &data->enabled_bp; + + _this->params = &data->params; + _this->fx_data = (void*)data; + + /** modif d'optim by Jeko : precalcul des 4 coefs resultant des 2 pos */ + generatePrecalCoef(data->precalCoef); } -#ifdef USE_ASM -static int use_asm = 1; -void -setAsmUse (int useIt) +void zoomFilterVisualFXWrapper_free (struct _VISUAL_FX *_this) { - use_asm = useIt; + free(_this->fx_data); } -int -getAsmUse (void) +void zoomFilterVisualFXWrapper_apply (struct _VISUAL_FX *_this, Pixel *src, Pixel *dest, PluginInfo *info) { - return use_asm; } -#endif - -/*===============================================================*/ -void -zoomFilterFastRGB (Uint * pix1, - Uint * pix2, - ZoomFilterData * zf, - Uint resx, Uint resy, int switchIncr, float switchMult) -{ - register Uint x, y; -// unsigned int *temp = brutD; - - static char reverse = 0; // vitesse inversé..(zoom out) - static unsigned char pertedec = 8; - static char firstTime = 1; - -#define INTERLACE_INCR 16 -#define INTERLACE_ADD 9 -#define INTERLACE_AND 0xf - static int interlace_start = -2; - -/* TODO virer */ - expix1 = pix1; - expix2 = pix2; -/* */ - - /** changement de taille **/ - if ((prevX != resx) || (prevY != resy)) { - prevX = resx; - prevY = resy; - - if (brutS) - free (freebrutS); - brutS = 0; - if (brutD) - free (freebrutD); - brutD = 0; - if (brutT) - free (freebrutT); - brutT = 0; - - middleX = resx / 2; - middleY = resy - 1; - firstTime = 1; - if (firedec) - free (firedec); - firedec = 0; - } - - if (interlace_start != -2) - zf = NULL; - - /** changement de config **/ - if (zf) { - reverse = zf->reverse; - vitesse = zf->vitesse; - if (reverse) - vitesse = 256 - vitesse; - pertedec = zf->pertedec; - middleX = zf->middleX; - middleY = zf->middleY; - theMode = zf->mode; - hPlaneEffect = zf->hPlaneEffect; - vPlaneEffect = zf->vPlaneEffect; - waveEffect = zf->waveEffect; - hypercosEffect = zf->hypercosEffect; - noisify = zf->noisify; - } - - /** generation d'un effet **/ - if (firstTime || zf) { - - // generation d'une table de sinus - if (firstTime) { - unsigned short us; - int yofs; - - firstTime = 0; - generatePrecalCoef (); -#ifdef HAVE_MMX - select_zoom_filter (); -#endif - - freebrutS = - (unsigned int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); - brutS = (guint32 *) ((1 + ((uintptr_t) (freebrutS)) / 128) * 128); - - freebrutD = - (unsigned int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); - brutD = (guint32 *) ((1 + ((uintptr_t) (freebrutD)) / 128) * 128); - - freebrutT = - (unsigned int *) calloc (resx * resy * 2 + 128, sizeof(unsigned int)); - brutT = (guint32 *) ((1 + ((uintptr_t) (freebrutT)) / 128) * 128); - - /** modif here by jeko : plus de multiplications **/ - { - int yperte = 0; - - for (y = 0, yofs = 0; y < resy; y++, yofs += resx) { - int xofs = yofs << 1; - int xperte = 0; - - for (x = 0; x < resx; x++) { - brutS[xofs++] = xperte; - brutS[xofs++] = yperte; - xperte += sqrtperte; - } - yperte += sqrtperte; - } - buffratio = 0; - } - - for (us = 0; us < 0xffff; us++) { - sintable[us] = - (int) (1024 * - sin ((double) us * 360 / - (sizeof (sintable) / sizeof (sintable[0]) - - 1) * 3.141592 / 180) + .5); - /* sintable [us] = (int)(1024.0f * sin (us*2*3.31415f/0xffff)) ; */ - } - - { - int loopv; - firedec = (int *) malloc (prevY * sizeof (int)); - - for (loopv = prevY; loopv != 0;) { - static int decc = 0; - static int spdc = 0; - static int accel = 0; - - loopv--; - firedec[loopv] = decc; - decc += spdc / 10; - spdc += RAND () % 3 - RAND () % 3; - - if (decc > 4) - spdc -= 1; - if (decc < -4) - spdc += 1; - - if (spdc > 30) - spdc = spdc - RAND () % 3 + accel / 10; - if (spdc < -30) - spdc = spdc + RAND () % 3 + accel / 10; - - if (decc > 8 && spdc > 1) - spdc -= RAND () % 3 - 2; - - if (decc < -8 && spdc < -1) - spdc += RAND () % 3 + 2; - - if (decc > 8 || decc < -8) - decc = decc * 8 / 9; - - accel += RAND () % 2 - RAND () % 2; - if (accel > 20) - accel -= 2; - if (accel < -20) - accel += 2; - } - } - } - -// buffratio = 0; - interlace_start = 0; - } - // generation du buffer de trans - if (interlace_start==-1) { - //int yprevx = 0; - //unsigned int ax = (prevX - 1) << PERTEDEC, ay = (prevY - 1) << PERTEDEC; - - /* sauvegarde de l'etat actuel dans la nouvelle source */ - -#if 0 - volatile mmx_t ratiox; - - ratiox.d[0] = buffratio; - ratiox.d[1] = buffratio; - movq_m2r (ratiox, mm6); - pslld_i2r (16,mm6); - - y = prevX * prevY; - for (x=0;x>16 format [X|Y] - * modified = mm0,mm1,mm2 - */ - - __asm__ __volatile__ ( - "movq %0,%%mm0\n" - "movq %1,%%mm1\n" - : :"X"(brutSm[x]),"X"(brutDm[x]) - ); /* mm0 = S */ - - psubd_r2r (mm0,mm1); /* mm1 = D - S */ - movq_r2r (mm1, mm2); /* mm2 = D - S */ - - pslld_i2r (16,mm1); - mmx_r2r (pmulhuw, mm6, mm1); /* mm1 = ?? */ - pmullw_r2r (mm6, mm2); - - paddd_r2r (mm2, mm1); /* mm1 = (D - S) * buffratio >> 16 */ - pslld_i2r (16,mm0); - - paddd_r2r (mm1, mm0); /* mm0 = S + mm1 */ - psrld_i2r (16, mm0); - movq_r2m (mm0,brutSm[x]); - } - emms(); -#else - y = prevX * prevY * 2; - for (x = 0; x < y; x += 2) { - int brutSmypos = brutS[x]; - int x2 = x + 1; - - brutS[x] = - brutSmypos + (((brutD[x] - brutSmypos) * buffratio) >> BUFFPOINTNB); - brutSmypos = brutS[x2]; - brutS[x2] = - brutSmypos + - (((brutD[x2] - brutSmypos) * buffratio) >> BUFFPOINTNB); - } -#endif - buffratio = 0; - } - - if (interlace_start==-1) { - signed int * tmp; - //int i,prevXY = prevX*prevY*2; - //for (i=0;i=0) { - * creation de la nouvelle destination * - for (y = interlace_start; y < prevY; y+=INTERLACE_INCR) { - Uint premul_y_prevX = y * prevX * 2; - for (x = 0; x < prevX; x++) { - int px, py; - - // unsigned char coefv,coefh; - - calculatePXandPY (x, y, &px, &py); - - * if (py>ay<<16) - py = iRAND (32); - if (px>ax<<16) - px = iRAND (32); - * - - * - if ((px == x << 4) && (py == y << 4)) { - if (x > middleX) - py += 2; - else - py -= 2; - if (y > middleY) - px += 2; - else - px -= 2; - } - * - - brutT[premul_y_prevX] = px; - brutT[premul_y_prevX + 1] = py; - premul_y_prevX += 2; - } - } - interlace_start += INTERLACE_ADD; - interlace_start &= INTERLACE_AND; - if (interlace_start == 0) - interlace_start = -1; - } -*/ - if (interlace_start>=0) { - int maxEnd = (interlace_start+INTERLACE_INCR); - /* creation de la nouvelle destination */ - for (y = interlace_start; (y < prevY) && (y= prevY-1) interlace_start = -1; - } - - if (switchIncr != 0) { - buffratio += switchIncr; - if (buffratio > BUFFPOINTMASK) - buffratio = BUFFPOINTMASK; - } - - if (switchMult != 1.0f) { - buffratio = - (int) ((float) BUFFPOINTMASK * (1.0f - switchMult) + - (float) buffratio * switchMult); - } - - zoom_width = prevX; - mmx_zoom_size = prevX * prevY; - -#ifdef USE_ASM -#ifdef HAVE_MMX - if (zf_use_xmmx) - zoom_filter_xmmx (prevX, prevY,expix1, expix2, - brutS, brutD, buffratio, precalCoef); - else if (zf_use_mmx) - zoom_filter_mmx (prevX, prevY,expix1, expix2, - brutS, brutD, buffratio, precalCoef); - else c_zoom (expix1, expix2, prevX, prevY, brutS, brutD); -#endif - -#ifdef POWERPC - if (useAltivec) +VisualFX zoomFilterVisualFXWrapper_create() { - ppc_zoom (expix1, expix2, prevX, prevY, brutS, brutD, buffratio,precalCoef); - //c_zoom (expix1, expix2, prevX, prevY, brutS, brutD); - //ppc_zoom_altivec (expix1, expix2, prevX, prevY, brutS, brutD, buffratio,precalCoef); // FIXME:rewrite alitvec -} - else - ppc_zoom (expix1, expix2, prevX, prevY, brutS, brutD, buffratio,precalCoef); -#endif -#else - c_zoom (expix1, expix2, prevX, prevY, brutS, brutD); -#endif + VisualFX fx; + fx.init = zoomFilterVisualFXWrapper_init; + fx.free = zoomFilterVisualFXWrapper_free; + fx.apply = zoomFilterVisualFXWrapper_apply; + return fx; } -void -pointFilter (Uint * pix1, Color c, - float t1, float t2, float t3, float t4, Uint cycle) + +/* TODO : MOVE THIS AWAY */ + +void pointFilter (PluginInfo *goomInfo, Pixel * pix1, Color c, float t1, float t2, float t3, float t4, Uint cycle) { - Uint x = (Uint) ((int) (resolx/2) - + (int) (t1 * cos ((float) cycle / t3))); - Uint y = (Uint) ((int) (c_resoly/2) - + (int) (t2 * sin ((float) cycle / t4))); - - if ((x > 1) && (y > 1) && (x < resolx - 2) && (y < c_resoly - 2)) { - setPixelRGB (pix1, x + 1, y, c); - setPixelRGB (pix1, x, y + 1, c); - setPixelRGB (pix1, x + 1, y + 1, WHITE); - setPixelRGB (pix1, x + 2, y + 1, c); - setPixelRGB (pix1, x + 1, y + 2, c); - } + Uint x = (Uint) ((int) (goomInfo->screen.width / 2) + + (int) (t1 * cos ((float) cycle / t3))); + Uint y = (Uint) ((int) (goomInfo->screen.height/2) + + (int) (t2 * sin ((float) cycle / t4))); + + if ((x > 1) && (y > 1) && (x < goomInfo->screen.width - 2) && (y < goomInfo->screen.height - 2)) { + setPixelRGB (goomInfo, pix1, x + 1, y, c); + setPixelRGB (goomInfo, pix1, x, y + 1, c); + setPixelRGB (goomInfo, pix1, x + 1, y + 1, WHITE); + setPixelRGB (goomInfo, pix1, x + 2, y + 1, c); + setPixelRGB (goomInfo, pix1, x + 1, y + 2, c); + } } diff --git a/src/post/goom/filters.h b/src/post/goom/filters.h deleted file mode 100644 index 2470fdb18..000000000 --- a/src/post/goom/filters.h +++ /dev/null @@ -1,77 +0,0 @@ -#ifndef FILTERS_H -#define FILTERS_H - -#include "goom_config.h" - -#include "graphic.h" -#include "math.h" - -typedef struct -{ - int vitesse; /* 128 = vitesse nule... * * 256 = en arriere * hyper vite.. * * 0 = en avant hype vite. */ - unsigned char pertedec; - unsigned char sqrtperte; - int middleX, middleY; /* milieu de l'effet */ - char reverse; /* inverse la vitesse */ - char mode; /* type d'effet à appliquer (cf les #define) */ /** @since June 2001 */ - int hPlaneEffect; /* deviation horitontale */ - int vPlaneEffect; /* deviation verticale */ /** @since April 2002 */ - int waveEffect; /* applique une "surcouche" de wave effect */ - int hypercosEffect; /* applique une "surcouche de hypercos effect */ - char noisify; /* ajoute un bruit a la transformation */ -} -ZoomFilterData; - - -#define NORMAL_MODE 0 -#define WAVE_MODE 1 -#define CRYSTAL_BALL_MODE 2 -#define SCRUNCH_MODE 3 -#define AMULETTE_MODE 4 -#define WATER_MODE 5 -#define HYPERCOS1_MODE 6 -#define HYPERCOS2_MODE 7 -#define YONLY_MODE 8 -#define SPEEDWAY_MODE 9 - -void pointFilter (Uint * pix1, Color c, - float t1, float t2, float t3, float t4, Uint cycle); - -/* filtre de zoom : - * le contenu de pix1 est copie dans pix2. - * zf : si non NULL, configure l'effet. - * resx,resy : taille des buffers. - */ - -void zoomFilterFastRGB (Uint * pix1, - Uint * pix2, - ZoomFilterData * zf, - Uint resx, Uint resy, - int switchIncr, float switchMult); - - -/* filtre sin : - le contenu de pix1 est copie dans pix2, avec l'effet appliqué - cycle est la variable de temps. - mode vaut SIN_MUL ou SIN_ADD - rate est le pourcentage de l'effet appliqué - lenght : la longueur d'onde (1..10) [5] - speed : la vitesse (1..100) [10] -*/ -/* -void sinFilter(Uint *pix1,Uint *pix2, - Uint cycle, - Uint mode, - Uint rate, - char lenght, - Uint speed); -*/ - -#define SIN_MUL 1 -#define SIN_ADD 2 - -//#ifdef USE_ASM -//void setAsmUse (int useIt); -//#endif - -#endif diff --git a/src/post/goom/flying_stars_fx.c b/src/post/goom/flying_stars_fx.c new file mode 100644 index 000000000..72231e9c8 --- /dev/null +++ b/src/post/goom/flying_stars_fx.c @@ -0,0 +1,280 @@ +#include "goom_fx.h" +#include "goom_plugin_info.h" +#include "goom_tools.h" + +#include "mathtools.h" + +/* TODO:-- FAIRE PROPREMENT */ +#define NCOL 15 +static const int colval[] = { + 0x1416181a, + 0x1419181a, + 0x141f181a, + 0x1426181a, + 0x142a181a, + 0x142f181a, + 0x1436181a, + 0x142f1819, + 0x14261615, + 0x13201411, + 0x111a100a, + 0x0c180508, + 0x08100304, + 0x00050101, + 0x0 +}; + +/* The different modes of the visual FX. + * Put this values on fx_mode */ +#define FIREWORKS_FX 0 +#define RAIN_FX 1 +#define FOUNTAIN_FX 2 +#define LAST_FX 3 + +typedef struct _FS_STAR { + float x,y; + float vx,vy; + float ax,ay; + float age,vage; +} Star; + +typedef struct _FS_DATA{ + + int fx_mode; + int nbStars; + + int maxStars; + Star *stars; + + float min_age; + float max_age; + + PluginParam min_age_p; + PluginParam max_age_p; + PluginParam nbStars_p; + PluginParam nbStars_limit_p; + PluginParam fx_mode_p; + + PluginParameters params; +} FSData; + +static void fs_init(VisualFX *_this) { + + FSData *data; + data = (FSData*)malloc(sizeof(FSData)); + + data->fx_mode = FIREWORKS_FX; + data->maxStars = 4096; + data->stars = (Star*)malloc(data->maxStars * sizeof(Star)); + data->nbStars = 0; + + data->max_age_p = secure_i_param ("Fireworks Smallest Bombs"); + IVAL(data->max_age_p) = 80; + IMIN(data->max_age_p) = 0; + IMAX(data->max_age_p) = 100; + ISTEP(data->max_age_p) = 1; + + data->min_age_p = secure_i_param ("Fireworks Largest Bombs"); + IVAL(data->min_age_p) = 99; + IMIN(data->min_age_p) = 0; + IMAX(data->min_age_p) = 100; + ISTEP(data->min_age_p) = 1; + + data->nbStars_limit_p = secure_i_param ("Max Number of Particules"); + IVAL(data->nbStars_limit_p) = 512; + IMIN(data->nbStars_limit_p) = 0; + IMAX(data->nbStars_limit_p) = data->maxStars; + ISTEP(data->nbStars_limit_p) = 64; + + data->fx_mode_p = secure_i_param ("FX Mode"); + IVAL(data->fx_mode_p) = data->fx_mode; + IMIN(data->fx_mode_p) = 1; + IMAX(data->fx_mode_p) = 3; + ISTEP(data->fx_mode_p) = 1; + + data->nbStars_p = secure_f_feedback ("Number of Particules (% of Max)"); + + data->params = plugin_parameters ("Particule System", 7); + data->params.params[0] = &data->fx_mode_p; + data->params.params[1] = &data->nbStars_limit_p; + data->params.params[2] = 0; + data->params.params[3] = &data->min_age_p; + data->params.params[4] = &data->max_age_p; + data->params.params[5] = 0; + data->params.params[6] = &data->nbStars_p; + + _this->params = &data->params; + _this->fx_data = (void*)data; +} + +static void fs_free(VisualFX *_this) { + free (_this->fx_data); +} + + +/** + * Cree une nouvelle 'bombe', c'est a dire une particule appartenant a une fusee d'artifice. + */ +static void addABomb (FSData *fs, int mx, int my, float radius, float vage, float gravity, PluginInfo *info) { + + int i = fs->nbStars; + float ro; + int theta; + + if (fs->nbStars >= fs->maxStars) + return; + fs->nbStars++; + + fs->stars[i].x = mx; + fs->stars[i].y = my; + + ro = radius * (float)goom_irand(info->gRandom,100) / 100.0f; + ro *= (float)goom_irand(info->gRandom,100)/100.0f + 1.0f; + theta = goom_irand(info->gRandom,256); + + fs->stars[i].vx = ro * cos256[theta]; + fs->stars[i].vy = -0.2f + ro * sin256[theta]; + + fs->stars[i].ax = 0; + fs->stars[i].ay = gravity; + + fs->stars[i].age = 0; + if (vage < fs->min_age) + vage=fs->min_age; + fs->stars[i].vage = vage; +} + + +/** + * Met a jour la position et vitesse d'une particule. + */ +static void updateStar (Star *s) { + s->x+=s->vx; + s->y+=s->vy; + s->vx+=s->ax; + s->vy+=s->ay; + s->age+=s->vage; +} + + +/** + * Ajoute de nouvelles particules au moment d'un evenement sonore. + */ +static void fs_sound_event_occured(VisualFX *_this, PluginInfo *info) { + + FSData *data = (FSData*)_this->fx_data; + int i; + + int max = (int)((1.0f+info->sound.goomPower)*goom_irand(info->gRandom,150)) + 100; + float radius = (1.0f+info->sound.goomPower) * (float)(goom_irand(info->gRandom,150)+50)/300; + int mx = goom_irand(info->gRandom,info->screen.width); + int my; + float vage, gravity = 0.02f; + + switch (data->fx_mode) { + case FIREWORKS_FX: + my = goom_irand(info->gRandom,info->screen.height); + vage = data->max_age * (1.0f - info->sound.goomPower); + break; + case RAIN_FX: + my = -(info->screen.height/3)-goom_irand(info->gRandom,info->screen.width/3); + radius *= 1.5; + vage = 0.002f; + break; + case FOUNTAIN_FX: + my = info->screen.height+2; + vage = 0.001f; + radius += 1.0f; + mx = info->screen.width / 2; + gravity = 0.04f; + break; + default: + return; + /* my = i R A N D (info->screen.height); vage = 0.01f; */ + } + + radius *= info->screen.height / 200.0f; /* why 200 ? because the FX was developped on 320x200 */ + max *= info->screen.height / 200.0f; + + if (info->sound.timeSinceLastBigGoom < 1) { + radius *= 1.5; + max *= 2; + } + for (i=0;ifx_data; + + /* Get the new parameters values */ + data->min_age = 1.0f - (float)IVAL(data->min_age_p)/100.0f; + data->max_age = 1.0f - (float)IVAL(data->max_age_p)/100.0f; + FVAL(data->nbStars_p) = (float)data->nbStars / (float)data->maxStars; + data->nbStars_p.change_listener(&data->nbStars_p); + data->maxStars = IVAL(data->nbStars_limit_p); + data->fx_mode = IVAL(data->fx_mode_p); + + /* look for events */ + if (info->sound.timeSinceLastGoom < 1) { + fs_sound_event_occured(_this, info); + if (goom_irand(info->gRandom,20)==1) { + IVAL(data->fx_mode_p) = goom_irand(info->gRandom,(LAST_FX*3)); + data->fx_mode_p.change_listener(&data->fx_mode_p); + } + } + + /* update particules */ + for (i=0;inbStars;++i) { + updateStar(&data->stars[i]); + + /* dead particule */ + if (data->stars[i].age>=NCOL) + continue; + + /* choose the color of the particule */ + col = colval[(int)data->stars[i].age]; + + /* draws the particule */ + info->methods.draw_line(dest,(int)data->stars[i].x,(int)data->stars[i].y, + (int)(data->stars[i].x-data->stars[i].vx*6), + (int)(data->stars[i].y-data->stars[i].vy*6), + col, + (int)info->screen.width, (int)info->screen.height); + info->methods.draw_line(dest,(int)data->stars[i].x,(int)data->stars[i].y, + (int)(data->stars[i].x-data->stars[i].vx*2), + (int)(data->stars[i].y-data->stars[i].vy*2), + col, + (int)info->screen.width, (int)info->screen.height); + } + + /* look for dead particules */ + for (i=0;inbStars;) { + + if ((data->stars[i].x > info->screen.width + 64) + ||((data->stars[i].vy>=0)&&(data->stars[i].y - 16*data->stars[i].vy > info->screen.height)) + ||(data->stars[i].x < -64) + ||(data->stars[i].age>=NCOL)) { + data->stars[i] = data->stars[data->nbStars-1]; + data->nbStars--; + } + else ++i; + } +} + +VisualFX flying_star_create() { + VisualFX vfx = { + init: fs_init, + free: fs_free, + apply: fs_apply, + fx_data: 0 + }; + return vfx; +} diff --git a/src/post/goom/gfontlib.c b/src/post/goom/gfontlib.c index b2ea0dca2..960ca43b9 100755 --- a/src/post/goom/gfontlib.c +++ b/src/post/goom/gfontlib.c @@ -1,23 +1,26 @@ #include "goom_config.h" -#include "gfontrle.c" +#include "gfontrle.h" +#include "gfontlib.h" #include #include -static int ***font_chars; +static Pixel ***font_chars; static int *font_width; static int *font_height; -static int ***small_font_chars; +static Pixel ***small_font_chars; static int *small_font_width; static int *small_font_height; -void gfont_load (void) { +void gfont_load () { unsigned char *gfont; unsigned int i = 0, j = 0; unsigned int nba = 0; unsigned int current = 32; int *font_pos; - // decompress le rle + /* decompress le rle */ + + gfont = malloc (the_font.width*the_font.height*the_font.bytes_per_pixel); while (i>2)<<(ROUGE*8))| (((g1 + g2 + g3 + g4)>>2)<<(VERT*8))| (((b1 + b2 + b3 + b4)>>2)<<(BLEU*8))| @@ -105,7 +108,7 @@ void gfont_load (void) { } } - // definir les lettres restantes + /* definir les lettres restantes */ for (i=0;i<256;i++) { if (font_chars[i]==0) { @@ -125,26 +128,26 @@ void gfont_load (void) { small_font_chars [32] = 0; } -void goom_draw_text (guint32 * buf,int resolx,int resoly, +void goom_draw_text (Pixel * buf,int resolx,int resoly, int x, int y, const char *str, float charspace, int center) { float fx = (float) x; int fin = 0; - int ***cur_font_chars; + Pixel ***cur_font_chars; int *cur_font_width; int *cur_font_height; if (resolx>320) { - //printf("use big\n"); + /* printf("use big\n"); */ cur_font_chars = font_chars; cur_font_width = font_width; cur_font_height = font_height; } else { - //printf ("use small\n"); + /* printf ("use small\n"); */ cur_font_chars = small_font_chars; cur_font_width = small_font_width; cur_font_height = small_font_height; @@ -198,26 +201,26 @@ void goom_draw_text (guint32 * buf,int resolx,int resoly, if (ymax >= (int) resoly - 1) ymax = resoly - 1; - for (; yy < ymax; yy++) - for (xx = xmin; xx < xmax; xx++) - { - unsigned int color = cur_font_chars[c][yy - ymin][xx - x]; - unsigned int transparency = color & 0xff000000; - if (transparency) - { - if (transparency==0xff000000) buf[yy * resolx + xx] = color; - else - { - unsigned int back = buf[yy * resolx + xx]; - unsigned int a1 = (color & 0xff000000) >> 24; - unsigned int a2 = 255 - a1; - buf[yy * resolx + xx] = - (((((color & 0x00ff0000) * a1) + ((back & 0x00ff0000) * a2)) & 0xff000000) >> 8) | - (((((color & 0x0000ff00) * a1) + ((back & 0x0000ff00) * a2)) & 0x00ff0000) >> 8) | - ((((color & 0x000000ff) * a1) + ((back & 0x000000ff) * a2)) >> 8); - } - } - } + for (; yy < ymax; yy++) + for (xx = xmin; xx < xmax; xx++) + { + Pixel color = cur_font_chars[c][yy - ymin][xx - x]; + Pixel transparency; + transparency.val = color.val & A_CHANNEL; + if (transparency.val) + { + if (transparency.val==A_CHANNEL) buf[yy * resolx + xx] = color; + else + { + Pixel back = buf[yy * resolx + xx]; + unsigned int a1 = color.channels.a; + unsigned int a2 = 255 - a1; + buf[yy * resolx + xx].channels.r = (unsigned char)((((unsigned int)color.channels.r * a1) + ((unsigned int)back.channels.r * a2)) >> 8); + buf[yy * resolx + xx].channels.g = (unsigned char)((((unsigned int)color.channels.g * a1) + ((unsigned int)back.channels.g * a2)) >> 8); + buf[yy * resolx + xx].channels.b = (unsigned char)((((unsigned int)color.channels.b * a1) + ((unsigned int)back.channels.b * a2)) >> 8); + } + } + } } fx += cur_font_width[c] + charspace; } diff --git a/src/post/goom/gfontlib.h b/src/post/goom/gfontlib.h index fe56024b8..f5b82917b 100755 --- a/src/post/goom/gfontlib.h +++ b/src/post/goom/gfontlib.h @@ -1,9 +1,10 @@ #ifndef _GFONTLIB_H #define _GFONTLIB_H -void gfont_load (void); -void goom_draw_text (guint32 * buf,int resolx,int resoly, - int x, int y, - const char *str, float chspace, int center); +#include "goom_graphic.h" + +void gfont_load (); +void goom_draw_text (Pixel * buf,int resolx,int resoly, int x, int y, + const char *str, float chspace, int center); #endif diff --git a/src/post/goom/gfontrle.c b/src/post/goom/gfontrle.c index 69c4afba5..8a4b32cd0 100755 --- a/src/post/goom/gfontrle.c +++ b/src/post/goom/gfontrle.c @@ -1,5 +1,6 @@ /* RGBA C-Source image dump (with zRLE compression) */ -static const struct { + +const struct { unsigned int width; unsigned int height; unsigned int bytes_per_pixel; diff --git a/src/post/goom/gfontrle.h b/src/post/goom/gfontrle.h new file mode 100644 index 000000000..41e2462fd --- /dev/null +++ b/src/post/goom/gfontrle.h @@ -0,0 +1,7 @@ +extern const struct { + unsigned int width; + unsigned int height; + unsigned int bytes_per_pixel; + unsigned int rle_size; + unsigned char rle_pixel [49725]; +} the_font ; diff --git a/src/post/goom/goom.h b/src/post/goom/goom.h new file mode 100644 index 000000000..bc0a88623 --- /dev/null +++ b/src/post/goom/goom.h @@ -0,0 +1,27 @@ +#ifndef _GOOMCORE_H +#define _GOOMCORE_H + +#include "goom_config.h" +#include "goom_plugin_info.h" +#include "goom_script.h" + +#define NB_FX 10 + +PluginInfo *goom_init (guint32 resx, guint32 resy); +void goom_set_resolution (PluginInfo *goomInfo, guint32 resx, guint32 resy); + +/* + * forceMode == 0 : do nothing + * forceMode == -1 : lock the FX + * forceMode == 1..NB_FX : force a switch to FX n# forceMode + * + * songTitle = pointer to the title of the song... + * - NULL if it is not the start of the song + * - only have a value at the start of the song + */ +guint32 *goom_update (PluginInfo *goomInfo, gint16 data[2][512], int forceMode, float fps, + char *songTitle, char *message); + +void goom_close (PluginInfo *goomInfo); + +#endif diff --git a/src/post/goom/goom_config.h b/src/post/goom/goom_config.h index ce7b24a7f..3c9b2c2c8 100644 --- a/src/post/goom/goom_config.h +++ b/src/post/goom/goom_config.h @@ -1,14 +1,9 @@ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -/* #define VERSION "1.9dev5" */ -/* #define _DEBUG */ +//#define VERSION "1.9.2" +//#define _DEBUG #define COLOR_BGRA -/* #define COLOR_ARGB */ +//#define COLOR_ARGB #ifdef COLOR_BGRA /** position des composantes **/ @@ -24,30 +19,21 @@ #endif -/* target */ -#define XMMS_PLUGIN -/* #define STANDALONE */ +// target +//#define XMMS_PLUGIN +#define STANDALONE -/* for pc users with mmx processors. */ -#if 0 -#ifdef ARCH_X86 -#define HAVE_MMX -#endif -#endif +//#define POWERPC -#ifdef ARCH_PPC -/* -#define POWERPC -*/ -#endif +#define HAVE_ATHLON -/* #define VERBOSE */ +//#define VERBOSE #ifndef guint32 -#define guint8 uint8_t -#define guin16 uint16_t -#define guint32 uint32_t -#define gint8 int8_t -#define gint16 int16_t -#define gint32 int32_t +#define guint8 unsigned char +#define guin16 unsigned short +#define guint32 unsigned int +#define gint8 signed char +#define gint16 signed short int +#define gint32 signed int #endif diff --git a/src/post/goom/goom_config_param.h b/src/post/goom/goom_config_param.h new file mode 100644 index 000000000..bd8753e7e --- /dev/null +++ b/src/post/goom/goom_config_param.h @@ -0,0 +1,106 @@ +#ifndef _GOOM_CONFIG_PARAM_H +#define _GOOM_CONFIG_PARAM_H + +#include + +/** + * File created on 2003-05-24 by Jeko. + * (c)2003, JC Hoelt for iOS-software. + * + * LGPL Licence. + */ + +typedef enum { + PARAM_INTVAL, + PARAM_FLOATVAL, + PARAM_BOOLVAL, + PARAM_STRVAL, + PARAM_LISTVAL, +} ParamType; + +struct IntVal { + int value; + int min; + int max; + int step; +}; +struct FloatVal { + float value; + float min; + float max; + float step; +}; +struct StrVal { + char *value; +}; +struct ListVal { + char *value; + int nbChoices; + char **choices; +}; +struct BoolVal { + int value; +}; + + +typedef struct _PARAM { + char *name; + char *desc; + char rw; + ParamType type; + union { + struct IntVal ival; + struct FloatVal fval; + struct StrVal sval; + struct ListVal slist; + struct BoolVal bval; + } param; + + /* used by the core to inform the GUI of a change */ + void (*change_listener)(struct _PARAM *_this); + + /* used by the GUI to inform the core of a change */ + void (*changed)(struct _PARAM *_this); + + void *user_data; /* can be used by the GUI */ +} PluginParam; + +#define IVAL(p) ((p).param.ival.value) +#define SVAL(p) ((p).param.sval.value) +#define FVAL(p) ((p).param.fval.value) +#define BVAL(p) ((p).param.bval.value) +#define LVAL(p) ((p).param.slist.value) + +#define FMIN(p) ((p).param.fval.min) +#define FMAX(p) ((p).param.fval.max) +#define FSTEP(p) ((p).param.fval.step) + +#define IMIN(p) ((p).param.ival.min) +#define IMAX(p) ((p).param.ival.max) +#define ISTEP(p) ((p).param.ival.step) + +void empty_fct(); + +PluginParam secure_param(); + +PluginParam secure_f_param(char *name); +PluginParam secure_i_param(char *name); +PluginParam secure_b_param(char *name, int value); +PluginParam secure_s_param(char *name); + +PluginParam secure_f_feedback(char *name); +PluginParam secure_i_feedback(char *name); + +void set_str_param_value(PluginParam *p, const char *str); +void set_list_param_value(PluginParam *p, const char *str); + +typedef struct _PARAMETERS { + char *name; + char *desc; + int nbParams; + PluginParam **params; +} PluginParameters; + +PluginParameters plugin_parameters(const char *name, int nb); + +#endif diff --git a/src/post/goom/goom_core.c b/src/post/goom/goom_core.c index 1cda9f744..b933dd742 100644 --- a/src/post/goom/goom_core.c +++ b/src/post/goom/goom_core.c @@ -1,1078 +1,880 @@ -#include +/** +* file: goom_core.c + * author: Jean-Christophe Hoelt (which is not so proud of it) + * + * Contains the core of goom's work. + * + * (c)2000-2003, by iOS-software. + */ + +#include #include +#include #include +#include -#if HAVE_INTTYPES_H -# include -#else -# if HAVE_STDINT_H -# include -# endif -#endif - -#include "goom_core.h" +#include "goom.h" #include "goom_tools.h" -#include "filters.h" +#include "goom_filters.h" #include "lines.h" #include "ifs.h" #include "tentacle3d.h" #include "gfontlib.h" -//#define VERBOSE +#include "sound_tester.h" +#include "goom_plugin_info.h" +#include "goom_fx.h" +#include "goom_script.h" -#ifdef VERBOSE -#include -#endif +/* #define VERBOSE */ #define STOP_SPEED 128 - +/* TODO: put that as variable in PluginInfo */ #define TIME_BTW_CHG 300 -/**-----------------------------------------------------** - ** SHARED DATA ** - **-----------------------------------------------------**/ -static guint32 *pixel; -static guint32 *back; -static guint32 *p1, *p2, *tmp; -static guint32 cycle; - -typedef struct { - int drawIFS; - int drawPoints; - int drawTentacle; - - int drawScope; - int farScope; +static void choose_a_goom_line (PluginInfo *goomInfo, float *param1, float *param2, int *couleur, + int *mode, float *amplitude, int far); - int rangemin; - int rangemax; -} GoomState; - -#define STATES_NB 8 -#define STATES_RANGEMAX 510 -GoomState states[STATES_NB] = { - {1,0,0,1,4, 000, 100}, - {1,0,0,0,1, 101, 140}, - {1,0,0,1,2, 141, 200}, - {0,1,0,1,2, 201, 260}, - {0,1,0,1,0, 261, 330}, - {0,1,1,1,4, 331, 400}, - {0,0,1,0,5, 401, 450}, - {0,0,1,1,1, 451, 510} -}; - -GoomState *curGState = states+4; - - -guint32 resolx, resoly, buffsize, c_black_height = 0, /* hauteur des bande * - * * noires en bas et * - * * en * haut */ - c_offset = 0, c_resoly = 0; /* avec prise en compte de ca */ - -// effet de ligne.. -static GMLine *gmline1 = NULL; -static GMLine *gmline2 = NULL; - -void choose_a_goom_line (float *param1, float *param2, int *couleur, - int *mode, float *amplitude, int farparm); - -// la police -//int ***font_chars; -//int *font_width; -//int *font_height; - -//void goom_draw_text (guint32 * buf, -// int x, int y, -// const char *str, float chspace, int center); - -void update_message (char *message); +static void update_message (PluginInfo *goomInfo, char *message); +static void init_buffers(PluginInfo *goomInfo, int buffsize) +{ + goomInfo->pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); + bzero (goomInfo->pixel, buffsize * sizeof (guint32) + 128); + goomInfo->back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); + bzero (goomInfo->back, buffsize * sizeof (guint32) + 128); + goomInfo->conv = (Pixel *) malloc (buffsize * sizeof (guint32) + 128); + bzero (goomInfo->conv, buffsize * sizeof (guint32) + 128); + + goomInfo->p1 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->pixel)) / 128) * 128); + goomInfo->p2 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->back)) / 128) * 128); +} -void -goom_init (guint32 resx, guint32 resy, int cinemascope) +/************************** +* INIT * +**************************/ +PluginInfo *goom_init (guint32 resx, guint32 resy) { + PluginInfo *goomInfo = (PluginInfo*)malloc(sizeof(PluginInfo)); + #ifdef VERBOSE - printf ("GOOM: init (%d, %d);\n", resx, resy); + printf ("GOOM: init (%d, %d);\n", resx, resy); #endif - if (cinemascope) - c_black_height = resy / 5; - else - c_black_height = 0; - - resolx = resx; - resoly = resy; - buffsize = resx * resy; - - c_offset = c_black_height * resx; - c_resoly = resy - c_black_height * 2; - - pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); - back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); - //RAND_INIT (); - srand ((guint32) pixel); - if (!rand_tab) rand_tab = (int *) malloc (NB_RAND * sizeof(int)) ; - rand_pos = 1 ; - while (rand_pos != 0) rand_tab [rand_pos++] = rand () ; - - cycle = 0; - - p1 = (guint32 *) ((1 + ((uintptr_t) (pixel)) / 128) * 128); - p2 = (guint32 *) ((1 + ((uintptr_t) (back)) / 128) * 128); - - init_ifs (resx, c_resoly); - gmline1 = goom_lines_init (resx, c_resoly, - GML_HLINE, c_resoly, GML_BLACK, - GML_CIRCLE, 0.4f * (float) c_resoly, GML_VERT); - gmline2 = goom_lines_init (resx, c_resoly, - GML_HLINE, 0, GML_BLACK, - GML_CIRCLE, 0.2f * (float) c_resoly, GML_RED); - -// font_height = NULL; -// font_width = NULL; -// font_chars = NULL; - gfont_load (); - - tentacle_new (); + + plugin_info_init(goomInfo,4); + + goomInfo->star_fx = flying_star_create(); + goomInfo->star_fx.init(&goomInfo->star_fx); + + goomInfo->zoomFilter_fx = zoomFilterVisualFXWrapper_create (); + goomInfo->zoomFilter_fx.init(&goomInfo->zoomFilter_fx); + + goomInfo->tentacles_fx = tentacle_fx_create(); + goomInfo->tentacles_fx.init(&goomInfo->tentacles_fx); + + goomInfo->convolve_fx = convolve_create(); + goomInfo->convolve_fx.init(&goomInfo->convolve_fx); + + plugin_info_add_visual (goomInfo, 0, &goomInfo->zoomFilter_fx); + plugin_info_add_visual (goomInfo, 1, &goomInfo->tentacles_fx); + plugin_info_add_visual (goomInfo, 2, &goomInfo->star_fx); + plugin_info_add_visual (goomInfo, 3, &goomInfo->convolve_fx); + + goomInfo->screen.width = resx; + goomInfo->screen.height = resy; + goomInfo->screen.size = resx * resy; + + init_buffers(goomInfo, goomInfo->screen.size); + goomInfo->gRandom = goom_random_init((uintptr_t)goomInfo->pixel); + + goomInfo->cycle = 0; + + goomInfo->ifs_fx = ifs_visualfx_create(); + goomInfo->ifs_fx.init(&goomInfo->ifs_fx); + + goomInfo->gmline1 = goom_lines_init (goomInfo, resx, goomInfo->screen.height, + GML_HLINE, goomInfo->screen.height, GML_BLACK, + GML_CIRCLE, 0.4f * (float) goomInfo->screen.height, GML_VERT); + goomInfo->gmline2 = goom_lines_init (goomInfo, resx, goomInfo->screen.height, + GML_HLINE, 0, GML_BLACK, + GML_CIRCLE, 0.2f * (float) goomInfo->screen.height, GML_RED); + + gfont_load (); + + goom_set_main_script(goomInfo, goomInfo->main_script_str); + + return goomInfo; } -void -goom_set_resolution (guint32 resx, guint32 resy, int cinemascope) +void goom_set_resolution (PluginInfo *goomInfo, guint32 resx, guint32 resy) { - free (pixel); - free (back); - - if (cinemascope) - c_black_height = resy / 8; - else - c_black_height = 0; - - c_offset = c_black_height * resx; - c_resoly = resy - c_black_height * 2; - - resolx = resx; - resoly = resy; - buffsize = resx * resy; - - pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); - bzero (pixel, buffsize * sizeof (guint32) + 128); - back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); - bzero (back, buffsize * sizeof (guint32) + 128); - p1 = (guint32 *) ((1 + ((uintptr_t) (pixel)) / 128) * 128); - p2 = (guint32 *) ((1 + ((uintptr_t) (back)) / 128) * 128); - - init_ifs (resx, c_resoly); - goom_lines_set_res (gmline1, resx, c_resoly); - goom_lines_set_res (gmline2, resx, c_resoly); + free (goomInfo->pixel); + free (goomInfo->back); + free (goomInfo->conv); + + goomInfo->screen.width = resx; + goomInfo->screen.height = resy; + goomInfo->screen.size = resx * resy; + + init_buffers(goomInfo, goomInfo->screen.size); + + /* init_ifs (goomInfo, resx, goomInfo->screen.height); */ + goomInfo->ifs_fx.free(&goomInfo->ifs_fx); + goomInfo->ifs_fx.init(&goomInfo->ifs_fx); + + goom_lines_set_res (goomInfo->gmline1, resx, goomInfo->screen.height); + goom_lines_set_res (goomInfo->gmline2, resx, goomInfo->screen.height); } +/******************************************** +* UPDATE * +******************************************** - -guint32 * goom_update (gint16 data[2][512], - int forceMode, - float fps, - char *songTitle, - char *message) -{ - static int lockvar = 0; // pour empecher de nouveaux changements - static int goomvar = 0; // boucle des gooms - static int totalgoom = 0; // nombre de gooms par seconds - static int agoom = 0; // un goom a eu lieu.. - static int abiggoom = 0; // un big goom a eu lieu.. - static int loopvar = 0; // mouvement des points - static int speedvar = 0; // vitesse des particules - - // duree de la transition entre afficher les lignes ou pas -#define DRAWLINES 80 - static int lineMode = DRAWLINES; // l'effet lineaire a dessiner - static int nombreCDDC = 0; // nombre de Cycle Depuis Dernier Changement - guint32 *return_val; - guint32 pointWidth; - guint32 pointHeight; - int incvar; // volume du son - static int accelvar=0; // acceleration des particules - int i; - float largfactor; // elargissement de l'intervalle d'évolution - static int stop_lines = 0; - - // des points - - static int ifs_incr = 1; // dessiner l'ifs (0 = non: > = increment) - static int decay_ifs = 0; // disparition de l'ifs - static int recay_ifs = 0; // dédisparition de l'ifs - -#define SWITCHMULT (29.0f/30.0f) -#define SWITCHINCR 0x7f - static float switchMult = 1.0f; - static int switchIncr = SWITCHINCR; - -// static int lastgoom = 0; - - static char goomlimit = 2; // sensibilité du goom - static ZoomFilterData zfd = { - 127, 8, 16, - 1, 1, 0, NORMAL_MODE, - 0, 0, 0, 0, 0 - }; - - ZoomFilterData *pzfd; - - /* test if the config has changed, update it if so */ - pointWidth = (resolx * 2) / 5; - pointHeight = ((c_resoly) * 2) / 5; - - /* ! etude du signal ... */ - incvar = 0; - for (i = 0; i < 512; i++) { - if (incvar < data[0][i]) - incvar = data[0][i]; - } - - i = accelvar; - accelvar = incvar / 1000; - - if (speedvar > 5) { - accelvar--; - if (speedvar > 20) - accelvar--; - if (speedvar > 40) - speedvar = 40; - } - accelvar--; - - i = accelvar - i; - if (i<0) i=-i; - - speedvar += (speedvar + i/2); - speedvar /= 2; - if ((speedvar) && (cycle%9==0)) { - speedvar -= 1; - } - if ((speedvar) && (cycle%5==0)) { - speedvar = (speedvar*7)/8; - } - - if (speedvar < 0) - speedvar = 0; - if (speedvar > 50) - speedvar = 50; - - - /* ! calcul du deplacement des petits points ... */ - - largfactor = ((float) speedvar / 40.0f + (float) incvar / 50000.0f) / 1.5f; - if (largfactor > 1.5f) - largfactor = 1.5f; - -/* - if ((ifs_incr == 1) && (iRAND (300) == 0) && (decay_ifs < -300) && (agoom)) { - decay_ifs = 200; - } +* WARNING: this is a 600 lines function ! (21-11-2003) */ - - decay_ifs--; - if (decay_ifs > 0) - ifs_incr += 2; - if (decay_ifs == 0) - ifs_incr = 0; - -/* - if ((ifs_incr == 0) && (iRAND (300) == 0) && (agoom) && (decay_ifs < -100)) { - recay_ifs = 5; - ifs_incr = 11; - if (iRAND(2)) - stop_lines = 0xf000 & 5; - } -*/ - - if (recay_ifs) { - ifs_incr -= 2; - recay_ifs--; - if ((recay_ifs == 0)&&(ifs_incr<=0)) - ifs_incr = 1; - } - - if (ifs_incr > 0) - ifs_update (p1 + c_offset, p2 + c_offset, resolx, c_resoly, ifs_incr); - - if (curGState->drawPoints) { - for (i = 1; i * 15 <= speedvar + 15; i++) { - loopvar += speedvar*2/3 + 1; - - pointFilter (p1 + c_offset, - YELLOW, - ((pointWidth - 6.0f) * largfactor + 5.0f), - ((pointHeight - 6.0f) * largfactor + 5.0f), - i * 152.0f, 128.0f, loopvar + i * 2032); - pointFilter (p1 + c_offset, ORANGE, - ((pointWidth / 2) * largfactor) / i + 10.0f * i, - ((pointHeight / 2) * largfactor) / i + 10.0f * i, - 96.0f, i * 80.0f, loopvar / i); - pointFilter (p1 + c_offset, VIOLET, - ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i, - ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i, - i + 122.0f, 134.0f, loopvar / i); - pointFilter (p1 + c_offset, BLACK, - ((pointHeight / 3) * largfactor + 20.0f), - ((pointHeight / 3) * largfactor + 20.0f), - 58.0f, i * 66.0f, loopvar / i); - pointFilter (p1 + c_offset, WHITE, - (pointHeight * largfactor + 10.0f * i) / i, - (pointHeight * largfactor + 10.0f * i) / i, - 66.0f, 74.0f, loopvar + i * 500); - } - } - - // par défaut pas de changement de zoom - pzfd = NULL; - - /* - * Test forceMode - */ +guint32 *goom_update (PluginInfo *goomInfo, gint16 data[2][512], + int forceMode, float fps, char *songTitle, char *message) +{ + Pixel *return_val; + guint32 pointWidth; + guint32 pointHeight; + int i; + float largfactor; /* elargissement de l'intervalle d'évolution des points */ + Pixel *tmp; + + ZoomFilterData *pzfd; + + /* test if the config has changed, update it if so */ + pointWidth = (goomInfo->screen.width * 2) / 5; + pointHeight = ((goomInfo->screen.height) * 2) / 5; + + /* ! etude du signal ... */ + evaluate_sound (data, &(goomInfo->sound)); + + goom_execute_main_script(goomInfo); + + /* ! calcul du deplacement des petits points ... */ + largfactor = goomInfo->sound.speedvar / 150.0f + goomInfo->sound.volume / 1.5f; + + if (largfactor > 1.5f) + largfactor = 1.5f; + + goomInfo->update.decay_ifs--; + if (goomInfo->update.decay_ifs > 0) + goomInfo->update.ifs_incr += 2; + if (goomInfo->update.decay_ifs == 0) + goomInfo->update.ifs_incr = 0; + + if (goomInfo->update.recay_ifs) { + goomInfo->update.ifs_incr -= 2; + goomInfo->update.recay_ifs--; + if ((goomInfo->update.recay_ifs == 0)&&(goomInfo->update.ifs_incr<=0)) + goomInfo->update.ifs_incr = 1; + } + + if (goomInfo->update.ifs_incr > 0) + goomInfo->ifs_fx.apply(&goomInfo->ifs_fx, goomInfo->p2, goomInfo->p1, goomInfo); + + if (goomInfo->curGState->drawPoints) { + for (i = 1; i * 15 <= goomInfo->sound.speedvar*80.0f + 15; i++) { + goomInfo->update.loopvar += goomInfo->sound.speedvar*50 + 1; + + pointFilter (goomInfo, goomInfo->p1, + YELLOW, + ((pointWidth - 6.0f) * largfactor + 5.0f), + ((pointHeight - 6.0f) * largfactor + 5.0f), + i * 152.0f, 128.0f, goomInfo->update.loopvar + i * 2032); + pointFilter (goomInfo, goomInfo->p1, ORANGE, + ((pointWidth / 2) * largfactor) / i + 10.0f * i, + ((pointHeight / 2) * largfactor) / i + 10.0f * i, + 96.0f, i * 80.0f, goomInfo->update.loopvar / i); + pointFilter (goomInfo, goomInfo->p1, VIOLET, + ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i, + ((pointHeight / 3 + 5.0f) * largfactor) / i + 10.0f * i, + i + 122.0f, 134.0f, goomInfo->update.loopvar / i); + pointFilter (goomInfo, goomInfo->p1, BLACK, + ((pointHeight / 3) * largfactor + 20.0f), + ((pointHeight / 3) * largfactor + 20.0f), + 58.0f, i * 66.0f, goomInfo->update.loopvar / i); + pointFilter (goomInfo, goomInfo->p1, WHITE, + (pointHeight * largfactor + 10.0f * i) / i, + (pointHeight * largfactor + 10.0f * i) / i, + 66.0f, 74.0f, goomInfo->update.loopvar + i * 500); + } + } + + /* par défaut pas de changement de zoom */ + pzfd = NULL; + + /* + * Test forceMode + */ #ifdef VERBOSE - if (forceMode != 0) { - printf ("forcemode = %d\n", forceMode); - } + if (forceMode != 0) { + printf ("forcemode = %d\n", forceMode); + } #endif - - - // diminuer de 1 le temps de lockage - // note pour ceux qui n'ont pas suivis : le lockvar permet d'empecher un - // changement d'etat du plugins juste apres un autre changement d'etat. oki - // - // ? - if (--lockvar < 0) - lockvar = 0; - - // temps du goom - if (--agoom < 0) - agoom = 0; - - // temps du goom - if (--abiggoom < 0) - abiggoom = 0; - - if ((!abiggoom) && (speedvar > 4) && (goomlimit > 4) && - ((accelvar > goomlimit*9/8+7)||(accelvar < -goomlimit*9/8-7))) { - int size,i; - static int couleur = - (0xc0<<(ROUGE*8)) - |(0xc0<<(VERT*8)) - |(0xf0<<(BLEU*8)) - |(0xf0<<(ALPHA*8)); - abiggoom = 100; - size = resolx*c_resoly; - for (i=0;i goomlimit) || (accelvar < -goomlimit) || (forceMode > 0) - || (nombreCDDC > TIME_BTW_CHG)) { - -// if (nombreCDDC > 300) { -// } - - // UN GOOM !!! YAHOO ! - totalgoom++; - agoom = 20; // mais pdt 20 cycles, il n'y en aura plus. - // lineMode = (lineMode + 1)%40; // Tous les 10 gooms on change de mode - // lineaire - - // if (iRAND(12) == 0) - // zfd.vitesse=STOP_SPEED-1; - // if (iRAND(13) == 0) - // zfd.vitesse=STOP_SPEED+1; - - // changement eventuel de mode - if (iRAND(16) == 0) - switch (iRAND (32)) { - case 0: - case 10: - zfd.hypercosEffect = iRAND (2); - case 13: - case 20: - case 21: - zfd.mode = WAVE_MODE; - zfd.reverse = 0; - zfd.waveEffect = (iRAND (3) == 0); - if (iRAND (2)) - zfd.vitesse = (zfd.vitesse + 127) >> 1; - break; - case 1: - case 11: - zfd.mode = CRYSTAL_BALL_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - break; - case 2: - case 12: - zfd.mode = AMULETTE_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - break; - case 3: - zfd.mode = WATER_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - break; - case 4: - case 14: - zfd.mode = SCRUNCH_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - break; - case 5: - case 15: - case 22: - zfd.mode = HYPERCOS1_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = (iRAND (3) == 0); - break; - case 6: - case 16: - zfd.mode = HYPERCOS2_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - break; - case 7: - case 17: - zfd.mode = CRYSTAL_BALL_MODE; - zfd.waveEffect = (iRAND (4) == 0); - zfd.hypercosEffect = iRAND (2); - break; - case 8: - case 18: - case 19: - zfd.mode = SCRUNCH_MODE; - zfd.waveEffect = 1; - zfd.hypercosEffect = 1; - break; - case 29: - case 30: - zfd.mode = YONLY_MODE; - break; - case 31: - case 32: - zfd.mode = SPEEDWAY_MODE; - break; - default: - zfd.mode = NORMAL_MODE; - zfd.waveEffect = 0; - zfd.hypercosEffect = 0; - } - } - - // tout ceci ne sera fait qu'en cas de non-blocage - if (lockvar == 0) { - // reperage de goom (acceleration forte de l'acceleration du volume) - // -> coup de boost de la vitesse si besoin.. - if ((accelvar > goomlimit) || (accelvar < -goomlimit)) { - static int rndn = 0 ,i; - static int blocker = 0; - goomvar++; - - /* SELECTION OF THE GOOM STATE */ - if ((!blocker)&&(iRAND(3))) { - rndn = iRAND(STATES_RANGEMAX); - blocker = 3; - } - else if (blocker) blocker--; - - for (i=0;i= states[i].rangemin) - && (rndn <= states[i].rangemax)) - curGState = states+i; - - if ((curGState->drawIFS) && (ifs_incr<=0)) { - recay_ifs = 5; - ifs_incr = 11; - } - - if ((!curGState->drawIFS) && (ifs_incr>0) && (decay_ifs<=0)) - decay_ifs = 100; - - if (!curGState->drawScope) - stop_lines = 0xf000 & 5; - - if (!curGState->drawScope) { - stop_lines = 0; - lineMode = DRAWLINES; - } - - // if (goomvar % 1 == 0) - { - guint32 vtmp; - guint32 newvit; - - lockvar = 50; - newvit = STOP_SPEED + 1 - ((float)4.0f * log10(speedvar+1)); - // retablir le zoom avant.. - if ((zfd.reverse) && (!(cycle % 13)) && (rand () % 5 == 0)) { - zfd.reverse = 0; - zfd.vitesse = STOP_SPEED - 2; - lockvar = 75; - } - if (iRAND (10) == 0) { - zfd.reverse = 1; - lockvar = 100; - } - - if (iRAND (10) == 0) - zfd.vitesse = STOP_SPEED - 1; - if (iRAND (12) == 0) - zfd.vitesse = STOP_SPEED + 1; - - // changement de milieu.. - switch (iRAND (25)) { - case 0: - case 3: - case 6: - zfd.middleY = c_resoly - 1; - zfd.middleX = resolx / 2; - break; - case 1: - case 4: - zfd.middleX = resolx - 1; - break; - case 2: - case 5: - zfd.middleX = 1; - break; - default: - zfd.middleY = c_resoly / 2; - zfd.middleX = resolx / 2; - } - - if ((zfd.mode == WATER_MODE) - || (zfd.mode == YONLY_MODE) - || (zfd.mode == AMULETTE_MODE)) { - zfd.middleX = resolx / 2; - zfd.middleY = c_resoly / 2; - } - - switch (vtmp = (iRAND (15))) { - case 0: - - zfd.vPlaneEffect = iRAND (3) - iRAND (3); - zfd.hPlaneEffect = iRAND (3) - iRAND (3); - break; - case 3: - zfd.vPlaneEffect = 0; - zfd.hPlaneEffect = iRAND (8) - iRAND (8); - break; - case 4: - case 5: - case 6: - case 7: - zfd.vPlaneEffect = iRAND (5) - iRAND (5); - zfd.hPlaneEffect = -zfd.vPlaneEffect; - break; - case 8: - zfd.hPlaneEffect = 5 + iRAND (8); - zfd.vPlaneEffect = -zfd.hPlaneEffect; - break; - case 9: - zfd.vPlaneEffect = 5 + iRAND (8); - zfd.hPlaneEffect = -zfd.hPlaneEffect; - break; - case 13: - zfd.hPlaneEffect = 0; - zfd.vPlaneEffect = iRAND (10) - iRAND (10); - break; - case 14: - zfd.hPlaneEffect = iRAND (10) - iRAND (10); - zfd.vPlaneEffect = iRAND (10) - iRAND (10); - break; - default: - if (vtmp < 10) { - zfd.vPlaneEffect = 0; - zfd.hPlaneEffect = 0; - } - } - - if (iRAND (5) != 0) - zfd.noisify = 0; - else { - zfd.noisify = iRAND (2) + 1; - lockvar *= 2; - } - - if (zfd.mode == AMULETTE_MODE) { - zfd.vPlaneEffect = 0; - zfd.hPlaneEffect = 0; - zfd.noisify = 0; - } - - if ((zfd.middleX == 1) || (zfd.middleX == resolx - 1)) { - zfd.vPlaneEffect = 0; - zfd.hPlaneEffect = iRAND (2) ? 0 : zfd.hPlaneEffect; - } - - if (newvit < zfd.vitesse) // on accelere - { - pzfd = &zfd; - if (((newvit < STOP_SPEED - 7) && - (zfd.vitesse < STOP_SPEED - 6) && - (cycle % 3 == 0)) || (iRAND (40) == 0)) { - zfd.vitesse = STOP_SPEED - iRAND (2) + iRAND (2); - zfd.reverse = !zfd.reverse; - } - else { - zfd.vitesse = (newvit + zfd.vitesse * 7) / 8; - } - lockvar += 50; - } - } - - if (lockvar > 150) { - switchIncr = SWITCHINCR; - switchMult = 1.0f; - } - } - // mode mega-lent - if (iRAND (700) == 0) { - /* - * printf ("coup du sort...\n") ; - */ - pzfd = &zfd; - zfd.vitesse = STOP_SPEED - 1; - zfd.pertedec = 8; - zfd.sqrtperte = 16; - goomvar = 1; - lockvar += 50; - switchIncr = SWITCHINCR; - switchMult = 1.0f; - } - } - - /* - * gros frein si la musique est calme - */ - if ((speedvar < 1) && (zfd.vitesse < STOP_SPEED - 4) && (cycle % 16 == 0)) { - pzfd = &zfd; - zfd.vitesse += 3; - zfd.pertedec = 8; - zfd.sqrtperte = 16; - goomvar = 0; - } - - /* - * baisser regulierement la vitesse... - */ - if ((cycle % 73 == 0) && (zfd.vitesse < STOP_SPEED - 5)) { - pzfd = &zfd; - zfd.vitesse++; - } - - /* - * arreter de decrémenter au bout d'un certain temps - */ - if ((cycle % 101 == 0) && (zfd.pertedec == 7)) { - pzfd = &zfd; - zfd.pertedec = 8; - zfd.sqrtperte = 16; - } - - /* - * Permet de forcer un effet. - */ - if ((forceMode > 0) && (forceMode <= NB_FX)) { - pzfd = &zfd; - pzfd->mode = forceMode - 1; - } - - if (forceMode == -1) { - pzfd = NULL; - } - - /* - * Changement d'effet de zoom ! - */ - if (pzfd != NULL) { - static int exvit = 128; - int dif; - - nombreCDDC = 0; - - switchIncr = SWITCHINCR; - - dif = zfd.vitesse - exvit; - if (dif < 0) - dif = -dif; - - if (dif > 2) { - switchIncr *= (dif + 2) / 2; - } - exvit = zfd.vitesse; - switchMult = 1.0f; - - if (((accelvar > goomlimit) && (totalgoom < 2)) || (forceMode > 0)) { - switchIncr = 0; - switchMult = SWITCHMULT; - } - } - else { - if (nombreCDDC > TIME_BTW_CHG) { - pzfd = &zfd; - nombreCDDC = 0; - } - else - nombreCDDC++; - } - + + + /* diminuer de 1 le temps de lockage */ + /* note pour ceux qui n'ont pas suivis : le lockvar permet d'empecher un */ + /* changement d'etat du plugin juste apres un autre changement d'etat. oki */ + if (--goomInfo->update.lockvar < 0) + goomInfo->update.lockvar = 0; + + /* on verifie qu'il ne se pas un truc interressant avec le son. */ + if ((goomInfo->sound.timeSinceLastGoom == 0) + || (forceMode > 0) + || (goomInfo->update.cyclesSinceLastChange > TIME_BTW_CHG)) { + + /* changement eventuel de mode */ + if (goom_irand(goomInfo->gRandom,16) == 0) + switch (goom_irand(goomInfo->gRandom,32)) { + case 0: + case 10: + goomInfo->update.zoomFilterData.hypercosEffect = goom_irand(goomInfo->gRandom,2); + case 13: + case 20: + case 21: + goomInfo->update.zoomFilterData.mode = WAVE_MODE; + goomInfo->update.zoomFilterData.reverse = 0; + goomInfo->update.zoomFilterData.waveEffect = (goom_irand(goomInfo->gRandom,3) == 0); + if (goom_irand(goomInfo->gRandom,2)) + goomInfo->update.zoomFilterData.vitesse = (goomInfo->update.zoomFilterData.vitesse + 127) >> 1; + break; + case 1: + case 11: + goomInfo->update.zoomFilterData.mode = CRYSTAL_BALL_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + break; + case 2: + case 12: + goomInfo->update.zoomFilterData.mode = AMULETTE_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + break; + case 3: + goomInfo->update.zoomFilterData.mode = WATER_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + break; + case 4: + case 14: + goomInfo->update.zoomFilterData.mode = SCRUNCH_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + break; + case 5: + case 15: + case 22: + goomInfo->update.zoomFilterData.mode = HYPERCOS1_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = (goom_irand(goomInfo->gRandom,3) == 0); + break; + case 6: + case 16: + goomInfo->update.zoomFilterData.mode = HYPERCOS2_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + break; + case 7: + case 17: + goomInfo->update.zoomFilterData.mode = CRYSTAL_BALL_MODE; + goomInfo->update.zoomFilterData.waveEffect = (goom_irand(goomInfo->gRandom,4) == 0); + goomInfo->update.zoomFilterData.hypercosEffect = goom_irand(goomInfo->gRandom,2); + break; + case 8: + case 18: + case 19: + goomInfo->update.zoomFilterData.mode = SCRUNCH_MODE; + goomInfo->update.zoomFilterData.waveEffect = 1; + goomInfo->update.zoomFilterData.hypercosEffect = 1; + break; + case 29: + case 30: + goomInfo->update.zoomFilterData.mode = YONLY_MODE; + break; + case 31: + case 32: + goomInfo->update.zoomFilterData.mode = SPEEDWAY_MODE; + break; + default: + goomInfo->update.zoomFilterData.mode = NORMAL_MODE; + goomInfo->update.zoomFilterData.waveEffect = 0; + goomInfo->update.zoomFilterData.hypercosEffect = 0; + } + } + + /* tout ceci ne sera fait qu'en cas de non-blocage */ + if (goomInfo->update.lockvar == 0) { + /* reperage de goom (acceleration forte de l'acceleration du volume) */ + /* -> coup de boost de la vitesse si besoin.. */ + if (goomInfo->sound.timeSinceLastGoom == 0) { + + int i; + goomInfo->update.goomvar++; + + /* SELECTION OF THE GOOM STATE */ + if ((!goomInfo->update.stateSelectionBlocker)&&(goom_irand(goomInfo->gRandom,3))) { + goomInfo->update.stateSelectionRnd = goom_irand(goomInfo->gRandom,goomInfo->statesRangeMax); + goomInfo->update.stateSelectionBlocker = 3; + } + else if (goomInfo->update.stateSelectionBlocker) goomInfo->update.stateSelectionBlocker--; + + for (i=0;istatesNumber;i++) + if ((goomInfo->update.stateSelectionRnd >= goomInfo->states[i].rangemin) + && (goomInfo->update.stateSelectionRnd <= goomInfo->states[i].rangemax)) + goomInfo->curGState = &(goomInfo->states[i]); + + if ((goomInfo->curGState->drawIFS) && (goomInfo->update.ifs_incr<=0)) { + goomInfo->update.recay_ifs = 5; + goomInfo->update.ifs_incr = 11; + } + + if ((!goomInfo->curGState->drawIFS) && (goomInfo->update.ifs_incr>0) && (goomInfo->update.decay_ifs<=0)) + goomInfo->update.decay_ifs = 100; + + if (!goomInfo->curGState->drawScope) + goomInfo->update.stop_lines = 0xf000 & 5; + + if (!goomInfo->curGState->drawScope) { + goomInfo->update.stop_lines = 0; + goomInfo->update.lineMode = goomInfo->update.drawLinesDuration; + } + + /* if (goomInfo->update.goomvar % 1 == 0) */ + { + guint32 vtmp; + guint32 newvit; + + goomInfo->update.lockvar = 50; + newvit = STOP_SPEED + 1 - ((float)3.5f * log10(goomInfo->sound.speedvar * 60 + 1)); + /* retablir le zoom avant.. */ + if ((goomInfo->update.zoomFilterData.reverse) && (!(goomInfo->cycle % 13)) && (rand () % 5 == 0)) { + goomInfo->update.zoomFilterData.reverse = 0; + goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 2; + goomInfo->update.lockvar = 75; + } + if (goom_irand(goomInfo->gRandom,10) == 0) { + goomInfo->update.zoomFilterData.reverse = 1; + goomInfo->update.lockvar = 100; + } + + if (goom_irand(goomInfo->gRandom,10) == 0) + goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 1; + if (goom_irand(goomInfo->gRandom,12) == 0) + goomInfo->update.zoomFilterData.vitesse = STOP_SPEED + 1; + + /* changement de milieu.. */ + switch (goom_irand(goomInfo->gRandom,25)) { + case 0: + case 3: + case 6: + goomInfo->update.zoomFilterData.middleY = goomInfo->screen.height - 1; + goomInfo->update.zoomFilterData.middleX = goomInfo->screen.width / 2; + break; + case 1: + case 4: + goomInfo->update.zoomFilterData.middleX = goomInfo->screen.width - 1; + break; + case 2: + case 5: + goomInfo->update.zoomFilterData.middleX = 1; + break; + default: + goomInfo->update.zoomFilterData.middleY = goomInfo->screen.height / 2; + goomInfo->update.zoomFilterData.middleX = goomInfo->screen.width / 2; + } + + if ((goomInfo->update.zoomFilterData.mode == WATER_MODE) + || (goomInfo->update.zoomFilterData.mode == YONLY_MODE) + || (goomInfo->update.zoomFilterData.mode == AMULETTE_MODE)) { + goomInfo->update.zoomFilterData.middleX = goomInfo->screen.width / 2; + goomInfo->update.zoomFilterData.middleY = goomInfo->screen.height / 2; + } + + switch (vtmp = (goom_irand(goomInfo->gRandom,15))) { + case 0: + goomInfo->update.zoomFilterData.vPlaneEffect = goom_irand(goomInfo->gRandom,3) + - goom_irand(goomInfo->gRandom,3); + goomInfo->update.zoomFilterData.hPlaneEffect = goom_irand(goomInfo->gRandom,3) + - goom_irand(goomInfo->gRandom,3); + break; + case 3: + goomInfo->update.zoomFilterData.vPlaneEffect = 0; + goomInfo->update.zoomFilterData.hPlaneEffect = goom_irand(goomInfo->gRandom,8) + - goom_irand(goomInfo->gRandom,8); + break; + case 4: + case 5: + case 6: + case 7: + goomInfo->update.zoomFilterData.vPlaneEffect = goom_irand(goomInfo->gRandom,5) + - goom_irand(goomInfo->gRandom,5); + goomInfo->update.zoomFilterData.hPlaneEffect = -goomInfo->update.zoomFilterData.vPlaneEffect; + break; + case 8: + goomInfo->update.zoomFilterData.hPlaneEffect = 5 + goom_irand(goomInfo->gRandom,8); + goomInfo->update.zoomFilterData.vPlaneEffect = -goomInfo->update.zoomFilterData.hPlaneEffect; + break; + case 9: + goomInfo->update.zoomFilterData.vPlaneEffect = 5 + goom_irand(goomInfo->gRandom,8); + goomInfo->update.zoomFilterData.hPlaneEffect = -goomInfo->update.zoomFilterData.hPlaneEffect; + break; + case 13: + goomInfo->update.zoomFilterData.hPlaneEffect = 0; + goomInfo->update.zoomFilterData.vPlaneEffect = goom_irand(goomInfo->gRandom,10) + - goom_irand(goomInfo->gRandom,10); + break; + case 14: + goomInfo->update.zoomFilterData.hPlaneEffect = goom_irand(goomInfo->gRandom,10) + - goom_irand(goomInfo->gRandom,10); + goomInfo->update.zoomFilterData.vPlaneEffect = goom_irand(goomInfo->gRandom,10) + - goom_irand(goomInfo->gRandom,10); + break; + default: + if (vtmp < 10) { + goomInfo->update.zoomFilterData.vPlaneEffect = 0; + goomInfo->update.zoomFilterData.hPlaneEffect = 0; + } + } + + if (goom_irand(goomInfo->gRandom,5) != 0) + goomInfo->update.zoomFilterData.noisify = 0; + else { + goomInfo->update.zoomFilterData.noisify = goom_irand(goomInfo->gRandom,2) + 1; + goomInfo->update.lockvar *= 2; + } + + if (goomInfo->update.zoomFilterData.mode == AMULETTE_MODE) { + goomInfo->update.zoomFilterData.vPlaneEffect = 0; + goomInfo->update.zoomFilterData.hPlaneEffect = 0; + goomInfo->update.zoomFilterData.noisify = 0; + } + + if ((goomInfo->update.zoomFilterData.middleX == 1) || (goomInfo->update.zoomFilterData.middleX == (signed int)goomInfo->screen.width - 1)) { + goomInfo->update.zoomFilterData.vPlaneEffect = 0; + if (goom_irand(goomInfo->gRandom,2)) + goomInfo->update.zoomFilterData.hPlaneEffect = 0; + } + + if ((signed int)newvit < goomInfo->update.zoomFilterData.vitesse) /* on accelere */ + { + pzfd = &goomInfo->update.zoomFilterData; + if (((newvit < STOP_SPEED - 7) && + (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 6) && + (goomInfo->cycle % 3 == 0)) || (goom_irand(goomInfo->gRandom,40) == 0)) { + goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - goom_irand(goomInfo->gRandom,2) + + goom_irand(goomInfo->gRandom,2); + goomInfo->update.zoomFilterData.reverse = !goomInfo->update.zoomFilterData.reverse; + } + else { + goomInfo->update.zoomFilterData.vitesse = (newvit + goomInfo->update.zoomFilterData.vitesse * 7) / 8; + } + goomInfo->update.lockvar += 50; + } + } + + if (goomInfo->update.lockvar > 150) { + goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount; + goomInfo->update.switchMult = 1.0f; + } + } + /* mode mega-lent */ + if (goom_irand(goomInfo->gRandom,700) == 0) { + /* + * printf ("coup du sort...\n") ; + */ + pzfd = &goomInfo->update.zoomFilterData; + goomInfo->update.zoomFilterData.vitesse = STOP_SPEED - 1; + goomInfo->update.zoomFilterData.pertedec = 8; + goomInfo->update.zoomFilterData.sqrtperte = 16; + goomInfo->update.goomvar = 1; + goomInfo->update.lockvar += 50; + goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount; + goomInfo->update.switchMult = 1.0f; + } + } + + /* + * gros frein si la musique est calme + */ + if ((goomInfo->sound.speedvar < 0.01f) + && (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 4) + && (goomInfo->cycle % 16 == 0)) { + pzfd = &goomInfo->update.zoomFilterData; + goomInfo->update.zoomFilterData.vitesse += 3; + goomInfo->update.zoomFilterData.pertedec = 8; + goomInfo->update.zoomFilterData.sqrtperte = 16; + goomInfo->update.goomvar = 0; + } + + /* + * baisser regulierement la vitesse... + */ + if ((goomInfo->cycle % 73 == 0) && (goomInfo->update.zoomFilterData.vitesse < STOP_SPEED - 5)) { + pzfd = &goomInfo->update.zoomFilterData; + goomInfo->update.zoomFilterData.vitesse++; + } + + /* + * arreter de decrémenter au bout d'un certain temps + */ + if ((goomInfo->cycle % 101 == 0) && (goomInfo->update.zoomFilterData.pertedec == 7)) { + pzfd = &goomInfo->update.zoomFilterData; + goomInfo->update.zoomFilterData.pertedec = 8; + goomInfo->update.zoomFilterData.sqrtperte = 16; + } + + /* + * Permet de forcer un effet. + */ + if ((forceMode > 0) && (forceMode <= NB_FX)) { + pzfd = &goomInfo->update.zoomFilterData; + pzfd->mode = forceMode - 1; + } + + if (forceMode == -1) { + pzfd = NULL; + } + + /* + * Changement d'effet de zoom ! + */ + if (pzfd != NULL) { + int dif; + + goomInfo->update.cyclesSinceLastChange = 0; + + goomInfo->update.switchIncr = goomInfo->update.switchIncrAmount; + + dif = goomInfo->update.zoomFilterData.vitesse - goomInfo->update.previousZoomSpeed; + if (dif < 0) + dif = -dif; + + if (dif > 2) { + goomInfo->update.switchIncr *= (dif + 2) / 2; + } + goomInfo->update.previousZoomSpeed = goomInfo->update.zoomFilterData.vitesse; + goomInfo->update.switchMult = 1.0f; + + if (((goomInfo->sound.timeSinceLastGoom == 0) + && (goomInfo->sound.totalgoom < 2)) || (forceMode > 0)) { + goomInfo->update.switchIncr = 0; + goomInfo->update.switchMult = goomInfo->update.switchMultAmount; + } + } + else { + if (goomInfo->update.cyclesSinceLastChange > TIME_BTW_CHG) { + pzfd = &goomInfo->update.zoomFilterData; + goomInfo->update.cyclesSinceLastChange = 0; + } + else + goomInfo->update.cyclesSinceLastChange++; + } + #ifdef VERBOSE - if (pzfd) { - printf ("GOOM: pzfd->mode = %d\n", pzfd->mode); - } + if (pzfd) { + printf ("GOOM: pzfd->mode = %d\n", pzfd->mode); + } #endif - - // Zoom here ! - zoomFilterFastRGB (p1 + c_offset, p2 + c_offset, pzfd, resolx, c_resoly, - switchIncr, switchMult); - - /* - * Affichage tentacule - */ - - // if (curGState->drawTentacle) - if (goomlimit!=0) - tentacle_update(p2 + c_offset, p1 + c_offset, resolx, c_resoly, - data, (float)accelvar/goomlimit, curGState->drawTentacle); - else - tentacle_update(p2 + c_offset, p1 + c_offset, resolx, c_resoly, - data,0.0f, curGState->drawTentacle); - - - /* - * Affichage de texte - */ - { - static char title[1024]; - static int displayTitle = 0; - char text[255]; - - /* - * Le fps - */ - if (fps > 0) { - int i; - if (speedvar>0) { - for (i=0;i0) { - for (i=0;i 0) { - sprintf (text, "%2.f fps", fps); - goom_draw_text (p1 + c_offset,resolx,c_resoly, - 10, 24, text, 1, 0); - } - - /* - * Le titre - */ - if (songTitle != NULL) { - sprintf (title, songTitle); // la flemme d'inclure string.h :) - displayTitle = 200; - } - - if (displayTitle) { - goom_draw_text (p1 + c_offset,resolx,c_resoly, - resolx / 2, c_resoly / 2 + 7, title, - ((float) (190 - displayTitle) / 10.0f), 1); - displayTitle--; - if (displayTitle < 4) - goom_draw_text (p2 + c_offset,resolx,c_resoly, - resolx / 2, c_resoly / 2 + 7, title, - ((float) (190 - displayTitle) / 10.0f), 1); - } - } - - /* - * Gestion du Scope - */ - - /* - * arret demande - */ - if ((stop_lines & 0xf000)||(!curGState->drawScope)) { - float param1, param2, amplitude; - int couleur; - int mode; - - choose_a_goom_line (¶m1, ¶m2, &couleur, &mode, &litude,1); - couleur = GML_BLACK; - - goom_lines_switch_to (gmline1, mode, param1, amplitude, couleur); - goom_lines_switch_to (gmline2, mode, param2, amplitude, couleur); - stop_lines &= 0x0fff; - } - - /* - * arret aleatore.. changement de mode de ligne.. - */ - if (lineMode != DRAWLINES) { - lineMode--; - if (lineMode == -1) - lineMode = 0; - } - else - if ((cycle%80==0)&&(iRAND(5)==0)&&lineMode) - lineMode--; - - if ((cycle % 120 == 0) - && (iRAND (4) == 0) - && (curGState->drawScope)) { - if (lineMode == 0) - lineMode = DRAWLINES; - else if (lineMode == DRAWLINES) { - float param1, param2, amplitude; - int couleur1,couleur2; - int mode; - - lineMode--; - choose_a_goom_line (¶m1, ¶m2, &couleur1, - &mode, &litude,stop_lines); - - couleur2 = 5-couleur1; - if (stop_lines) { - stop_lines--; - if (iRAND(2)) - couleur2=couleur1 = GML_BLACK; - } - - goom_lines_switch_to (gmline1, mode, param1, amplitude, couleur1); - goom_lines_switch_to (gmline2, mode, param2, amplitude, couleur2); - } - } - - /* - * si on est dans un goom : afficher les lignes... - */ - if ((lineMode != 0) || (agoom > 15)) { - gmline2->power = gmline1->power; - - goom_lines_draw (gmline1, data[0], p2 + c_offset); - goom_lines_draw (gmline2, data[1], p2 + c_offset); - - if (((cycle % 121) == 9) && (iRAND (3) == 1) - && ((lineMode == 0) || (lineMode == DRAWLINES))) { - float param1, param2, amplitude; - int couleur1,couleur2; - int mode; - - choose_a_goom_line (¶m1, ¶m2, &couleur1, - &mode, &litude, stop_lines); - couleur2 = 5-couleur1; - - if (stop_lines) { - stop_lines--; - if (iRAND(2)) - couleur2=couleur1 = GML_BLACK; - } - goom_lines_switch_to (gmline1, mode, param1, amplitude, couleur1); - goom_lines_switch_to (gmline2, mode, param2, amplitude, couleur2); - } - } - - return_val = p1; - tmp = p1; - p1 = p2; - p2 = tmp; - - // affichage et swappage des buffers.. - cycle++; - - // toute les 2 secondes : vérifier si le taux de goom est correct - // et le modifier sinon.. - if (!(cycle % 64)) { - if (speedvar<1) - goomlimit /= 2; - if (totalgoom > 4) { - goomlimit++; - } - if (totalgoom > 7) { - goomlimit*=4/3; - goomlimit+=2; - } - if ((totalgoom == 0) && (goomlimit > 1)) - goomlimit--; - if ((totalgoom == 1) && (goomlimit > 1)) - goomlimit--; - totalgoom = 0; - } - return return_val; + + /* Zoom here ! */ + zoomFilterFastRGB (goomInfo, goomInfo->p1, goomInfo->p2, pzfd, goomInfo->screen.width, goomInfo->screen.height, + goomInfo->update.switchIncr, goomInfo->update.switchMult); + + /* + * Affichage tentacule + */ + + /* if (goomInfo.sound.goomlimit > 0.0001f) */ + goomInfo->tentacles_fx.apply(&goomInfo->tentacles_fx, goomInfo->p1, goomInfo->p2, goomInfo); + /* tentacle_update(goomInfo, goomInfo->p2, goomInfo->p1, goomInfo->screen.width, goomInfo->screen.height, + data, (float)goomInfo->sound.accelvar, goomInfo->curGState->drawTentacle); */ + + goomInfo->star_fx.apply (&goomInfo->star_fx,goomInfo->p2,goomInfo->p1,goomInfo); + + /* + * Affichage de texte + */ + { + /*char title[1024];*/ + char text[64]; + + /* + * Le message + */ + update_message (goomInfo, message); + + if (fps > 0) { + sprintf (text, "%2.0f fps", fps); + goom_draw_text (goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, + 10, 24, text, 1, 0); + } + + /* + * Le titre + */ + if (songTitle != NULL) { + strncpy (goomInfo->update.titleText, songTitle, 1023); + goomInfo->update.titleText[1023]=0; + goomInfo->update.timeOfTitleDisplay = 200; + } + + if (goomInfo->update.timeOfTitleDisplay) { + goom_draw_text (goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, + goomInfo->screen.width / 2, goomInfo->screen.height / 2 + 7, goomInfo->update.titleText, + ((float) (190 - goomInfo->update.timeOfTitleDisplay) / 10.0f), 1); + goomInfo->update.timeOfTitleDisplay--; + if (goomInfo->update.timeOfTitleDisplay < 4) + goom_draw_text (goomInfo->p2,goomInfo->screen.width,goomInfo->screen.height, + goomInfo->screen.width / 2, goomInfo->screen.height / 2 + 7, goomInfo->update.titleText, + ((float) (190 - goomInfo->update.timeOfTitleDisplay) / 10.0f), 1); + } + } + + /* + * Gestion du Scope + */ + + /* + * arret demande + */ + if ((goomInfo->update.stop_lines & 0xf000)||(!goomInfo->curGState->drawScope)) { + float param1, param2, amplitude; + int couleur; + int mode; + + choose_a_goom_line (goomInfo, ¶m1, ¶m2, &couleur, &mode, &litude,1); + couleur = GML_BLACK; + + goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude, couleur); + goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude, couleur); + goomInfo->update.stop_lines &= 0x0fff; + } + + /* + * arret aleatore.. changement de mode de ligne.. + */ + if (goomInfo->update.lineMode != goomInfo->update.drawLinesDuration) { + goomInfo->update.lineMode--; + if (goomInfo->update.lineMode == -1) + goomInfo->update.lineMode = 0; + } + else + if ((goomInfo->cycle%80==0)&&(goom_irand(goomInfo->gRandom,5)==0)&&goomInfo->update.lineMode) + goomInfo->update.lineMode--; + + if ((goomInfo->cycle % 120 == 0) + && (goom_irand(goomInfo->gRandom,4) == 0) + && (goomInfo->curGState->drawScope)) { + if (goomInfo->update.lineMode == 0) + goomInfo->update.lineMode = goomInfo->update.drawLinesDuration; + else if (goomInfo->update.lineMode == goomInfo->update.drawLinesDuration) { + float param1, param2, amplitude; + int couleur1,couleur2; + int mode; + + goomInfo->update.lineMode--; + choose_a_goom_line (goomInfo, ¶m1, ¶m2, &couleur1, + &mode, &litude,goomInfo->update.stop_lines); + + couleur2 = 5-couleur1; + if (goomInfo->update.stop_lines) { + goomInfo->update.stop_lines--; + if (goom_irand(goomInfo->gRandom,2)) + couleur2=couleur1 = GML_BLACK; + } + + goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude, couleur1); + goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude, couleur2); + } + } + + /* + * si on est dans un goom : afficher les lignes... + */ + if ((goomInfo->update.lineMode != 0) || (goomInfo->sound.timeSinceLastGoom < 5)) { + goomInfo->gmline2->power = goomInfo->gmline1->power; + + goom_lines_draw (goomInfo, goomInfo->gmline1, data[0], goomInfo->p2); + goom_lines_draw (goomInfo, goomInfo->gmline2, data[1], goomInfo->p2); + + if (((goomInfo->cycle % 121) == 9) && (goom_irand(goomInfo->gRandom,3) == 1) + && ((goomInfo->update.lineMode == 0) || (goomInfo->update.lineMode == goomInfo->update.drawLinesDuration))) { + float param1, param2, amplitude; + int couleur1,couleur2; + int mode; + + choose_a_goom_line (goomInfo, ¶m1, ¶m2, &couleur1, + &mode, &litude, goomInfo->update.stop_lines); + couleur2 = 5-couleur1; + + if (goomInfo->update.stop_lines) { + goomInfo->update.stop_lines--; + if (goom_irand(goomInfo->gRandom,2)) + couleur2=couleur1 = GML_BLACK; + } + goom_lines_switch_to (goomInfo->gmline1, mode, param1, amplitude, couleur1); + goom_lines_switch_to (goomInfo->gmline2, mode, param2, amplitude, couleur2); + } + } + + return_val = goomInfo->p1; + tmp = goomInfo->p1; + goomInfo->p1 = goomInfo->p2; + goomInfo->p2 = tmp; + + /* affichage et swappage des buffers.. */ + goomInfo->cycle++; + + goomInfo->convolve_fx.apply(&goomInfo->convolve_fx,return_val,goomInfo->conv,goomInfo); + + return (guint32*)goomInfo->conv; } -void -goom_close (void) +/**************************************** +* CLOSE * +****************************************/ +void goom_close (PluginInfo *goomInfo) { - if (pixel != NULL) - free (pixel); - if (back != NULL) - free (back); - pixel = back = NULL; - RAND_CLOSE (); - release_ifs (); - goom_lines_free (&gmline1); - goom_lines_free (&gmline2); - tentacle_free(); + if (goomInfo->pixel != NULL) + free (goomInfo->pixel); + if (goomInfo->back != NULL) + free (goomInfo->back); + if (goomInfo->conv != NULL) + free (goomInfo->conv); + + goomInfo->pixel = goomInfo->back = NULL; + goomInfo->conv = NULL; + goom_random_free(goomInfo->gRandom); + goom_lines_free (&goomInfo->gmline1); + goom_lines_free (&goomInfo->gmline2); + + /* release_ifs (); */ + goomInfo->ifs_fx.free(&goomInfo->ifs_fx); + goomInfo->convolve_fx.free(&goomInfo->convolve_fx); + goomInfo->star_fx.free(&goomInfo->star_fx); + goomInfo->tentacles_fx.free(&goomInfo->tentacles_fx); + goomInfo->zoomFilter_fx.free(&goomInfo->zoomFilter_fx); + + free(goomInfo); } +/* *** */ void -choose_a_goom_line (float *param1, float *param2, int *couleur, int *mode, - float *amplitude, int farparm) -{ - *mode = iRAND (3); - *amplitude = 1.0f; - switch (*mode) { - case GML_CIRCLE: - if (farparm) { - *param1 = *param2 = 0.47f; - *amplitude = 0.8f; - break; - } - if (iRAND (3) == 0) { - *param1 = *param2 = 0; - *amplitude = 3.0f; - } - else if (iRAND (2)) { - *param1 = 0.40f * c_resoly; - *param2 = 0.22f * c_resoly; - } - else { - *param1 = *param2 = c_resoly * 0.35; - } - break; - case GML_HLINE: - if (iRAND (4) || farparm) { - *param1 = c_resoly / 7; - *param2 = 6.0f * c_resoly / 7.0f; - } - else { - *param1 = *param2 = c_resoly / 2.0f; - *amplitude = 2.0f; - } - break; - case GML_VLINE: - if (iRAND (3) || farparm) { - *param1 = resolx / 7.0f; - *param2 = 6.0f * resolx / 7.0f; - } - else { - *param1 = *param2 = resolx / 2.0f; - *amplitude = 1.5f; - } - break; - } - - *couleur = iRAND (6); -} - -void -goom_set_font (int ***chars, int *width, int *height) +choose_a_goom_line (PluginInfo *goomInfo, float *param1, float *param2, int *couleur, int *mode, + float *amplitude, int far) { - if (chars == NULL) - return ; + *mode = goom_irand(goomInfo->gRandom,3); + *amplitude = 1.0f; + switch (*mode) { + case GML_CIRCLE: + if (far) { + *param1 = *param2 = 0.47f; + *amplitude = 0.8f; + break; + } + if (goom_irand(goomInfo->gRandom,3) == 0) { + *param1 = *param2 = 0; + *amplitude = 3.0f; + } + else if (goom_irand(goomInfo->gRandom,2)) { + *param1 = 0.40f * goomInfo->screen.height; + *param2 = 0.22f * goomInfo->screen.height; + } + else { + *param1 = *param2 = goomInfo->screen.height * 0.35; + } + break; + case GML_HLINE: + if (goom_irand(goomInfo->gRandom,4) || far) { + *param1 = goomInfo->screen.height / 7; + *param2 = 6.0f * goomInfo->screen.height / 7.0f; + } + else { + *param1 = *param2 = goomInfo->screen.height / 2.0f; + *amplitude = 2.0f; + } + break; + case GML_VLINE: + if (goom_irand(goomInfo->gRandom,3) || far) { + *param1 = goomInfo->screen.width / 7.0f; + *param2 = 6.0f * goomInfo->screen.width / 7.0f; + } + else { + *param1 = *param2 = goomInfo->screen.width / 2.0f; + *amplitude = 1.5f; + } + break; + } -// font_chars = chars; -// font_width = width; -// font_height = height; - // tester les fonts.. + *couleur = goom_irand(goomInfo->gRandom,6); } +#define ECART_VARIATION 1.5 +#define POS_VARIATION 3.0 +#define SCROLLING_SPEED 80 /* * Met a jour l'affichage du message defilant */ -void update_message (char *message) { - - static int nbl; - static char msg2 [0x800]; - static int affiche = 0; - static int longueur; - int fin = 0; - - if (message) { - int i=1,j=0; - sprintf (msg2,message); - for (j=0;msg2[j];j++) - if (msg2[j]=='\n') - i++; - nbl = i; - affiche = resoly + nbl * 25 + 105; - longueur = strlen (msg2); - } - if (affiche) { - int i = 0; - char *msg=malloc(longueur+1); - char *ptr = msg; - int pos; - float ecart; - message = msg; - sprintf (msg,msg2); - - while (!fin) { - while (1) { - if (*ptr == 0) { - fin = 1; - break; - } - if (*ptr == '\n') { - *ptr = 0; - break; - } - ++ptr; - } - pos = affiche - (nbl-i)*25; - pos += 6.0*(cos((double)pos/20.0)); - pos -= 80; - ecart = (1.0+2.0*sin((double)pos/20.0)); - if ((fin) && (2 * pos < (int)resoly)) - pos = (int)resoly / 2; - pos += 7; - - goom_draw_text(p1 + c_offset,resolx,c_resoly, - resolx/2, pos, - message, - ecart, - 1); - message = ++ptr; - i++; - } - affiche --; - free (msg); - } +void update_message (PluginInfo *goomInfo, char *message) { + + int fin = 0; + + if (message) { + int i=1,j=0; + sprintf (goomInfo->update_message.message, message); + for (j=0;goomInfo->update_message.message[j];j++) + if (goomInfo->update_message.message[j]=='\n') + i++; + goomInfo->update_message.numberOfLinesInMessage = i; + goomInfo->update_message.affiche = goomInfo->screen.height + goomInfo->update_message.numberOfLinesInMessage * 25 + 105; + goomInfo->update_message.longueur = strlen(goomInfo->update_message.message); + } + if (goomInfo->update_message.affiche) { + int i = 0; + char *msg = malloc(goomInfo->update_message.longueur + 1); + char *ptr = msg; + int pos; + float ecart; + message = msg; + sprintf (msg, goomInfo->update_message.message); + + while (!fin) { + while (1) { + if (*ptr == 0) { + fin = 1; + break; + } + if (*ptr == '\n') { + *ptr = 0; + break; + } + ++ptr; + } + pos = goomInfo->update_message.affiche - (goomInfo->update_message.numberOfLinesInMessage - i)*25; + pos += POS_VARIATION * (cos((double)pos / 20.0)); + pos -= SCROLLING_SPEED; + ecart = (ECART_VARIATION * sin((double)pos / 20.0)); + if ((fin) && (2 * pos < (int)goomInfo->screen.height)) + pos = (int)goomInfo->screen.height / 2; + pos += 7; + + goom_draw_text(goomInfo->p1,goomInfo->screen.width,goomInfo->screen.height, + goomInfo->screen.width/2, pos, + message, + ecart, + 1); + message = ++ptr; + i++; + } + goomInfo->update_message.affiche --; + free (msg); + } } diff --git a/src/post/goom/goom_core.h b/src/post/goom/goom_core.h deleted file mode 100644 index 70f570f3b..000000000 --- a/src/post/goom/goom_core.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef _GOOMCORE_H -#define _GOOMCORE_H - -#include "goom_config.h" - -/* typedef union { - guint32 val; - struct { - guint8 r; - guint8 g; - guint8 b; - guint32 a; - } rgba; - } Pixel ; - - typedef Pixel * GoomBuffer; -*/ - -#define NB_FX 10 - -void goom_init (guint32 resx, guint32 resy, int cinemascope); -void goom_set_resolution (guint32 resx, guint32 resy, int cinemascope); - -/* - * forceMode == 0 : do nothing - * forceMode == -1 : lock the FX - * forceMode == 1..NB_FX : force a switch to FX n°forceMode - * - * songTitle = pointer to the title of the song... - * - NULL if it is not the start of the song - * - only have a value at the start of the song - */ -guint32 * goom_update ( gint16 data[2][512], int forceMode, float fps, - char *songTitle, char *message); - -void goom_close (void); - -void goom_set_font (int ***chars, int *width, int *height); - -#endif diff --git a/src/post/goom/goom_filters.h b/src/post/goom/goom_filters.h new file mode 100644 index 000000000..bf64c166a --- /dev/null +++ b/src/post/goom/goom_filters.h @@ -0,0 +1,52 @@ +#ifndef _GOOM_FILTERS_H +#define _GOOM_FILTERS_H + +#include "goom_config.h" +#include "goom_typedefs.h" +#include "goom_visual_fx.h" +#include "goom_graphic.h" + +VisualFX zoomFilterVisualFXWrapper_create(); + +struct _ZOOM_FILTER_DATA +{ + int vitesse; /* 128 = vitesse nule... * * 256 = en arriere + * hyper vite.. * * 0 = en avant hype vite. */ + unsigned char pertedec; + unsigned char sqrtperte; + int middleX, middleY; /* milieu de l'effet */ + char reverse; /* inverse la vitesse */ + char mode; /* type d'effet à appliquer (cf les #define) */ + /** @since June 2001 */ + int hPlaneEffect; /* deviation horitontale */ + int vPlaneEffect; /* deviation verticale */ + /** @since April 2002 */ + int waveEffect; /* applique une "surcouche" de wave effect */ + int hypercosEffect; /* applique une "surcouche de hypercos effect */ + + char noisify; /* ajoute un bruit a la transformation */ +}; + +#define NORMAL_MODE 0 +#define WAVE_MODE 1 +#define CRYSTAL_BALL_MODE 2 +#define SCRUNCH_MODE 3 +#define AMULETTE_MODE 4 +#define WATER_MODE 5 +#define HYPERCOS1_MODE 6 +#define HYPERCOS2_MODE 7 +#define YONLY_MODE 8 +#define SPEEDWAY_MODE 9 + +void pointFilter (PluginInfo *goomInfo, Pixel * pix1, Color c, + float t1, float t2, float t3, float t4, guint32 cycle); + +/* filtre de zoom : + * le contenu de pix1 est copie dans pix2. + * zf : si non NULL, configure l'effet. + * resx,resy : taille des buffers. + */ +void zoomFilterFastRGB (PluginInfo *goomInfo, Pixel * pix1, Pixel * pix2, ZoomFilterData * zf, guint32 resx, + guint32 resy, int switchIncr, float switchMult); + +#endif diff --git a/src/post/goom/goom_fx.h b/src/post/goom/goom_fx.h new file mode 100644 index 000000000..0a0e1287b --- /dev/null +++ b/src/post/goom/goom_fx.h @@ -0,0 +1,10 @@ +#ifndef _GOOM_FX_H +#define _GOOM_FX_H + +#include "goom_visual_fx.h" +#include "goom_plugin_info.h" + +VisualFX convolve_create (); +VisualFX flying_star_create (); + +#endif diff --git a/src/post/goom/goom_graphic.h b/src/post/goom/goom_graphic.h new file mode 100644 index 000000000..8f0a12c49 --- /dev/null +++ b/src/post/goom/goom_graphic.h @@ -0,0 +1,66 @@ +#ifndef _GOOM_GRAPHIC_H +#define _GOOM_GRAPHIC_H + +typedef unsigned int Uint; + +typedef struct +{ + unsigned short r, v, b; +} +Color; + +extern const Color BLACK; +extern const Color WHITE; +extern const Color RED; +extern const Color BLUE; +extern const Color GREEN; +extern const Color YELLOW; +extern const Color ORANGE; +extern const Color VIOLET; + + +#ifdef COLOR_BGRA + +#define B_CHANNEL 0xFF000000 +#define G_CHANNEL 0x00FF0000 +#define R_CHANNEL 0x0000FF00 +#define A_CHANNEL 0x000000FF + +typedef union _PIXEL { + struct { + unsigned char b; + unsigned char g; + unsigned char r; + unsigned char a; + } channels; + unsigned int val; + unsigned char cop[4]; +} Pixel; + +#else + +#define A_CHANNEL 0xFF000000 +#define R_CHANNEL 0x00FF0000 +#define G_CHANNEL 0x0000FF00 +#define B_CHANNEL 0x000000FF + +typedef union _PIXEL { + struct { + unsigned char a; + unsigned char r; + unsigned char g; + unsigned char b; + } channels; + unsigned int val; + unsigned char cop[4]; +} Pixel; + +#endif /* COLOR_BGRA */ + +/* +inline void setPixelRGB (Pixel * buffer, Uint x, Uint y, Color c); +inline void getPixelRGB (Pixel * buffer, Uint x, Uint y, Color * c); +*/ + + +#endif /* _GOOM_GRAPHIC_H */ diff --git a/src/post/goom/goom_hash.c b/src/post/goom/goom_hash.c new file mode 100644 index 000000000..09052ed90 --- /dev/null +++ b/src/post/goom/goom_hash.c @@ -0,0 +1,100 @@ +#include "goom_hash.h" +#include +#include + +static GoomHashEntry *entry_new(const char *key, HashValue value) { + + GoomHashEntry *entry = (GoomHashEntry*)malloc(sizeof(GoomHashEntry)); + + entry->key = (char *)malloc(strlen(key)+1); + strcpy(entry->key,key); + entry->value = value; + entry->lower = NULL; + entry->upper = NULL; + + return entry; +} + +static void entry_free(GoomHashEntry *entry) { + if (entry!=NULL) { + entry_free(entry->lower); + entry_free(entry->upper); + free(entry->key); + free(entry); + } +} + +static void entry_put(GoomHashEntry *entry, const char *key, HashValue value) { + int cmp = strcmp(key,entry->key); + if (cmp==0) { + entry->value = value; + } + else if (cmp > 0) { + if (entry->upper == NULL) + entry->upper = entry_new(key,value); + else + entry_put(entry->upper, key, value); + } + else { + if (entry->lower == NULL) + entry->lower = entry_new(key,value); + else + entry_put(entry->lower, key, value); + } +} + +static HashValue *entry_get(GoomHashEntry *entry, const char *key) { + + int cmp; + if (entry==NULL) + return NULL; + cmp = strcmp(key,entry->key); + if (cmp > 0) + return entry_get(entry->upper, key); + else if (cmp < 0) + return entry_get(entry->lower, key); + else + return &(entry->value); +} + +GoomHash *goom_hash_new() { + GoomHash *_this = (GoomHash*)malloc(sizeof(GoomHash)); + _this->root = NULL; + return _this; +} + +void goom_hash_free(GoomHash *_this) { + entry_free(_this->root); + free(_this); +} + +void goom_hash_put(GoomHash *_this, const char *key, HashValue value) { + if (_this->root == NULL) + _this->root = entry_new(key,value); + else + entry_put(_this->root,key,value); +} + +HashValue *goom_hash_get(GoomHash *_this, const char *key) { + return entry_get(_this->root,key); +} + +void goom_hash_put_int(GoomHash *_this, const char *key, int i) { + HashValue value; + value.i = i; + goom_hash_put(_this,key,value); +} + +void goom_hash_put_float(GoomHash *_this, const char *key, float f) { + HashValue value; + value.f = f; + goom_hash_put(_this,key,value); +} + +void goom_hash_put_ptr(GoomHash *_this, const char *key, void *ptr) { + HashValue value; + value.ptr = ptr; + goom_hash_put(_this,key,value); +} + + diff --git a/src/post/goom/goom_hash.h b/src/post/goom/goom_hash.h new file mode 100644 index 000000000..c869e67e4 --- /dev/null +++ b/src/post/goom/goom_hash.h @@ -0,0 +1,34 @@ +#ifndef _GOOM_HASH_H +#define _GOOM_HASH_H + +typedef struct GOOM_HASH_ENTRY GoomHashEntry; +typedef struct GOOM_HASH GoomHash; + +typedef union { + void *ptr; + int i; + float f; +} HashValue; + +struct GOOM_HASH_ENTRY { + char *key; + HashValue value; + GoomHashEntry *lower; + GoomHashEntry *upper; +}; + +struct GOOM_HASH { + GoomHashEntry *root; +}; + +GoomHash *goom_hash_new(); +void goom_hash_free(GoomHash *gh); + +void goom_hash_put(GoomHash *gh, const char *key, HashValue value); +HashValue *goom_hash_get(GoomHash *gh, const char *key); + +void goom_hash_put_int(GoomHash *_this, const char *key, int i); +void goom_hash_put_float(GoomHash *_this, const char *key, float f); +void goom_hash_put_ptr(GoomHash *_this, const char *key, void *ptr); + +#endif /* _GOOM_HASH_H */ diff --git a/src/post/goom/goom_plugin_info.h b/src/post/goom/goom_plugin_info.h new file mode 100644 index 000000000..c28df65dd --- /dev/null +++ b/src/post/goom/goom_plugin_info.h @@ -0,0 +1,176 @@ +#ifndef _GOOM_PLUGIN_INFO_H +#define _GOOM_PLUGIN_INFO_H + +#include "goom_typedefs.h" + +#include "goom_config.h" + +#include "goom_graphic.h" +#include "goom_config_param.h" +#include "goom_visual_fx.h" +#include "goom_filters.h" +#include "goom_tools.h" +#include "goom_script_scanner.h" + +typedef struct { + char drawIFS; + char drawPoints; + char drawTentacle; + + char drawScope; + int farScope; + + int rangemin; + int rangemax; +} GoomState; + +#define STATES_MAX_NB 128 + +/** + * Gives informations about the sound. + */ +struct _SOUND_INFO { + + /* nota : a Goom is just a sound event... */ + + int timeSinceLastGoom; /* >= 0 */ + float goomPower; /* power of the last Goom [0..1] */ + + int timeSinceLastBigGoom; /* >= 0 */ + + float volume; /* [0..1] */ + short samples[2][512]; + + /* other "internal" datas for the sound_tester */ + float goom_limit; /* auto-updated limit of goom_detection */ + float bigGoomLimit; + float accelvar; /* acceleration of the sound - [0..1] */ + float speedvar; /* speed of the sound - [0..100] */ + int allTimesMax; + int totalgoom; /* number of goom since last reset + * (a reset every 64 cycles) */ + + float prov_max; /* accel max since last reset */ + + int cycle; + + /* private */ + PluginParam volume_p; + PluginParam speed_p; + PluginParam accel_p; + PluginParam goom_limit_p; + PluginParam goom_power_p; + PluginParam last_goom_p; + PluginParam last_biggoom_p; + PluginParam biggoom_speed_limit_p; + PluginParam biggoom_factor_p; + + PluginParameters params; /* contains the previously defined parameters. */ +}; + + +/** + * Allows FXs to know the current state of the plugin. + */ +struct _PLUGIN_INFO { + + /* public datas */ + + int nbParams; + PluginParameters *params; + + /* private datas */ + + struct _SIZE_TYPE { + int width; + int height; + int size; /* == screen.height * screen.width. */ + } screen; + + SoundInfo sound; + + int nbVisuals; + VisualFX **visuals; /* pointers on all the visual fx */ + + /** The known FX */ + VisualFX convolve_fx; + VisualFX star_fx; + VisualFX zoomFilter_fx; + VisualFX tentacles_fx; + VisualFX ifs_fx; + + /** image buffers */ + guint32 *pixel; + guint32 *back; + Pixel *p1, *p2; + Pixel *conv; + + /** state of goom */ + guint32 cycle; + GoomState states[STATES_MAX_NB]; + int statesNumber; + int statesRangeMax; + + GoomState *curGState; + + /** effet de ligne.. */ + GMLine *gmline1; + GMLine *gmline2; + + /** sinus table */ + int sintable[0x10000]; + + /* INTERNALS */ + + /** goom_update internals. + * I took all static variables from goom_update and put them here.. for the moment. + */ + struct { + int lockvar; /* pour empecher de nouveaux changements */ + int goomvar; /* boucle des gooms */ + int loopvar; /* mouvement des points */ + int stop_lines; + int ifs_incr; /* dessiner l'ifs (0 = non: > = increment) */ + int decay_ifs; /* disparition de l'ifs */ + int recay_ifs; /* dedisparition de l'ifs */ + int cyclesSinceLastChange; /* nombre de Cycle Depuis Dernier Changement */ + int drawLinesDuration; /* duree de la transition entre afficher les lignes ou pas */ + int lineMode; /* l'effet lineaire a dessiner */ + float switchMultAmount; /* SWITCHMULT (29.0f/30.0f) */ + int switchIncrAmount; /* 0x7f */ + float switchMult; /* 1.0f */ + int switchIncr; /* = SWITCHINCR; */ + int stateSelectionRnd; + int stateSelectionBlocker; + int previousZoomSpeed; + int timeOfTitleDisplay; + char titleText[1024]; + ZoomFilterData zoomFilterData; + } update; + + struct { + int numberOfLinesInMessage; + char message[0x800]; + int affiche; + int longueur; + } update_message; + + struct { + void (*draw_line) (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); + void (*zoom_filter) (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); + void (*create_output_with_brightness) (Pixel *src, Pixel *dest, int screensize, int iff); + } methods; + + GoomRandom *gRandom; + + GoomScriptScanner *scanner; + GoomScriptScanner *main_scanner; + const char *main_script_str; +}; + +void plugin_info_init(PluginInfo *p, int nbVisual); + +/* i = [0..p->nbVisual-1] */ +void plugin_info_add_visual(PluginInfo *p, int i, VisualFX *visual); + +#endif diff --git a/src/post/goom/goom_script.c b/src/post/goom/goom_script.c new file mode 100644 index 000000000..5645d583e --- /dev/null +++ b/src/post/goom/goom_script.c @@ -0,0 +1,107 @@ +#include "goom_script.h" +#include +#include +#include + +static PluginParameters *getBaseForVariable (PluginInfo *pluginInfo, const char *name) { + + int i; + if (name == NULL) { + printf("ERROR: No variable container name specified\n"); + return NULL; + } + + /* TODO: using an hashmap */ + for (i=0;inbParams;i++) { + if (!strcmp(name, pluginInfo->params[i].name)) { + return &(pluginInfo->params[i]); + } + } + + printf ("ERROR: No such variable container: %s\n", name); + return NULL; +} + +static PluginParam *getParamForVariable(PluginParameters *params, const char *name) { + + int i; + if (name == NULL) + return NULL; + + for (i=0;inbParams;i++) { + if (params->params[i] && (!strcmp(name, params->params[i]->name))) { + return params->params[i]; + } + } + printf ("ERROR: No such variable into %s: %s\n", params->name, name); + return NULL; +} + +PluginParam *goom_script_get_param(PluginInfo *pluginInfo, const char *name) { + + int i; + char *base; + char *var; + int len = strlen(name); + int hasDot = 0; + PluginParameters *pparams; + + if (name == NULL) + return NULL; + if (pluginInfo == NULL) { + printf("ERROR: programming %s on line %d\n", __FILE__, __LINE__); + return NULL; + } + + base = (char*)calloc(len+1,1); + var = (char*)calloc(len+1,1); + + for (i=0;iscanner, pluginInfo, cmds); + goom_script_scanner_execute(pluginInfo->scanner); +} + +/* set a script that will be executed every loop */ +void goom_set_main_script(PluginInfo *pluginInfo, const char *script) { + + pluginInfo->main_script_str = script; + goom_script_scanner_compile(pluginInfo->main_scanner, pluginInfo, script); +} + +void goom_execute_main_script(PluginInfo *pluginInfo) { + + goom_script_scanner_execute(pluginInfo->main_scanner); +} + +/* return a script containing the current goom state */ +char *goom_create_state_script(PluginInfo *pluginInfo) { + printf("not implemented\n"); + return NULL; +} + diff --git a/src/post/goom/goom_script.h b/src/post/goom/goom_script.h new file mode 100644 index 000000000..8b5bfb648 --- /dev/null +++ b/src/post/goom/goom_script.h @@ -0,0 +1,16 @@ +#ifndef _GOOM_SCRIPT_H +#define _GOOM_SCRIPT_H + +#include "goom_plugin_info.h" + +void goom_execute_script(PluginInfo *pluginInfo, const char *cmds); + +/* set a script that will be executed every loop */ +void goom_set_main_script(PluginInfo *pluginInfo, const char *script); +void goom_execute_main_script(PluginInfo *pluginInfo); + + /* return a script containing the current goom state */ +char *goom_create_state_script(PluginInfo *pluginInfo); + + +#endif /* _GOOM_SCRIPT_H */ diff --git a/src/post/goom/goom_script_scanner.c b/src/post/goom/goom_script_scanner.c new file mode 100644 index 000000000..5aec843b4 --- /dev/null +++ b/src/post/goom/goom_script_scanner.c @@ -0,0 +1,2463 @@ +#line 2 "goom_script_scanner.c" + +#line 4 "goom_script_scanner.c" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 5 +#define YY_FLEX_SUBMINOR_VERSION 31 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; +#endif /* ! C99 */ + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! FLEXINT_H */ + +#ifdef __cplusplus + +/* The "const" storage-class-modifier is valid. */ +#define YY_USE_CONST + +#else /* ! __cplusplus */ + +#if __STDC__ + +#define YY_USE_CONST + +#endif /* __STDC__ */ +#endif /* ! __cplusplus */ + +#ifdef YY_USE_CONST +#define yyconst const +#else +#define yyconst +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#define YY_BUF_SIZE 16384 +#endif + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +/* The following is because we cannot portably get our hands on size_t + * (without autoconf's help, which isn't available because we want + * flex-generated scanners to compile on their own). + */ + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef unsigned int yy_size_t; +#endif + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + yy_size_t yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = (char *) 0; +static int yy_init = 1; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +typedef unsigned char YY_CHAR; + +FILE *yyin = (FILE *) 0, *yyout = (FILE *) 0; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yy_fatal_error (yyconst char msg[] ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (size_t) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 14 +#define YY_END_OF_BUFFER 15 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[35] = + { 0, + 0, 0, 0, 0, 15, 13, 12, 1, 13, 13, + 9, 8, 8, 8, 3, 3, 12, 9, 4, 11, + 10, 0, 8, 8, 8, 2, 10, 7, 8, 6, + 7, 8, 5, 0 + } ; + +static yyconst flex_int32_t yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, + 1, 5, 1, 1, 6, 7, 8, 9, 9, 9, + 9, 9, 9, 9, 9, 9, 9, 1, 1, 1, + 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, + 1, 1, 1, 1, 10, 1, 11, 10, 10, 10, + + 10, 12, 10, 10, 13, 10, 10, 14, 10, 15, + 16, 10, 10, 10, 10, 17, 10, 10, 10, 10, + 10, 10, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst flex_int32_t yy_meta[18] = + { 0, + 1, 1, 1, 1, 1, 1, 2, 1, 3, 4, + 4, 4, 4, 4, 4, 4, 4 + } ; + +static yyconst flex_int16_t yy_base[39] = + { 0, + 0, 0, 15, 16, 57, 58, 54, 58, 46, 49, + 18, 46, 16, 17, 58, 44, 49, 0, 58, 58, + 41, 0, 42, 19, 21, 58, 39, 0, 22, 30, + 0, 19, 17, 58, 38, 41, 27, 43 + } ; + +static yyconst flex_int16_t yy_def[39] = + { 0, + 34, 1, 35, 35, 34, 34, 34, 34, 34, 34, + 34, 36, 36, 36, 34, 34, 34, 11, 34, 34, + 34, 37, 36, 36, 36, 34, 34, 38, 36, 36, + 38, 25, 25, 0, 34, 34, 34, 34 + } ; + +static yyconst flex_int16_t yy_nxt[76] = + { 0, + 6, 7, 8, 6, 6, 9, 6, 10, 11, 12, + 12, 13, 14, 12, 12, 12, 12, 8, 8, 16, + 16, 20, 22, 22, 21, 22, 18, 22, 22, 24, + 28, 25, 32, 23, 29, 33, 22, 30, 15, 15, + 15, 15, 23, 23, 23, 31, 31, 27, 22, 27, + 17, 26, 22, 19, 18, 17, 34, 5, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34 + } ; + +static yyconst flex_int16_t yy_chk[76] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 3, 4, 3, + 4, 11, 13, 14, 11, 24, 11, 25, 29, 13, + 37, 14, 29, 33, 24, 32, 30, 25, 35, 35, + 35, 35, 36, 36, 36, 38, 38, 27, 23, 21, + 17, 16, 12, 10, 9, 7, 5, 34, 34, 34, + 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, + 34, 34, 34, 34, 34 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "goom_script_scanner.lex" +#line 2 "goom_script_scanner.lex" + +#include +#include +#include +#include "goom_script_scanner.h" +#include "goom_script_scanner.tab.h" +void yyerror(char *); +void yyparse(); + +/* #define TRACE_SCRIPT */ + +#define INSTR_SETI_PARAM_INTEGER 1 +#define INSTR_SETI_VAR_INTEGER 2 +#define INSTR_SETI_VAR_VAR 3 +#define INSTR_SETI_VAR_PARAM 4 +#define INSTR_SETI_PARAM_VAR 5 +/* #define INSTR_JUMP 6 */ +#define INSTR_NOP 7 +#define INSTR_SETF_PARAM_FLOAT 8 +#define INSTR_SETF_VAR_FLOAT 9 +#define INSTR_SETF_VAR_VAR 10 +#define INSTR_SETF_VAR_PARAM 11 +#define INSTR_SETF_PARAM_VAR 12 +#define INSTR_ISLOWERF_VAR_VAR 13 +#define INSTR_ISLOWERF_VAR_FLOAT 14 +#define INSTR_ISLOWERI_VAR_VAR 15 +#define INSTR_ISLOWERI_VAR_INTEGER 16 +#define INSTR_ADDI_VAR_INTEGER 17 +#define INSTR_ADDF_VAR_FLOAT 18 +#define INSTR_ADDI_VAR_VAR 19 +#define INSTR_ADDF_VAR_VAR 20 +#define INSTR_MULI_VAR_INTEGER 21 +#define INSTR_MULF_VAR_FLOAT 22 +#define INSTR_MULI_VAR_VAR 23 +#define INSTR_MULF_VAR_VAR 24 +#define INSTR_ISEQUALF_VAR_VAR 25 +#define INSTR_ISEQUALF_VAR_FLOAT 26 +#define INSTR_ISEQUALI_VAR_VAR 27 +#define INSTR_ISEQUALI_VAR_INTEGER 28 +/* #define INSTR_JZERO 29 */ + +#define VALIDATE_OK "ok" +#define VALIDATE_ERROR "error while validating" +#define VALIDATE_TODO "todo" +#define VALIDATE_SYNTHAX_ERROR "synthax error" +#define VALIDATE_NO_SUCH_INT "no such integer variable" +#define VALIDATE_NO_SUCH_PARAM "no such param" +#define VALIDATE_NO_SUCH_VAR "no such variable" +#define VALIDATE_NO_SUCH_DEST_VAR "no such destination variable" +#define VALIDATE_NO_SUCH_SRC_VAR "no such src variable" + + PluginParam *goom_script_get_param(PluginInfo *pluginInfo, const char *name); + + /* ------------- SCRIPT_EXEC_ENV ------------ */ + + /* Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param); */ + static void instr_free(Instruction *_this); + /* void instr_add_param(Instruction *_this, char *param, int type); */ + static const char *instr_validate(Instruction *_this); + /* void instr_display(Instruction *_this); */ + + /* ----------- INSTRUCTION_FLOW ------------- */ + + static InstructionFlow *iflow_new(); + static void iflow_add_instr(InstructionFlow *_this, Instruction *instr); + static void iflow_clean(InstructionFlow *_this); + static void iflow_execute(InstructionFlow *_this, ScriptExecEnv *exec_env); + + /* ----------- IMPLEMENTATIONS --------------- */ + + void iflow_clean(InstructionFlow *_this) { + /* TODO: clean chaque instruction du flot */ + _this->number = 0; + goom_hash_free(_this->labels); + _this->labels = goom_hash_new(); + } + + InstructionFlow *iflow_new() { + + InstructionFlow *_this = (InstructionFlow*)malloc(sizeof(InstructionFlow)); + _this->number = 0; + _this->tabsize = 6; + _this->instr = (Instruction**)malloc(_this->tabsize * sizeof(Instruction*)); + _this->labels = goom_hash_new(); + + return _this; + } + + void iflow_add_instr(InstructionFlow *_this, Instruction *instr) { + + if (_this->number == _this->tabsize) { + _this->tabsize *= 2; + _this->instr = (Instruction**)realloc(_this->instr, _this->tabsize * sizeof(Instruction*)); + } + _this->instr[_this->number] = instr; + instr->address = _this->number; + _this->number++; + } + + /** + * instr_add_param + */ + void instr_add_param(Instruction *instr, char *param, int type) { + + int len; + if (instr==NULL) + return; + if (instr->cur_param==0) + return; + --instr->cur_param; + len = strlen(param); + instr->params[instr->cur_param] = (char*)malloc(len+1); + strcpy(instr->params[instr->cur_param], param); + instr->types[instr->cur_param] = type; + if (instr->cur_param == 0) { + + const char *result = instr_validate(instr); + if (result != VALIDATE_OK) { + printf("ERROR LINE %d: ", instr->parent->num_lines + 1); + instr_display(instr); + printf("... %s\n", result); + instr->parent->compilationOK = 0; + } + + if (instr->id != INSTR_NOP) + iflow_add_instr(instr->parent->current_flow, instr); + else + instr_free(instr); + } + } + + /** + * instr_init + */ + Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param) { + + Instruction *instr = (Instruction*)malloc(sizeof(Instruction)); + instr->params = (char**)malloc(nb_param*sizeof(char*)); + instr->types = (int*)malloc(nb_param*sizeof(int)); + instr->cur_param = instr->nb_param = nb_param; + instr->parent = parent; + instr->id = id; + instr->name = name; + instr->jump_label = NULL; + return instr; + } + + void instr_free(Instruction *_this) { + + int i; + free(_this->types); + for (i=_this->cur_param; i<_this->nb_param; ++i) + free(_this->params[i]); + free(_this->params); + free(_this); + } + + void instr_display(Instruction *_this) { + int i=_this->nb_param-1; + printf("%s", _this->name); + while(i>=_this->cur_param) { + printf(" %s", _this->params[i]); + --i; + } + } + + /** VALIDATE **/ + + static const char *validate_v_v(Instruction *_this) { + + _this->data.v_v.var_dest = goom_hash_get(_this->parent->vars, _this->params[1]); + _this->data.v_v.var_src = goom_hash_get(_this->parent->vars, _this->params[0]); + + if (_this->data.v_v.var_dest == NULL) { + return VALIDATE_NO_SUCH_DEST_VAR; + } + if (_this->data.v_v.var_src == NULL) { + return VALIDATE_NO_SUCH_SRC_VAR; + } + return VALIDATE_OK; + } + + static const char *validate_v_i(Instruction *_this) { + + _this->data.v_i.var = goom_hash_get(_this->parent->vars, _this->params[1]); + _this->data.v_i.value = atoi(_this->params[0]); + + if (_this->data.v_i.var == NULL) { + return VALIDATE_NO_SUCH_INT; + } + return VALIDATE_OK; + } + + static const char *validate_v_p(Instruction *_this) { + _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[1]); + _this->data.p_i.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[0]); + if (_this->data.p_i.param == NULL) + return VALIDATE_NO_SUCH_PARAM; + if (_this->data.p_i.param->type != PARAM_INTVAL) + return VALIDATE_ERROR; + if (_this->data.v_i.var == NULL) { + return VALIDATE_NO_SUCH_INT; + } + return VALIDATE_OK; + } + + static const char *validate_p_v(Instruction *_this) { + _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[0]); + _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); + if (_this->data.v_p.param == NULL) + return VALIDATE_NO_SUCH_PARAM; + if (_this->data.v_p.param->type != PARAM_INTVAL) + return VALIDATE_ERROR; + if (_this->data.v_p.var == NULL) { + return VALIDATE_NO_SUCH_INT; + } + return VALIDATE_OK; + } + + static const char *validate_p_i(Instruction *_this) { + _this->data.p_i.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); + _this->data.p_i.value = atoi(_this->params[0]); + if (_this->data.p_i.param == NULL) + return VALIDATE_NO_SUCH_PARAM; + if (_this->data.p_i.param->type == PARAM_INTVAL) + return VALIDATE_OK; + return VALIDATE_ERROR; + } + + /***/ + + static const char *validate_v_f(Instruction *_this) { + + _this->data.v_f.var = goom_hash_get(_this->parent->vars, _this->params[1]); + _this->data.v_f.value = atof(_this->params[0]); + + if (_this->data.v_f.var == NULL) { + return VALIDATE_NO_SUCH_VAR; + } + return VALIDATE_OK; + } + + static const char *validate_v_pf(Instruction *_this) { + + _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[1]); + _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[0]); + if (_this->data.v_p.param == NULL) + return VALIDATE_NO_SUCH_VAR; + if (_this->data.v_p.param->type != PARAM_FLOATVAL) + return VALIDATE_ERROR; + if (_this->data.v_p.var == NULL) { + return VALIDATE_NO_SUCH_VAR; + } + return VALIDATE_OK; + } + + static const char *validate_pf_v(Instruction *_this) { + + _this->data.v_p.var = goom_hash_get(_this->parent->vars, _this->params[0]); + _this->data.v_p.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); + if (_this->data.v_p.param == NULL) + return VALIDATE_NO_SUCH_VAR; + if (_this->data.v_p.param->type != PARAM_FLOATVAL) + return VALIDATE_ERROR; + if (_this->data.v_p.var == NULL) { + return VALIDATE_NO_SUCH_VAR; + } + return VALIDATE_OK; + } + + static const char *validate_p_f(Instruction *_this) { + _this->data.p_f.param = goom_script_get_param(_this->parent->pluginInfo, _this->params[1]); + _this->data.p_f.value = atof(_this->params[0]); + if (_this->data.p_f.param == NULL) + return VALIDATE_NO_SUCH_VAR; + if (_this->data.p_f.param->type == PARAM_FLOATVAL) + return VALIDATE_OK; + return VALIDATE_ERROR; + } + + static const char *validate_i(Instruction *_this, int v_i_id, int v_v_id) { + + if ((_this->types[0] == TYPE_INTEGER) && (_this->types[1] == TYPE_VAR)) { + _this->id = v_i_id; + return validate_v_i(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = v_v_id; + return validate_v_v(_this); + } + return VALIDATE_ERROR; + } + + static const char *validate_f(Instruction *_this, int v_f_id, int v_v_id) { + + if ((_this->types[0] == TYPE_FLOAT) && (_this->types[1] == TYPE_VAR)) { + _this->id = v_f_id; + return validate_v_f(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = v_v_id; + return validate_v_v(_this); + } + return VALIDATE_ERROR; + } + + /** + * instr_validate + */ + const char *instr_validate(Instruction *_this) { + + switch (_this->id) { + + /* set.i */ + case INSTR_SETI: + + if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_INTEGER)) { + _this->id = INSTR_SETI_PARAM_INTEGER; + return validate_p_i(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_INTEGER)) { + _this->id = INSTR_SETI_VAR_INTEGER; + return validate_v_i(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = INSTR_SETI_VAR_VAR; + return validate_v_v(_this); + } + else if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_VAR)) { + _this->id = INSTR_SETI_PARAM_VAR; + return validate_p_v(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_PARAM)) { + _this->id = INSTR_SETI_VAR_PARAM; + return validate_v_p(_this); + } + else { + return VALIDATE_TODO; + } + return VALIDATE_SYNTHAX_ERROR; + + /* set.f */ + case INSTR_SETF: + + if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_FLOAT)) { + _this->id = INSTR_SETF_PARAM_FLOAT; + return validate_p_f(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_FLOAT)) { + _this->id = INSTR_SETF_VAR_FLOAT; + return validate_v_f(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_VAR)) { + _this->id = INSTR_SETF_VAR_VAR; + return validate_v_v(_this); + } + else if ((_this->types[1] == TYPE_PARAM) && (_this->types[0] == TYPE_VAR)) { + _this->id = INSTR_SETF_PARAM_VAR; + return validate_pf_v(_this); + } + else if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_PARAM)) { + _this->id = INSTR_SETF_VAR_PARAM; + return validate_v_pf(_this); + } + else { + return VALIDATE_TODO; + } + return VALIDATE_SYNTHAX_ERROR; + + /* int */ + case INSTR_INT: + + if (_this->types[0] == TYPE_VAR) { + _this->id = INSTR_NOP; + goom_hash_put_int(_this->parent->vars, _this->params[0], 0); + return VALIDATE_OK; + } + return VALIDATE_SYNTHAX_ERROR; + + /* jump */ + case INSTR_JUMP: + + if (_this->types[0] == TYPE_LABEL) { + _this->jump_label = _this->params[0]; + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* jzero */ + case INSTR_JZERO: + + if ((_this->types[1] == TYPE_VAR) && (_this->types[0] == TYPE_LABEL)) { + _this->jump_label = _this->params[0]; + _this->data.v.var = goom_hash_get(_this->parent->vars, _this->params[1]); + if (_this->data.v.var == NULL) return VALIDATE_NO_SUCH_VAR; + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* label */ + case INSTR_LABEL: + + if (_this->types[0] == TYPE_LABEL) { + _this->id = INSTR_NOP; + goom_hash_put_int(_this->parent->current_flow->labels, _this->params[0], _this->parent->current_flow->number); + return VALIDATE_OK; + } + return VALIDATE_ERROR; + + /* isequal.i */ + case INSTR_ISEQUALI: + return validate_i(_this, INSTR_ISEQUALI_VAR_INTEGER, INSTR_ISEQUALI_VAR_VAR); + + /* isequal.f */ + case INSTR_ISEQUALF: + return validate_f(_this, INSTR_ISEQUALF_VAR_FLOAT, INSTR_ISEQUALF_VAR_VAR); + + /* islower.i */ + case INSTR_ISLOWERI: + return validate_i(_this, INSTR_ISLOWERI_VAR_INTEGER, INSTR_ISLOWERI_VAR_VAR); + + /* islower.f */ + case INSTR_ISLOWERF: + return validate_f(_this, INSTR_ISLOWERF_VAR_FLOAT, INSTR_ISLOWERF_VAR_VAR); + + /* add.i */ + case INSTR_ADDI: + return validate_i(_this, INSTR_ADDI_VAR_INTEGER, INSTR_ADDI_VAR_VAR); + + /* add.f */ + case INSTR_ADDF: + return validate_f(_this, INSTR_ADDF_VAR_FLOAT, INSTR_ADDF_VAR_VAR); + + /* mul.i */ + case INSTR_MULI: + return validate_i(_this, INSTR_MULI_VAR_INTEGER, INSTR_MULI_VAR_VAR); + + /* mul.f */ + case INSTR_MULF: + return validate_f(_this, INSTR_MULF_VAR_FLOAT, INSTR_MULF_VAR_VAR); + + default: + return VALIDATE_TODO; + } + return VALIDATE_ERROR; + } + + /** EXECUTE **/ + + void iflow_execute(InstructionFlow *_this, ScriptExecEnv *exec_env) { + int ip = 0; + while (ip < _this->number) { + Instruction *instr = _this->instr[ip]; +#ifdef TRACE_SCRIPT + printf("execute "); instr_display(instr); printf("\n"); +#endif + + switch (instr->id) { + + /* SET.I */ + case INSTR_SETI_PARAM_INTEGER: + IVAL(*instr->data.p_i.param) = instr->data.p_i.value; + instr->data.p_i.param->change_listener(instr->data.p_i.param); + ++ip; break; + + case INSTR_SETI_VAR_VAR: + *instr->data.v_v.var_dest = *instr->data.v_v.var_src; + ++ip; break; + + case INSTR_SETI_PARAM_VAR: + IVAL(*instr->data.v_p.param) = instr->data.v_p.var->i; + instr->data.v_p.param->change_listener(instr->data.v_p.param); + ++ip; break; + + case INSTR_SETI_VAR_PARAM: + instr->data.v_p.var->i = IVAL(*instr->data.v_p.param); + ++ip; break; + + case INSTR_SETI_VAR_INTEGER: + instr->data.v_i.var->i = instr->data.v_i.value; + ++ip; break; + + /* SET.F */ + case INSTR_SETF_PARAM_FLOAT: + FVAL(*instr->data.p_i.param) = instr->data.p_f.value; + instr->data.p_f.param->change_listener(instr->data.p_f.param); + ++ip; break; + + case INSTR_SETF_VAR_VAR: + *instr->data.v_v.var_dest = *instr->data.v_v.var_src; + ++ip; break; + + case INSTR_SETF_PARAM_VAR: + FVAL(*instr->data.v_p.param) = instr->data.v_p.var->f; + instr->data.v_p.param->change_listener(instr->data.v_p.param); + ++ip; break; + + case INSTR_SETF_VAR_PARAM: + instr->data.v_p.var->f = FVAL(*instr->data.v_p.param); + ++ip; break; + + case INSTR_SETF_VAR_FLOAT: + instr->data.v_f.var->f = instr->data.v_f.value; + ++ip; break; + + /* JUMP */ + case INSTR_JUMP: + ip += instr->data.jump_offset; break; + + /* JZERO */ + case INSTR_JZERO: + ip += (instr->data.v.var->i ? 1 : instr->data.jump_offset); break; + + case INSTR_NOP: + ++ip; break; + + /* ISEQUAL.I */ + case INSTR_ISEQUALI_VAR_VAR: + instr->data.v_v.var_dest->i -= instr->data.v_v.var_src->i; + ++ip; break; + + case INSTR_ISEQUALI_VAR_INTEGER: + instr->data.v_i.var->i -= instr->data.v_i.value; + ++ip; break; + + /* ISEQUAL.F */ + case INSTR_ISEQUALF_VAR_VAR: + instr->data.v_v.var_dest->f -= instr->data.v_v.var_src->f; + ++ip; break; + + case INSTR_ISEQUALF_VAR_FLOAT: + instr->data.v_f.var->f -= instr->data.v_f.value; + ++ip; break; + + /* ISLOWER.I */ + case INSTR_ISLOWERI_VAR_VAR: + instr->data.v_v.var_dest->i = (instr->data.v_v.var_dest->i < instr->data.v_v.var_src->i); + ++ip; break; + + case INSTR_ISLOWERI_VAR_INTEGER: + instr->data.v_i.var->i = (instr->data.v_i.var->i < instr->data.v_i.value); + ++ip; break; + + /* ISLOWER.F */ + case INSTR_ISLOWERF_VAR_VAR: + instr->data.v_v.var_dest->f = (instr->data.v_v.var_dest->f < instr->data.v_v.var_src->f); + ++ip; break; + + case INSTR_ISLOWERF_VAR_FLOAT: + instr->data.v_f.var->f = (instr->data.v_f.var->f < instr->data.v_f.value); + ++ip; break; + + /* ADD.I */ + case INSTR_ADDI_VAR_VAR: + instr->data.v_v.var_dest->i += instr->data.v_v.var_src->i; + ++ip; break; + + case INSTR_ADDI_VAR_INTEGER: + instr->data.v_i.var->i += instr->data.v_i.value; + ++ip; break; + + /* ADD.F */ + case INSTR_ADDF_VAR_VAR: + instr->data.v_v.var_dest->f += instr->data.v_v.var_src->f; + ++ip; break; + + case INSTR_ADDF_VAR_FLOAT: + instr->data.v_f.var->f += instr->data.v_f.value; + ++ip; break; + + /* MUL.I */ + case INSTR_MULI_VAR_VAR: + instr->data.v_v.var_dest->i *= instr->data.v_v.var_src->i; + ++ip; break; + + case INSTR_MULI_VAR_INTEGER: + instr->data.v_i.var->i *= instr->data.v_i.value; + ++ip; break; + + /* MUL.F */ + case INSTR_MULF_VAR_VAR: + instr->data.v_v.var_dest->f *= instr->data.v_v.var_src->f; + ++ip; break; + + case INSTR_MULF_VAR_FLOAT: + instr->data.v_f.var->f *= instr->data.v_f.value; + ++ip; break; + + /* EQUALS.I * / + case INSTR_EQUALSI_VAR_VAR: + return (instr->data.v_v.var_src->i == instr->data.v_v.var_dest->i)?1:2; + + case INSTR_EQUALSI_VAR_INTEGER: + return (instr->data.v_i.var->i == instr->data.v_i.value)?1:2; + + / * EQUALS.F * / + case INSTR_EQUALSF_VAR_VAR: + return (instr->data.v_v.var_src->f == instr->data.v_v.var_dest->f)?1:2; + case INSTR_EQUALSF_VAR_FLOAT: + return (instr->data.v_f.var->f == instr->data.v_f.value)?1:2; + + / * LOWER.I * / + case INSTR_LOWERI_VAR_VAR: + return (instr->data.v_v.var_src->i > instr->data.v_v.var_dest->i)?1:2; + case INSTR_LOWERI_VAR_INTEGER: + return (instr->data.v_i.var->i < instr->data.v_i.value)?1:2; + + / * LOWER.F * / + case INSTR_LOWERF_VAR_VAR: + return (instr->data.v_v.var_src->f > instr->data.v_v.var_dest->f)?1:2; + case INSTR_LOWERF_VAR_FLOAT: + return (instr->data.v_f.var->f < instr->data.v_f.value)?1:2; + */ + + default: + printf("NOT IMPLEMENTED : %d\n", instr->id); + ++ip; + } + } + } + + GoomScriptScanner *currentScanner; + +#line 1090 "goom_script_scanner.c" + +#define INITIAL 0 +#define COMMENT 1 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + + static void yyunput (int c,char *buf_ptr ); + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#define YY_READ_BUF_SIZE 8192 +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO (void) fwrite( yytext, yyleng, 1, yyout ) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + register yy_state_type yy_current_state; + register char *yy_cp, *yy_bp; + register int yy_act; + +#line 631 "goom_script_scanner.lex" + + +#line 1245 "goom_script_scanner.c" + + if ( (yy_init) ) + { + (yy_init) = 0; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + while ( 1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)]; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 35 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 58 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +/* rule 1 can match eol */ +YY_RULE_SETUP +#line 633 "goom_script_scanner.lex" +{ ++currentScanner->num_lines; } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 635 "goom_script_scanner.lex" +{ BEGIN INITIAL; } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 636 "goom_script_scanner.lex" +{ /* eat up comment */ } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 638 "goom_script_scanner.lex" +{ BEGIN COMMENT; } + YY_BREAK +/* + set"."i { currentScanner->instr = instr_init(currentScanner, "set.i", INSTR_SETI, 2); } + set"."f { currentScanner->instr = instr_init(currentScanner, "set.f", INSTR_SETF, 2); } + add"."i { currentScanner->instr = instr_init(currentScanner, "add.i", INSTR_ADDI, 2); } + add"."f { currentScanner->instr = instr_init(currentScanner, "add.f", INSTR_ADDF, 2); } + mul"."i { currentScanner->instr = instr_init(currentScanner, "mul.i", INSTR_MULI, 2); } + mul"."f { currentScanner->instr = instr_init(currentScanner, "mul.f", INSTR_MULF, 2); } + bool { currentScanner->instr = instr_init(currentScanner, "bool", INSTR_INT, 1); } + jump { currentScanner->instr = instr_init(currentScanner, "jump", INSTR_JUMP, 1); } + label { currentScanner->instr = instr_init(currentScanner, "label", INSTR_LABEL, 1); } + equals"."i { currentScanner->instr = instr_init(currentScanner, "equals.i", INSTR_EQUALSI, 2); } + equals"."f { currentScanner->instr = instr_init(currentScanner, "equals.f", INSTR_EQUALSF, 2); } + lower"."i { currentScanner->instr = instr_init(currentScanner, "lower.i", INSTR_LOWERI, 2); } + lower"."f { currentScanner->instr = instr_init(currentScanner, "lower.f", INSTR_LOWERF, 2); } + ":"{ID}":" { instr_add_param(currentScanner->instr, yytext, TYPE_LABEL); } + {ID}"."{ID} { instr_add_param(currentScanner->instr, yytext, TYPE_PARAM); } + */ +case 5: +YY_RULE_SETUP +#line 657 "goom_script_scanner.lex" +{ return FLOAT_TK; } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 658 "goom_script_scanner.lex" +{ return INT_TK; } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 659 "goom_script_scanner.lex" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_PARAM; } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 660 "goom_script_scanner.lex" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_VAR; } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 661 "goom_script_scanner.lex" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_INTEGER; } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 662 "goom_script_scanner.lex" +{ strncpy(yylval.strValue, yytext, 2047); return TYPE_FLOAT; } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 663 "goom_script_scanner.lex" +{ sprintf(yylval.strValue, "%3.2f", atof(yytext)/100.0f); return TYPE_FLOAT; } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 664 "goom_script_scanner.lex" +/* eat up whitespace */ + YY_BREAK +case 13: +YY_RULE_SETUP +#line 665 "goom_script_scanner.lex" +{ yylval.charValue = *yytext; return *yytext; } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 667 "goom_script_scanner.lex" +ECHO; + YY_BREAK +#line 1416 "goom_script_scanner.c" +case YY_STATE_EOF(INITIAL): +case YY_STATE_EOF(COMMENT): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + register char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + register char *source = (yytext_ptr); + register int number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (int) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + size_t num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = 0; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + register yy_state_type yy_current_state; + register char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + register YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 35 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + register int yy_is_jam; + register char *yy_cp = (yy_c_buf_p); + + register YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 35 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; + yy_is_jam = (yy_current_state == 34); + + return yy_is_jam ? 0 : yy_current_state; +} + + static void yyunput (int c, register char * yy_bp ) +{ + register char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + register int number_to_move = (yy_n_chars) + 2; + register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + register char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return EOF; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +#ifndef __cplusplus +extern int isatty (int ); +#endif /* __cplusplus */ + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + int grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return 0; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = 0; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param str a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yy_str ) +{ + + return yy_scan_bytes(yy_str,strlen(yy_str) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param bytes the byte buffer to scan + * @param len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * bytes, int len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + int i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < len; ++i ) + buf[i] = bytes[i]; + + buf[len] = buf[len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param line_number + * + */ +void yyset_lineno (int line_number ) +{ + + yylineno = line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * in_str ) +{ + yyin = in_str ; +} + +void yyset_out (FILE * out_str ) +{ + yyout = out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int bdebug ) +{ + yy_flex_debug = bdebug ; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + register int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + register int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return (void *) malloc( size ); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return (void *) realloc( (char *) ptr, size ); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#undef YY_NEW_FILE +#undef YY_FLUSH_BUFFER +#undef yy_set_bol +#undef yy_new_buffer +#undef yy_set_interactive +#undef yytext_ptr +#undef YY_DO_BEFORE_ACTION + +#ifdef YY_DECL_IS_OURS +#undef YY_DECL_IS_OURS +#undef YY_DECL +#endif +#line 667 "goom_script_scanner.lex" + + + +static void reset_scanner(GoomScriptScanner *gss) { + + gss->num_lines = 0; + gss->instr = NULL; + iflow_clean(gss->iflow); + gss->current_flow = gss->iflow; + gss->compilationOK = 1; +} + +static void calculate_labels(InstructionFlow *iflow) { + int i = 0; + while (i < iflow->number) { + Instruction *instr = iflow->instr[i]; + if (instr->jump_label) { + HashValue *label = goom_hash_get(iflow->labels,instr->jump_label); + if (label) { + instr->data.jump_offset = -instr->address + label->i; + } + else { + fprintf(stderr, "ERROR: could not find label %s\n", instr->jump_label); + instr->id = INSTR_NOP; + } + } + ++i; + } +} + +void goom_script_scanner_compile(GoomScriptScanner *_currentScanner, PluginInfo *pluginInfo, const char *script) { + +#ifdef VERBOSE + printf("\n=== Starting Compilation ===\n"); +#endif + currentScanner = _currentScanner; + reset_scanner(currentScanner); + currentScanner->pluginInfo = pluginInfo; + + yy_scan_string(script); + yyparse(); + gsl_commit_compilation(); + + calculate_labels(currentScanner->iflow); + +#ifdef VERBOSE + printf("=== Compilation done. # of lines: %d. # of instr: %d ===\n", currentScanner->num_lines, currentScanner->iflow->number); +#endif +} + +void goom_script_scanner_execute(GoomScriptScanner *scanner) { + + ScriptExecEnv exec_env; + exec_env.vars = scanner->vars; + if (scanner->compilationOK) + iflow_execute(scanner->iflow, &exec_env); +} + +GoomScriptScanner *goom_script_scanner_new() { + + GoomScriptScanner *gss = (GoomScriptScanner*)malloc(sizeof(GoomScriptScanner)); + + gss->iflow = iflow_new(); + gss->vars = goom_hash_new(); + + reset_scanner(gss); + gss->compilationOK = 0; + return gss; +} + +int goom_script_scanner_is_compiled(GoomScriptScanner *gss) { + return gss->compilationOK; +} + +void goom_script_scanner_free(GoomScriptScanner *gss) { + free(gss); +} + +int yywrap(void) { return 1; } + + diff --git a/src/post/goom/goom_script_scanner.h b/src/post/goom/goom_script_scanner.h new file mode 100644 index 000000000..63b3c7ca3 --- /dev/null +++ b/src/post/goom/goom_script_scanner.h @@ -0,0 +1,197 @@ +#ifndef _GOOM_SCRIPT_SCANNER_H +#define _GOOM_SCRIPT_SCANNER_H + +#include "goom_plugin_info.h" + +void goom_script_scanner_compile(GoomScriptScanner *scanner, PluginInfo *pluginInfo, const char *script); +void goom_script_scanner_execute(GoomScriptScanner *scanner); +int goom_script_scanner_is_compiled(GoomScriptScanner *gss); + +GoomScriptScanner *goom_script_scanner_new(); +void goom_script_scanner_free(GoomScriptScanner *gss); + + +/* -- internal use -- */ + +#include "goom_hash.h" + +#define EMPTY_NODE 0 +#define CONST_INT_NODE 1 +#define CONST_FLOAT_NODE 2 +#define VAR_NODE 3 +#define PARAM_NODE 4 +#define OPR_NODE 5 + +#define OPR_SET 1 +#define OPR_DECLARE_INT 2 +#define OPR_DECLARE_FLOAT 3 +#define OPR_IF 4 +#define OPR_BLOCK 5 +#define OPR_ADD 6 +#define OPR_MUL 7 +#define OPR_EQU 8 +#define OPR_LOW 9 + +typedef struct { +/* char *name;*/ +} ParamNodeType; + +typedef struct { +/* char *name;*/ +} VarNodeType; + +typedef struct { + int val; +} ConstIntNodeType; + +typedef struct { + float val; +} ConstFloatNodeType; + +typedef struct { + int type; + int nbOp; + struct _NODE_TYPE *op[3]; /* maximal number of operand needed */ + struct _NODE_TYPE *next; +} OprNodeType; + +typedef struct _NODE_TYPE{ + int type; + char *str; + union { + ParamNodeType param; + VarNodeType var; + ConstIntNodeType constInt; + ConstFloatNodeType constFloat; + OprNodeType opr; + }; +} NodeType; + +void gsl_commit_compilation(); + +/* ------------- SCRIPT_EXEC_ENV ------------ */ + +typedef struct _SCRIPT_EXEC_ENV { + int ip; + GoomHash *vars; +} ScriptExecEnv; + +/* ------------- INSTRUCTIONS -------------- */ + +typedef struct _INSTRUCTION { + + int id; + GoomScriptScanner *parent; + const char *name; /* name of the instruction */ + + char **params; /* parametres de l'instruction */ + int *types; /* type des parametres de l'instruction */ + int cur_param; + int nb_param; + + int address; + char *jump_label; + + union { + + /* PARAM - INTEGER */ + struct { + PluginParam *param; + int value; + } p_i; + + /* PARAM - FLOAT */ + struct { + PluginParam *param; + float value; + } p_f; + + /* VAR - PARAM */ + struct { + PluginParam *param; + HashValue *var; + } v_p; + + /* VAR - INTEGER */ + struct { + HashValue *var; + int value; + } v_i; + + /* VAR - FLOAT */ + struct { + HashValue *var; + float value; + } v_f; + + /* VAR - VAR */ + struct { + HashValue *var_src; + HashValue *var_dest; + } v_v; + + /* VAR */ + struct { + int jump_offset; + HashValue *var; + } v; + + int jump_offset; + + } data; + +} Instruction; + +Instruction *instr_init(GoomScriptScanner *parent, const char *name, int id, int nb_param); +void instr_add_param(Instruction *_this, char *param, int type); +void instr_display(Instruction *_this); + +/* ----------- INSTRUCTION_FLOW ------------- */ + +typedef struct _INSTRUCTION_FLOW { + + Instruction **instr; + int number; + int tabsize; + GoomHash *labels; + +} InstructionFlow; + +/* ----------- GOOM SCRIPT SCANNER ------------- */ + +struct _GoomScriptScanner { + int num_lines; + Instruction *instr; /* instruction en cours de construction */ + + InstructionFlow *iflow; /* flow d'instruction racine */ + GoomHash *vars; /* table de variables */ + InstructionFlow *current_flow; + + PluginInfo *pluginInfo; + int compilationOK; +}; + +/* #define TYPE_PARAM 1 + #define TYPE_INTEGER 2 + #define TYPE_FLOAT 3 + #define TYPE_VAR 4 */ +#define TYPE_LABEL 5 +#define TYPE_OP_EQUAL 6 + +#define INSTR_JUMP 6 + +#define INSTR_SETI 10001 +#define INSTR_SETF 10002 +#define INSTR_INT 10003 +#define INSTR_LABEL 10004 +#define INSTR_ISLOWERI 10005 +#define INSTR_ISLOWERF 10006 +#define INSTR_ADDI 10007 +#define INSTR_ADDF 10008 +#define INSTR_MULI 10009 +#define INSTR_MULF 10010 +#define INSTR_ISEQUALI 10011 +#define INSTR_ISEQUALF 10012 +#define INSTR_JZERO 29 + +#endif diff --git a/src/post/goom/goom_script_scanner.tab.c b/src/post/goom/goom_script_scanner.tab.c new file mode 100644 index 000000000..1f70ab192 --- /dev/null +++ b/src/post/goom/goom_script_scanner.tab.c @@ -0,0 +1,1644 @@ +/* A Bison parser, made by GNU Bison 1.875a. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, 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 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. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Written by Richard Stallman by simplifying the original so called + ``semantic'' parser. */ + +/* All symbols defined below should begin with yy or YY, to avoid + infringing on user name space. This should be done even for local + variables, as they might otherwise be expanded by user macros. + There are some unavoidable exceptions within include files to + define necessary library symbols; they are noted "INFRINGES ON + USER NAME SPACE" below. */ + +/* Identify Bison output. */ +#define YYBISON 1 + +/* Skeleton name. */ +#define YYSKELETON_NAME "yacc.c" + +/* Pure parsers. */ +#define YYPURE 0 + +/* Using locations. */ +#define YYLSP_NEEDED 0 + + + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TYPE_INTEGER = 258, + TYPE_FLOAT = 259, + TYPE_VAR = 260, + TYPE_PARAM = 261, + INT_TK = 262, + FLOAT_TK = 263 + }; +#endif +#define TYPE_INTEGER 258 +#define TYPE_FLOAT 259 +#define TYPE_VAR 260 +#define TYPE_PARAM 261 +#define INT_TK 262 +#define FLOAT_TK 263 + + + + +/* Copy the first part of user declarations. */ +#line 6 "goom_script_scanner.y" + + #include + #include + #include "goom_script_scanner.h" + + int yylex(void); + void yyerror(char *); + extern GoomScriptScanner *currentScanner; + + static NodeType *nodeNew(const char *str, int type); + static void nodeFreeInternals(NodeType *node); + static void nodeFree(NodeType *node); + + static void commit_node(NodeType *node); + static void precommit_node(NodeType *node); + + static NodeType *new_constInt(const char *str); + static NodeType *new_constFloat(const char *str); + static NodeType *new_var(const char *str); + static NodeType *new_param(const char *str); + static NodeType *new_nop(const char *str); + static NodeType *new_op(const char *str, int type, int nbOp); + + static int allocateLabel(); + #define allocateTemp allocateLabel + + /* SETTER */ + static NodeType *new_set(NodeType *lvalue, NodeType *expression) { + NodeType *set = new_op("set", OPR_SET, 2); + set->opr.op[0] = lvalue; + set->opr.op[1] = expression; + return set; + } + static void commit_set(NodeType *set) { + precommit_node(set->opr.op[1]); +#ifdef VERBOSE + printf("set.f %s %s\n", set->opr.op[0]->str, set->opr.op[1]->str); +#endif + currentScanner->instr = instr_init(currentScanner, "set.f", INSTR_SETF, 2); + commit_node(set->opr.op[0]); + commit_node(set->opr.op[1]); + } + + /* FLOAT */ + static NodeType *new_float_decl(NodeType *name) { + NodeType *fld = new_op("float", OPR_DECLARE_FLOAT, 1); + fld->opr.op[0] = name; + return fld; + } + static void commit_float(NodeType *var) { +#ifdef VERBOSE + printf("float %s\n", var->opr.op[0]->str); +#endif + currentScanner->instr = instr_init(currentScanner, "float", INSTR_INT, 1); + commit_node(var->opr.op[0]); + } + + /* INT */ + static NodeType *new_int_decl(NodeType *name) { + NodeType *intd = new_op("int", OPR_DECLARE_INT, 1); + intd->opr.op[0] = name; + return intd; + } + static void commit_int(NodeType *var) { +#ifdef VERBOSE + printf("int %s\n", var->opr.op[0]->str); +#endif + currentScanner->instr = instr_init(currentScanner, "int", INSTR_INT, 1); + commit_node(var->opr.op[0]); + } + + /* commodity method for add, mult, ... */ + + static int is_tmp_expr(NodeType *node) { + return node->str && !strncmp(node->str,"__tmp",5); + } + + static void precommit_expr(NodeType *expr, const char *type, int instr_id) { + + char stmp[256]; + NodeType *tmp; + int toAdd; + + /* compute "left" and "right" */ + precommit_node(expr->opr.op[0]); + precommit_node(expr->opr.op[1]); + + if (is_tmp_expr(expr->opr.op[0])) { + strcpy(stmp, expr->opr.op[0]->str); + toAdd = 1; + } + else if (is_tmp_expr(expr->opr.op[1])) { + strcpy(stmp,expr->opr.op[1]->str); + toAdd = 0; + } + else { + /* declare a float to store the result */ + sprintf(stmp,"__tmp%i",allocateTemp()); + commit_node(new_float_decl(new_var(stmp))); + /* set the float to the value of "op1" */ + commit_node(new_set(new_var(stmp),expr->opr.op[0])); + toAdd = 1; + } + + /* add op2 to tmp */ +#ifdef VERBOSE + printf("%s %s %s\n", type, stmp, expr->opr.op[toAdd]->str); +#endif + currentScanner->instr = instr_init(currentScanner, type, instr_id, 2); + commit_node(new_var(stmp)); + commit_node(expr->opr.op[toAdd]); + + /* redefine the ADD node now as the computed variable */ + nodeFreeInternals(expr); + tmp = new_var(stmp); + *expr = *tmp; + free(tmp); + } + + static NodeType *new_expr2(const char *name, int id, NodeType *expr1, NodeType *expr2) { + NodeType *add = new_op(name, id, 2); + add->opr.op[0] = expr1; + add->opr.op[1] = expr2; + return add; + } + + /* ADD */ + static NodeType *new_add(NodeType *expr1, NodeType *expr2) { + return new_expr2("add.f", OPR_ADD, expr1, expr2); + } + static void precommit_add(NodeType *add) { + precommit_expr(add,"add.f",INSTR_ADDF); + } + + /* MUL */ + static NodeType *new_mul(NodeType *expr1, NodeType *expr2) { + return new_expr2("mul.f", OPR_MUL, expr1, expr2); + } + static void precommit_mul(NodeType *mul) { + precommit_expr(mul,"mul.f",INSTR_MULF); + } + + /* EQU */ + static NodeType *new_equ(NodeType *expr1, NodeType *expr2) { + return new_expr2("isequal.f", OPR_EQU, expr1, expr2); + } + static void precommit_equ(NodeType *mul) { + precommit_expr(mul,"isequal.f",INSTR_ISEQUALF); + } + + /* INF */ + static NodeType *new_low(NodeType *expr1, NodeType *expr2) { + return new_expr2("islower.f", OPR_LOW, expr1, expr2); + } + static void precommit_low(NodeType *mul) { + precommit_expr(mul,"islower.f",INSTR_ISLOWERF); + } + + /* IF */ + static NodeType *new_if(NodeType *expression, NodeType *instr) { + NodeType *node = new_op("if", OPR_IF, 2); + node->opr.op[0] = expression; + node->opr.op[1] = instr; + return node; + } + static void commit_if(NodeType *node) { + + char slab[1024]; + precommit_node(node->opr.op[0]); + + /* jzero.i */ + sprintf(slab, "|eif%d|", allocateLabel()); +#ifdef VERBOSE + printf("jzero.i %s %s\n", node->opr.op[0]->str, slab); +#endif + currentScanner->instr = instr_init(currentScanner, "jzero.i", INSTR_JZERO, 2); + commit_node(node->opr.op[0]); + instr_add_param(currentScanner->instr, slab, TYPE_LABEL); + + /* [... instrs of the if ...] */ + commit_node(node->opr.op[1]); + /* label */ +#ifdef VERBOSE + printf("label %s\n", slab); +#endif + currentScanner->instr = instr_init(currentScanner, "label", INSTR_LABEL, 1); + instr_add_param(currentScanner->instr, slab, TYPE_LABEL); + } + + /* BLOCK */ + static NodeType *new_block(NodeType *lastNode) { + NodeType *blk = new_op("block", OPR_BLOCK, 2); + blk->opr.op[0] = new_nop("start_of_block"); + blk->opr.op[1] = lastNode; + return blk; + } + static void commit_block(NodeType *node) { + commit_node(node->opr.op[0]->opr.next); + } + + /** **/ + + static NodeType *rootNode = 0; // TODO: reinitialiser a chaque compilation. + static NodeType *lastNode = 0; + static NodeType *gsl_append(NodeType *curNode) { + if (lastNode) + lastNode->opr.next = curNode; + lastNode = curNode; + while(lastNode->opr.next) lastNode = lastNode->opr.next; + if (rootNode == 0) + rootNode = curNode; + return curNode; + } + + static int lastLabel = 0; + int allocateLabel() { + return ++lastLabel; + } + void releaseLabel(int n) { + if (n == lastLabel) + lastLabel--; + } + + void gsl_commit_compilation() { + commit_node(rootNode); + rootNode = 0; + lastNode = 0; + } + + void precommit_node(NodeType *node) { + /* do here stuff for expression.. for exemple */ + switch(node->type) { + case OPR_NODE: + switch(node->opr.type) { + case OPR_ADD: precommit_add(node); break; + case OPR_MUL: precommit_mul(node); break; + case OPR_EQU: precommit_equ(node); break; + case OPR_LOW: precommit_low(node); break; + } + } + } + + void commit_node(NodeType *node) { + + if (node == 0) return; + + switch(node->type) { + case OPR_NODE: + switch(node->opr.type) { + case OPR_DECLARE_FLOAT: commit_float(node); break; + case OPR_DECLARE_INT: commit_int(node); break; + case OPR_SET: commit_set(node); break; + case OPR_IF: commit_if(node); break; + case OPR_BLOCK: commit_block(node); break; +#ifdef VERBOSE + case EMPTY_NODE: printf("NOP\n"); break; +#endif + } + + commit_node(node->opr.next); /* recursive for the moment, maybe better to do something iterative? */ + break; + + case PARAM_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_PARAM); break; + case VAR_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_VAR); break; + case CONST_INT_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_INTEGER); break; + case CONST_FLOAT_NODE: instr_add_param(currentScanner->instr, node->str, TYPE_FLOAT); break; + } + nodeFree(node); + } + + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG 0 +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE 0 +#endif + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) +#line 263 "goom_script_scanner.y" +typedef union YYSTYPE { + int intValue; + float floatValue; + char charValue; + char strValue[2048]; + NodeType *nPtr; + } YYSTYPE; +/* Line 191 of yacc.c. */ +#line 357 "goom_script_scanner.tab.c" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + + + +/* Copy the second part of user declarations. */ + + +/* Line 214 of yacc.c. */ +#line 369 "goom_script_scanner.tab.c" + +#if ! defined (yyoverflow) || YYERROR_VERBOSE + +/* The parser invokes alloca or malloc; define the necessary symbols. */ + +# if YYSTACK_USE_ALLOCA +# define YYSTACK_ALLOC alloca +# else +# ifndef YYSTACK_USE_ALLOCA +# if defined (alloca) || defined (_ALLOCA_H) +# define YYSTACK_ALLOC alloca +# else +# ifdef __GNUC__ +# define YYSTACK_ALLOC __builtin_alloca +# endif +# endif +# endif +# endif + +# ifdef YYSTACK_ALLOC + /* Pacify GCC's `empty if-body' warning. */ +# define YYSTACK_FREE(Ptr) do { /* empty */; } while (0) +# else +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +# define YYSTACK_ALLOC malloc +# define YYSTACK_FREE free +# endif +#endif /* ! defined (yyoverflow) || YYERROR_VERBOSE */ + + +#if (! defined (yyoverflow) \ + && (! defined (__cplusplus) \ + || (YYSTYPE_IS_TRIVIAL))) + +/* A type that is properly aligned for any stack member. */ +union yyalloc +{ + short yyss; + YYSTYPE yyvs; + }; + +/* The size of the maximum gap between one aligned stack and the next. */ +# define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1) + +/* The size of an array large to enough to hold all stacks, each with + N elements. */ +# define YYSTACK_BYTES(N) \ + ((N) * (sizeof (short) + sizeof (YYSTYPE)) \ + + YYSTACK_GAP_MAXIMUM) + +/* Copy COUNT objects from FROM to TO. The source and destination do + not overlap. */ +# ifndef YYCOPY +# if 1 < __GNUC__ +# define YYCOPY(To, From, Count) \ + __builtin_memcpy (To, From, (Count) * sizeof (*(From))) +# else +# define YYCOPY(To, From, Count) \ + do \ + { \ + register YYSIZE_T yyi; \ + for (yyi = 0; yyi < (Count); yyi++) \ + (To)[yyi] = (From)[yyi]; \ + } \ + while (0) +# endif +# endif + +/* Relocate STACK from its old location to the new one. The + local variables YYSIZE and YYSTACKSIZE give the old and new number of + elements in the stack, and YYPTR gives the new location of the + stack. Advance YYPTR to a properly aligned location for the next + stack. */ +# define YYSTACK_RELOCATE(Stack) \ + do \ + { \ + YYSIZE_T yynewbytes; \ + YYCOPY (&yyptr->Stack, Stack, yysize); \ + Stack = &yyptr->Stack; \ + yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \ + yyptr += yynewbytes / sizeof (*yyptr); \ + } \ + while (0) + +#endif + +#if defined (__STDC__) || defined (__cplusplus) + typedef signed char yysigned_char; +#else + typedef short yysigned_char; +#endif + +/* YYFINAL -- State number of the termination state. */ +#define YYFINAL 2 +/* YYLAST -- Last index in YYTABLE. */ +#define YYLAST 79 + +/* YYNTOKENS -- Number of terminals. */ +#define YYNTOKENS 19 +/* YYNNTS -- Number of nonterminals. */ +#define YYNNTS 7 +/* YYNRULES -- Number of rules. */ +#define YYNRULES 22 +/* YYNRULES -- Number of states. */ +#define YYNSTATES 44 + +/* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX. */ +#define YYUNDEFTOK 2 +#define YYMAXUTOK 263 + +#define YYTRANSLATE(YYX) \ + ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK) + +/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */ +static const unsigned char yytranslate[] = +{ + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 14, 15, 10, 9, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 13, + 8, 7, 2, 16, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 17, 2, 18, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, + 5, 6, 11, 12 +}; + +#if YYDEBUG +/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in + YYRHS. */ +static const unsigned char yyprhs[] = +{ + 0, 0, 3, 6, 7, 12, 18, 22, 26, 32, + 37, 39, 40, 42, 44, 48, 52, 56, 60, 64, + 66, 68, 70 +}; + +/* YYRHS -- A `-1'-separated list of the rules' RHS. */ +static const yysigned_char yyrhs[] = +{ + 20, 0, -1, 20, 21, -1, -1, 24, 7, 23, + 13, -1, 12, 5, 7, 23, 13, -1, 12, 5, + 13, -1, 11, 5, 13, -1, 14, 23, 15, 16, + 21, -1, 17, 22, 20, 18, -1, 13, -1, -1, + 24, -1, 25, -1, 23, 10, 23, -1, 23, 9, + 23, -1, 23, 7, 23, -1, 23, 8, 23, -1, + 14, 23, 15, -1, 5, -1, 6, -1, 4, -1, + 3, -1 +}; + +/* YYRLINE[YYN] -- source line where rule number YYN was defined. */ +static const unsigned short yyrline[] = +{ + 0, 284, 284, 285, 288, 289, 291, 292, 293, 294, + 295, 298, 301, 302, 303, 304, 305, 306, 307, 310, + 311, 314, 315 +}; +#endif + +#if YYDEBUG || YYERROR_VERBOSE +/* YYTNME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + First, the terminals, then, starting at YYNTOKENS, nonterminals. */ +static const char *const yytname[] = +{ + "$end", "error", "$undefined", "TYPE_INTEGER", "TYPE_FLOAT", "TYPE_VAR", + "TYPE_PARAM", "'='", "'<'", "'+'", "'*'", "INT_TK", "FLOAT_TK", "';'", + "'('", "')'", "'?'", "'{'", "'}'", "$accept", "gsl", "instruction", + "start_block", "expression", "variable", "constValue", 0 +}; +#endif + +# ifdef YYPRINT +/* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to + token YYLEX-NUM. */ +static const unsigned short yytoknum[] = +{ + 0, 256, 257, 258, 259, 260, 261, 61, 60, 43, + 42, 262, 263, 59, 40, 41, 63, 123, 125 +}; +# endif + +/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */ +static const unsigned char yyr1[] = +{ + 0, 19, 20, 20, 21, 21, 21, 21, 21, 21, + 21, 22, 23, 23, 23, 23, 23, 23, 23, 24, + 24, 25, 25 +}; + +/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */ +static const unsigned char yyr2[] = +{ + 0, 2, 2, 0, 4, 5, 3, 3, 5, 4, + 1, 0, 1, 1, 3, 3, 3, 3, 3, 1, + 1, 1, 1 +}; + +/* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state + STATE-NUM when YYTABLE doesn't specify something else to do. Zero + means the default is an error. */ +static const unsigned char yydefact[] = +{ + 3, 0, 1, 19, 20, 0, 0, 10, 0, 11, + 2, 0, 0, 0, 22, 21, 0, 0, 12, 13, + 3, 0, 7, 0, 6, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 18, 16, 17, 15, 14, 0, + 9, 4, 5, 8 +}; + +/* YYDEFGOTO[NTERM-NUM]. */ +static const yysigned_char yydefgoto[] = +{ + -1, 1, 10, 20, 17, 18, 19 +}; + +/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + STATE-NUM. */ +#define YYPACT_NINF -8 +static const yysigned_char yypact[] = +{ + -8, 1, -8, -8, -8, 0, 22, -8, 5, -8, + -8, -3, 8, 13, -8, -8, 5, 46, -8, -8, + -8, 5, -8, 5, -8, 50, 5, 5, 5, 5, + 15, 11, 59, 66, -8, -7, -7, 23, -8, 35, + -8, -8, -8, -8 +}; + +/* YYPGOTO[NTERM-NUM]. */ +static const yysigned_char yypgoto[] = +{ + -8, 14, -4, -8, 16, -1, -8 +}; + +/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If + positive, shift that token. If negative, reduce the rule which + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, syntax error. */ +#define YYTABLE_NINF -1 +static const unsigned char yytable[] = +{ + 11, 2, 28, 29, 21, 12, 3, 4, 14, 15, + 3, 4, 5, 6, 7, 8, 3, 4, 9, 16, + 23, 22, 5, 6, 7, 8, 24, 13, 9, 40, + 11, 39, 25, 29, 31, 43, 0, 32, 11, 33, + 3, 4, 35, 36, 37, 38, 5, 6, 7, 8, + 0, 0, 9, 26, 27, 28, 29, 26, 27, 28, + 29, 30, 0, 0, 0, 34, 26, 27, 28, 29, + 0, 0, 41, 26, 27, 28, 29, 0, 0, 42 +}; + +static const yysigned_char yycheck[] = +{ + 1, 0, 9, 10, 7, 5, 5, 6, 3, 4, + 5, 6, 11, 12, 13, 14, 5, 6, 17, 14, + 7, 13, 11, 12, 13, 14, 13, 5, 17, 18, + 31, 16, 16, 10, 20, 39, -1, 21, 39, 23, + 5, 6, 26, 27, 28, 29, 11, 12, 13, 14, + -1, -1, 17, 7, 8, 9, 10, 7, 8, 9, + 10, 15, -1, -1, -1, 15, 7, 8, 9, 10, + -1, -1, 13, 7, 8, 9, 10, -1, -1, 13 +}; + +/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing + symbol of state STATE-NUM. */ +static const unsigned char yystos[] = +{ + 0, 20, 0, 5, 6, 11, 12, 13, 14, 17, + 21, 24, 5, 5, 3, 4, 14, 23, 24, 25, + 22, 7, 13, 7, 13, 23, 7, 8, 9, 10, + 15, 20, 23, 23, 15, 23, 23, 23, 23, 16, + 18, 13, 13, 21 +}; + +#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__) +# define YYSIZE_T __SIZE_TYPE__ +#endif +#if ! defined (YYSIZE_T) && defined (size_t) +# define YYSIZE_T size_t +#endif +#if ! defined (YYSIZE_T) +# if defined (__STDC__) || defined (__cplusplus) +# include /* INFRINGES ON USER NAME SPACE */ +# define YYSIZE_T size_t +# endif +#endif +#if ! defined (YYSIZE_T) +# define YYSIZE_T unsigned int +#endif + +#define yyerrok (yyerrstatus = 0) +#define yyclearin (yychar = YYEMPTY) +#define YYEMPTY (-2) +#define YYEOF 0 + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrlab1 + + +/* Like YYERROR except do call yyerror. This remains here temporarily + to ease the transition to the new meaning of YYERROR, for GCC. + Once GCC version 2 has supplanted version 1, this can go. */ + +#define YYFAIL goto yyerrlab + +#define YYRECOVERING() (!!yyerrstatus) + +#define YYBACKUP(Token, Value) \ +do \ + if (yychar == YYEMPTY && yylen == 1) \ + { \ + yychar = (Token); \ + yylval = (Value); \ + yytoken = YYTRANSLATE (yychar); \ + YYPOPSTACK; \ + goto yybackup; \ + } \ + else \ + { \ + yyerror ("syntax error: cannot back up");\ + YYERROR; \ + } \ +while (0) + +#define YYTERROR 1 +#define YYERRCODE 256 + +/* YYLLOC_DEFAULT -- Compute the default location (before the actions + are run). */ + +#ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + Current.first_line = Rhs[1].first_line; \ + Current.first_column = Rhs[1].first_column; \ + Current.last_line = Rhs[N].last_line; \ + Current.last_column = Rhs[N].last_column; +#endif + +/* YYLEX -- calling `yylex' with the right arguments. */ + +#ifdef YYLEX_PARAM +# define YYLEX yylex (YYLEX_PARAM) +#else +# define YYLEX yylex () +#endif + +/* Enable debugging if requested. */ +#if YYDEBUG + +# ifndef YYFPRINTF +# include /* INFRINGES ON USER NAME SPACE */ +# define YYFPRINTF fprintf +# endif + +# define YYDPRINTF(Args) \ +do { \ + if (yydebug) \ + YYFPRINTF Args; \ +} while (0) + +# define YYDSYMPRINT(Args) \ +do { \ + if (yydebug) \ + yysymprint Args; \ +} while (0) + +# define YYDSYMPRINTF(Title, Token, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Token, Value); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (0) + +/*------------------------------------------------------------------. +| yy_stack_print -- Print the state stack from its BOTTOM up to its | +| TOP (cinluded). | +`------------------------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_stack_print (short *bottom, short *top) +#else +static void +yy_stack_print (bottom, top) + short *bottom; + short *top; +#endif +{ + YYFPRINTF (stderr, "Stack now"); + for (/* Nothing. */; bottom <= top; ++bottom) + YYFPRINTF (stderr, " %d", *bottom); + YYFPRINTF (stderr, "\n"); +} + +# define YY_STACK_PRINT(Bottom, Top) \ +do { \ + if (yydebug) \ + yy_stack_print ((Bottom), (Top)); \ +} while (0) + + +/*------------------------------------------------. +| Report that the YYRULE is going to be reduced. | +`------------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yy_reduce_print (int yyrule) +#else +static void +yy_reduce_print (yyrule) + int yyrule; +#endif +{ + int yyi; + unsigned int yylineno = yyrline[yyrule]; + YYFPRINTF (stderr, "Reducing stack by rule %d (line %u), ", + yyrule - 1, yylineno); + /* Print the symbols being reduced, and their result. */ + for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + YYFPRINTF (stderr, "%s ", yytname [yyrhs[yyi]]); + YYFPRINTF (stderr, "-> %s\n", yytname [yyr1[yyrule]]); +} + +# define YY_REDUCE_PRINT(Rule) \ +do { \ + if (yydebug) \ + yy_reduce_print (Rule); \ +} while (0) + +/* Nonzero means print parse trace. It is left uninitialized so that + multiple parsers can coexist. */ +int yydebug; +#else /* !YYDEBUG */ +# define YYDPRINTF(Args) +# define YYDSYMPRINT(Args) +# define YYDSYMPRINTF(Title, Token, Value, Location) +# define YY_STACK_PRINT(Bottom, Top) +# define YY_REDUCE_PRINT(Rule) +#endif /* !YYDEBUG */ + + +/* YYINITDEPTH -- initial size of the parser's stacks. */ +#ifndef YYINITDEPTH +# define YYINITDEPTH 200 +#endif + +/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only + if the built-in stack extension method is used). + + Do not make this value too large; the results are undefined if + SIZE_MAX < YYSTACK_BYTES (YYMAXDEPTH) + evaluated with infinite-precision integer arithmetic. */ + +#if YYMAXDEPTH == 0 +# undef YYMAXDEPTH +#endif + +#ifndef YYMAXDEPTH +# define YYMAXDEPTH 10000 +#endif + + + +#if YYERROR_VERBOSE + +# ifndef yystrlen +# if defined (__GLIBC__) && defined (_STRING_H) +# define yystrlen strlen +# else +/* Return the length of YYSTR. */ +static YYSIZE_T +# if defined (__STDC__) || defined (__cplusplus) +yystrlen (const char *yystr) +# else +yystrlen (yystr) + const char *yystr; +# endif +{ + register const char *yys = yystr; + + while (*yys++ != '\0') + continue; + + return yys - yystr - 1; +} +# endif +# endif + +# ifndef yystpcpy +# if defined (__GLIBC__) && defined (_STRING_H) && defined (_GNU_SOURCE) +# define yystpcpy stpcpy +# else +/* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in + YYDEST. */ +static char * +# if defined (__STDC__) || defined (__cplusplus) +yystpcpy (char *yydest, const char *yysrc) +# else +yystpcpy (yydest, yysrc) + char *yydest; + const char *yysrc; +# endif +{ + register char *yyd = yydest; + register const char *yys = yysrc; + + while ((*yyd++ = *yys++) != '\0') + continue; + + return yyd - 1; +} +# endif +# endif + +#endif /* !YYERROR_VERBOSE */ + + + +#if YYDEBUG +/*--------------------------------. +| Print this symbol on YYOUTPUT. | +`--------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yysymprint (FILE *yyoutput, int yytype, YYSTYPE *yyvaluep) +#else +static void +yysymprint (yyoutput, yytype, yyvaluep) + FILE *yyoutput; + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + if (yytype < YYNTOKENS) + { + YYFPRINTF (yyoutput, "token %s (", yytname[yytype]); +# ifdef YYPRINT + YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep); +# endif + } + else + YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]); + + switch (yytype) + { + default: + break; + } + YYFPRINTF (yyoutput, ")"); +} + +#endif /* ! YYDEBUG */ +/*-----------------------------------------------. +| Release the memory associated to this symbol. | +`-----------------------------------------------*/ + +#if defined (__STDC__) || defined (__cplusplus) +static void +yydestruct (int yytype, YYSTYPE *yyvaluep) +#else +static void +yydestruct (yytype, yyvaluep) + int yytype; + YYSTYPE *yyvaluep; +#endif +{ + /* Pacify ``unused variable'' warnings. */ + (void) yyvaluep; + + switch (yytype) + { + + default: + break; + } +} + + +/* Prevent warnings from -Wmissing-prototypes. */ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM); +# else +int yyparse (); +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int yyparse (void); +#else +int yyparse (); +#endif +#endif /* ! YYPARSE_PARAM */ + + + +/* The lookahead symbol. */ +int yychar; + +/* The semantic value of the lookahead symbol. */ +YYSTYPE yylval; + +/* Number of syntax errors so far. */ +int yynerrs; + + + +/*----------. +| yyparse. | +`----------*/ + +#ifdef YYPARSE_PARAM +# if defined (__STDC__) || defined (__cplusplus) +int yyparse (void *YYPARSE_PARAM) +# else +int yyparse (YYPARSE_PARAM) + void *YYPARSE_PARAM; +# endif +#else /* ! YYPARSE_PARAM */ +#if defined (__STDC__) || defined (__cplusplus) +int +yyparse (void) +#else +int +yyparse () + +#endif +#endif +{ + + register int yystate; + register int yyn; + int yyresult; + /* Number of tokens to shift before error messages enabled. */ + int yyerrstatus; + /* Lookahead token as an internal (translated) token number. */ + int yytoken = 0; + + /* Three stacks and their tools: + `yyss': related to states, + `yyvs': related to semantic values, + `yyls': related to locations. + + Refer to the stacks thru separate pointers, to allow yyoverflow + to reallocate them elsewhere. */ + + /* The state stack. */ + short yyssa[YYINITDEPTH]; + short *yyss = yyssa; + register short *yyssp; + + /* The semantic value stack. */ + YYSTYPE yyvsa[YYINITDEPTH]; + YYSTYPE *yyvs = yyvsa; + register YYSTYPE *yyvsp; + + + +#define YYPOPSTACK (yyvsp--, yyssp--) + + YYSIZE_T yystacksize = YYINITDEPTH; + + /* The variables used to return semantic value and location from the + action routines. */ + YYSTYPE yyval; + + + /* When reducing, the number of symbols on the RHS of the reduced + rule. */ + int yylen; + + YYDPRINTF ((stderr, "Starting parse\n")); + + yystate = 0; + yyerrstatus = 0; + yynerrs = 0; + yychar = YYEMPTY; /* Cause a token to be read. */ + + /* Initialize stack pointers. + Waste one element of value and location stack + so that they stay on the same level as the state stack. + The wasted elements are never initialized. */ + + yyssp = yyss; + yyvsp = yyvs; + + goto yysetstate; + +/*------------------------------------------------------------. +| yynewstate -- Push a new state, which is found in yystate. | +`------------------------------------------------------------*/ + yynewstate: + /* In all cases, when you get here, the value and location stacks + have just been pushed. so pushing a state here evens the stacks. + */ + yyssp++; + + yysetstate: + *yyssp = yystate; + + if (yyss + yystacksize - 1 <= yyssp) + { + /* Get the current used size of the three stacks, in elements. */ + YYSIZE_T yysize = yyssp - yyss + 1; + +#ifdef yyoverflow + { + /* Give user a chance to reallocate the stack. Use copies of + these so that the &'s don't force the real ones into + memory. */ + YYSTYPE *yyvs1 = yyvs; + short *yyss1 = yyss; + + + /* Each stack pointer address is followed by the size of the + data in use in that stack, in bytes. This used to be a + conditional around just the two extra args, but that might + be undefined if yyoverflow is a macro. */ + yyoverflow ("parser stack overflow", + &yyss1, yysize * sizeof (*yyssp), + &yyvs1, yysize * sizeof (*yyvsp), + + &yystacksize); + + yyss = yyss1; + yyvs = yyvs1; + } +#else /* no yyoverflow */ +# ifndef YYSTACK_RELOCATE + goto yyoverflowlab; +# else + /* Extend the stack our own way. */ + if (YYMAXDEPTH <= yystacksize) + goto yyoverflowlab; + yystacksize *= 2; + if (YYMAXDEPTH < yystacksize) + yystacksize = YYMAXDEPTH; + + { + short *yyss1 = yyss; + union yyalloc *yyptr = + (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize)); + if (! yyptr) + goto yyoverflowlab; + YYSTACK_RELOCATE (yyss); + YYSTACK_RELOCATE (yyvs); + +# undef YYSTACK_RELOCATE + if (yyss1 != yyssa) + YYSTACK_FREE (yyss1); + } +# endif +#endif /* no yyoverflow */ + + yyssp = yyss + yysize - 1; + yyvsp = yyvs + yysize - 1; + + + YYDPRINTF ((stderr, "Stack size increased to %lu\n", + (unsigned long int) yystacksize)); + + if (yyss + yystacksize - 1 <= yyssp) + YYABORT; + } + + YYDPRINTF ((stderr, "Entering state %d\n", yystate)); + + goto yybackup; + +/*-----------. +| yybackup. | +`-----------*/ +yybackup: + +/* Do appropriate processing given the current state. */ +/* Read a lookahead token if we need one and don't already have one. */ +/* yyresume: */ + + /* First try to decide what to do without reference to lookahead token. */ + + yyn = yypact[yystate]; + if (yyn == YYPACT_NINF) + goto yydefault; + + /* Not known => get a lookahead token if don't already have one. */ + + /* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */ + if (yychar == YYEMPTY) + { + YYDPRINTF ((stderr, "Reading a token: ")); + yychar = YYLEX; + } + + if (yychar <= YYEOF) + { + yychar = yytoken = YYEOF; + YYDPRINTF ((stderr, "Now at end of input.\n")); + } + else + { + yytoken = YYTRANSLATE (yychar); + YYDSYMPRINTF ("Next token is", yytoken, &yylval, &yylloc); + } + + /* If the proper action on seeing token YYTOKEN is to reduce or to + detect an error, take that action. */ + yyn += yytoken; + if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken) + goto yydefault; + yyn = yytable[yyn]; + if (yyn <= 0) + { + if (yyn == 0 || yyn == YYTABLE_NINF) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + if (yyn == YYFINAL) + YYACCEPT; + + /* Shift the lookahead token. */ + YYDPRINTF ((stderr, "Shifting token %s, ", yytname[yytoken])); + + /* Discard the token being shifted unless it is eof. */ + if (yychar != YYEOF) + yychar = YYEMPTY; + + *++yyvsp = yylval; + + + /* Count tokens shifted since error; after three, turn off error + status. */ + if (yyerrstatus) + yyerrstatus--; + + yystate = yyn; + goto yynewstate; + + +/*-----------------------------------------------------------. +| yydefault -- do the default action for the current state. | +`-----------------------------------------------------------*/ +yydefault: + yyn = yydefact[yystate]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + +/*-----------------------------. +| yyreduce -- Do a reduction. | +`-----------------------------*/ +yyreduce: + /* yyn is the number of a rule to reduce with. */ + yylen = yyr2[yyn]; + + /* If YYLEN is nonzero, implement the default value of the action: + `$$ = $1'. + + Otherwise, the following line sets YYVAL to garbage. + This behavior is undocumented and Bison + users should not rely upon it. Assigning to YYVAL + unconditionally makes the parser a bit smaller, and it avoids a + GCC warning that YYVAL may be used uninitialized. */ + yyval = yyvsp[1-yylen]; + + + YY_REDUCE_PRINT (yyn); + switch (yyn) + { + case 2: +#line 284 "goom_script_scanner.y" + { gsl_append(yyvsp[0].nPtr); } + break; + + case 4: +#line 288 "goom_script_scanner.y" + { yyval.nPtr = new_set(yyvsp[-3].nPtr,yyvsp[-1].nPtr); } + break; + + case 5: +#line 289 "goom_script_scanner.y" + { yyval.nPtr = new_float_decl(new_var(yyvsp[-3].strValue)); + yyval.nPtr->opr.next = new_set(new_var(yyvsp[-3].strValue), yyvsp[-1].nPtr); } + break; + + case 6: +#line 291 "goom_script_scanner.y" + { yyval.nPtr = new_float_decl(new_var(yyvsp[-1].strValue)); } + break; + + case 7: +#line 292 "goom_script_scanner.y" + { yyval.nPtr = new_int_decl(new_var(yyvsp[-1].strValue)); } + break; + + case 8: +#line 293 "goom_script_scanner.y" + { yyval.nPtr = new_if(yyvsp[-3].nPtr,yyvsp[0].nPtr); } + break; + + case 9: +#line 294 "goom_script_scanner.y" + { lastNode = yyvsp[-2].nPtr->opr.op[1]; yyval.nPtr=yyvsp[-2].nPtr; } + break; + + case 10: +#line 295 "goom_script_scanner.y" + { yyval.nPtr = new_nop("nop"); } + break; + + case 11: +#line 298 "goom_script_scanner.y" + { yyval.nPtr = new_block(lastNode); lastNode = yyval.nPtr->opr.op[0]; } + break; + + case 12: +#line 301 "goom_script_scanner.y" + { yyval.nPtr = yyvsp[0].nPtr; } + break; + + case 13: +#line 302 "goom_script_scanner.y" + { yyval.nPtr = yyvsp[0].nPtr; } + break; + + case 14: +#line 303 "goom_script_scanner.y" + { yyval.nPtr = new_mul(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 15: +#line 304 "goom_script_scanner.y" + { yyval.nPtr = new_add(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 16: +#line 305 "goom_script_scanner.y" + { yyval.nPtr = new_equ(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 17: +#line 306 "goom_script_scanner.y" + { yyval.nPtr = new_low(yyvsp[-2].nPtr,yyvsp[0].nPtr); } + break; + + case 18: +#line 307 "goom_script_scanner.y" + { yyval.nPtr = yyvsp[-1].nPtr; } + break; + + case 19: +#line 310 "goom_script_scanner.y" + { yyval.nPtr = new_var(yyvsp[0].strValue); } + break; + + case 20: +#line 311 "goom_script_scanner.y" + { yyval.nPtr = new_param(yyvsp[0].strValue); } + break; + + case 21: +#line 314 "goom_script_scanner.y" + { yyval.nPtr = new_constFloat(yyvsp[0].strValue); } + break; + + case 22: +#line 315 "goom_script_scanner.y" + { yyval.nPtr = new_constInt(yyvsp[0].strValue); } + break; + + + } + +/* Line 999 of yacc.c. */ +#line 1376 "goom_script_scanner.tab.c" + + yyvsp -= yylen; + yyssp -= yylen; + + + YY_STACK_PRINT (yyss, yyssp); + + *++yyvsp = yyval; + + + /* Now `shift' the result of the reduction. Determine what state + that goes to, based on the state we popped back to and the rule + number reduced by. */ + + yyn = yyr1[yyn]; + + yystate = yypgoto[yyn - YYNTOKENS] + *yyssp; + if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp) + yystate = yytable[yystate]; + else + yystate = yydefgoto[yyn - YYNTOKENS]; + + goto yynewstate; + + +/*------------------------------------. +| yyerrlab -- here on detecting error | +`------------------------------------*/ +yyerrlab: + /* If not already recovering from an error, report this error. */ + if (!yyerrstatus) + { + ++yynerrs; +#if YYERROR_VERBOSE + yyn = yypact[yystate]; + + if (YYPACT_NINF < yyn && yyn < YYLAST) + { + YYSIZE_T yysize = 0; + int yytype = YYTRANSLATE (yychar); + char *yymsg; + int yyx, yycount; + + yycount = 0; + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. */ + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + yysize += yystrlen (yytname[yyx]) + 15, yycount++; + yysize += yystrlen ("syntax error, unexpected ") + 1; + yysize += yystrlen (yytname[yytype]); + yymsg = (char *) YYSTACK_ALLOC (yysize); + if (yymsg != 0) + { + char *yyp = yystpcpy (yymsg, "syntax error, unexpected "); + yyp = yystpcpy (yyp, yytname[yytype]); + + if (yycount < 5) + { + yycount = 0; + for (yyx = yyn < 0 ? -yyn : 0; + yyx < (int) (sizeof (yytname) / sizeof (char *)); + yyx++) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) + { + const char *yyq = ! yycount ? ", expecting " : " or "; + yyp = yystpcpy (yyp, yyq); + yyp = yystpcpy (yyp, yytname[yyx]); + yycount++; + } + } + yyerror (yymsg); + YYSTACK_FREE (yymsg); + } + else + yyerror ("syntax error; also virtual memory exhausted"); + } + else +#endif /* YYERROR_VERBOSE */ + yyerror ("syntax error"); + } + + + + if (yyerrstatus == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + /* Return failure if at end of input. */ + if (yychar == YYEOF) + { + /* Pop the error token. */ + YYPOPSTACK; + /* Pop the rest of the stack. */ + while (yyss < yyssp) + { + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[*yyssp], yyvsp); + YYPOPSTACK; + } + YYABORT; + } + + YYDSYMPRINTF ("Error: discarding", yytoken, &yylval, &yylloc); + yydestruct (yytoken, &yylval); + yychar = YYEMPTY; + + } + + /* Else will try to reuse lookahead token after shifting the error + token. */ + goto yyerrlab1; + + +/*----------------------------------------------------. +| yyerrlab1 -- error raised explicitly by an action. | +`----------------------------------------------------*/ +yyerrlab1: + yyerrstatus = 3; /* Each real token shifted decrements this. */ + + for (;;) + { + yyn = yypact[yystate]; + if (yyn != YYPACT_NINF) + { + yyn += YYTERROR; + if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR) + { + yyn = yytable[yyn]; + if (0 < yyn) + break; + } + } + + /* Pop the current state because it cannot handle the error token. */ + if (yyssp == yyss) + YYABORT; + + YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp); + yydestruct (yystos[yystate], yyvsp); + yyvsp--; + yystate = *--yyssp; + + YY_STACK_PRINT (yyss, yyssp); + } + + if (yyn == YYFINAL) + YYACCEPT; + + YYDPRINTF ((stderr, "Shifting error token, ")); + + *++yyvsp = yylval; + + + yystate = yyn; + goto yynewstate; + + +/*-------------------------------------. +| yyacceptlab -- YYACCEPT comes here. | +`-------------------------------------*/ +yyacceptlab: + yyresult = 0; + goto yyreturn; + +/*-----------------------------------. +| yyabortlab -- YYABORT comes here. | +`-----------------------------------*/ +yyabortlab: + yyresult = 1; + goto yyreturn; + +#ifndef yyoverflow +/*----------------------------------------------. +| yyoverflowlab -- parser overflow comes here. | +`----------------------------------------------*/ +yyoverflowlab: + yyerror ("parser stack overflow"); + yyresult = 2; + /* Fall through. */ +#endif + +yyreturn: +#ifndef yyoverflow + if (yyss != yyssa) + YYSTACK_FREE (yyss); +#endif + return yyresult; +} + + +#line 318 "goom_script_scanner.y" + + + NodeType *nodeNew(const char *str, int type) { + NodeType *node = (NodeType*)malloc(sizeof(NodeType)); + node->type = type; + node->str = (char*)malloc(strlen(str)+1); + strcpy(node->str, str); + return node; + } + + void nodeFreeInternals(NodeType *node) { + free(node->str); + } + + void nodeFree(NodeType *node) { + nodeFreeInternals(node); + free(node); + } + + NodeType *new_constInt(const char *str) { + NodeType *node = nodeNew(str, CONST_INT_NODE); + node->constInt.val = atoi(str); + return node; + } + + NodeType *new_constFloat(const char *str) { + NodeType *node = nodeNew(str, CONST_FLOAT_NODE); + node->constFloat.val = atof(str); + return node; + } + + NodeType *new_var(const char *str) { + NodeType *node = nodeNew(str, VAR_NODE); + return node; + } + + NodeType *new_param(const char *str) { + NodeType *node = nodeNew(str, PARAM_NODE); + return node; + } + + NodeType *new_nop(const char *str) { + NodeType *node = new_op(str, EMPTY_NODE, 0); + return node; + } + + NodeType *new_op(const char *str, int type, int nbOp) { + int i; + NodeType *node = nodeNew(str, OPR_NODE); + node->opr.next = 0; + node->opr.type = type; + node->opr.nbOp = nbOp; + for (i=0;iopr.op[i] = 0; + return node; + } + +void yyerror(char *str) { + fprintf(stderr, "GSL ERROR: %s\n", str); +} + + diff --git a/src/post/goom/goom_script_scanner.tab.h b/src/post/goom/goom_script_scanner.tab.h new file mode 100644 index 000000000..6b9a2e04a --- /dev/null +++ b/src/post/goom/goom_script_scanner.tab.h @@ -0,0 +1,69 @@ +/* A Bison parser, made by GNU Bison 1.875a. */ + +/* Skeleton parser for Yacc-like parsing with Bison, + Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003 Free Software Foundation, Inc. + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, 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 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. */ + +/* As a special exception, when this file is copied by Bison into a + Bison output file, you may use that output file without restriction. + This special exception was added by the Free Software Foundation + in version 1.24 of Bison. */ + +/* Tokens. */ +#ifndef YYTOKENTYPE +# define YYTOKENTYPE + /* Put the tokens into the symbol table, so that GDB and other debuggers + know about them. */ + enum yytokentype { + TYPE_INTEGER = 258, + TYPE_FLOAT = 259, + TYPE_VAR = 260, + TYPE_PARAM = 261, + INT_TK = 262, + FLOAT_TK = 263 + }; +#endif +#define TYPE_INTEGER 258 +#define TYPE_FLOAT 259 +#define TYPE_VAR 260 +#define TYPE_PARAM 261 +#define INT_TK 262 +#define FLOAT_TK 263 + + + + +#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) +#line 263 "goom_script_scanner.y" +typedef union YYSTYPE { + int intValue; + float floatValue; + char charValue; + char strValue[2048]; + NodeType *nPtr; + } YYSTYPE; +/* Line 1240 of yacc.c. */ +#line 61 "goom_script_scanner.tab.h" +# define yystype YYSTYPE /* obsolescent; will be withdrawn */ +# define YYSTYPE_IS_DECLARED 1 +# define YYSTYPE_IS_TRIVIAL 1 +#endif + +extern YYSTYPE yylval; + + + diff --git a/src/post/goom/goom_tools.c b/src/post/goom/goom_tools.c new file mode 100644 index 000000000..45bbca3f0 --- /dev/null +++ b/src/post/goom/goom_tools.c @@ -0,0 +1,21 @@ +#include "goom_tools.h" +#include + +GoomRandom *goom_random_init(int i) { + GoomRandom *grandom = (GoomRandom*)malloc(sizeof(GoomRandom)); + srand (i); + grandom->pos = 1; + goom_random_update_array(grandom, GOOM_NB_RAND); + return grandom; +} + +void goom_random_free(GoomRandom *grandom) { + free(grandom); +} + +void goom_random_update_array(GoomRandom *grandom, int numberOfValuesToChange) { + while (numberOfValuesToChange > 0) { + grandom->array[grandom->pos++] = rand() / 127; + numberOfValuesToChange--; + } +} diff --git a/src/post/goom/goom_tools.h b/src/post/goom/goom_tools.h index cb2148e31..9ee0e8082 100644 --- a/src/post/goom/goom_tools.h +++ b/src/post/goom/goom_tools.h @@ -1,33 +1,33 @@ -#ifndef _GOOMTOOLS_H -#define _GOOMTOOLS_H +#ifndef _GOOM_TOOLS_H +#define _GOOM_TOOLS_H -#define NB_RAND 0x10000 +/** + * Random number generator wrapper for faster random number. + */ -/* in graphic.c */ -extern int *rand_tab; -static unsigned short rand_pos; +#define GOOM_NB_RAND 0x10000 -#define RAND_INIT(i) \ - srand (i) ;\ - if (!rand_tab) rand_tab = (int *) malloc (NB_RAND * sizeof(int)) ;\ - rand_pos = 1 ;\ - while (rand_pos != 0) rand_tab [rand_pos++] = rand () ; +typedef struct _GOOM_RANDOM { + int array[GOOM_NB_RAND]; + unsigned short pos; +} GoomRandom; +GoomRandom *goom_random_init(int i); +void goom_random_free(GoomRandom *grandom); -static inline int RAND(void) { - ++rand_pos; - return rand_tab[rand_pos]; +inline static int goom_random(GoomRandom *grandom) { + + grandom->pos++; /* works because pos is an unsigned short */ + return grandom->array[grandom->pos]; } -#define RAND_CLOSE()\ - free (rand_tab);\ - rand_tab = 0; +inline static int goom_irand(GoomRandom *grandom, int i) { + grandom->pos++; + return grandom->array[grandom->pos] % i; +} -//#define iRAND(i) ((guint32)((float)i * RAND()/RAND_MAX)) -#define iRAND(i) (RAND()%i) - -//inline unsigned int RAND(void); -//inline unsigned int iRAND(int i); +/* called to change the specified number of value in the array, so that the array does not remain the same*/ +void goom_random_update_array(GoomRandom *grandom, int numberOfValuesToChange); #endif diff --git a/src/post/goom/goom_typedefs.h b/src/post/goom/goom_typedefs.h new file mode 100644 index 000000000..0abbb6b1c --- /dev/null +++ b/src/post/goom/goom_typedefs.h @@ -0,0 +1,12 @@ +#ifndef _GOOM_TYPEDEFS_H +#define _GOOM_TYPEDEFS_H + +typedef struct _PLUGIN_INFO PluginInfo; +typedef struct _SOUND_INFO SoundInfo; +typedef struct _GMLINE GMLine; +typedef struct _GMUNITPOINTER GMUnitPointer; +typedef struct _ZOOM_FILTER_DATA ZoomFilterData; +typedef struct _VISUAL_FX VisualFX; +typedef struct _GoomScriptScanner GoomScriptScanner; + +#endif diff --git a/src/post/goom/goom_visual_fx.h b/src/post/goom/goom_visual_fx.h new file mode 100644 index 000000000..6cc798350 --- /dev/null +++ b/src/post/goom/goom_visual_fx.h @@ -0,0 +1,26 @@ +#ifndef _GOOM_VISUAL_FX_H +#define _GOOM_VISUAL_FX_H + +/** + * File created on 2003-05-21 by Jeko. + * (c)2003, JC Hoelt for iOS-software. + * + * LGPL Licence. + * If you use this file on a visual program, + * please make my name being visible on it. + */ + +#include "goom_config_param.h" +#include "goom_graphic.h" +#include "goom_typedefs.h" + +struct _VISUAL_FX { + void (*init) (struct _VISUAL_FX *_this); + void (*free) (struct _VISUAL_FX *_this); + void (*apply) (struct _VISUAL_FX *_this, Pixel *src, Pixel *dest, PluginInfo *info); + void *fx_data; + + PluginParameters *params; +}; + +#endif diff --git a/src/post/goom/graphic.c b/src/post/goom/graphic.c index 8ff08ff14..2ee71a6dd 100644 --- a/src/post/goom/graphic.c +++ b/src/post/goom/graphic.c @@ -1,30 +1,10 @@ -#include "graphic.h" +#include "goom_graphic.h" const Color BLACK = { 0, 0, 0 }; const Color WHITE = { 0xff, 0xff, 0xff }; -const Color RED = { 0xff, 0, 0 }; -const Color GREEN = { 0, 0xff, 0 }; -const Color BLUE = { 0, 0, 0xff }; +const Color RED = { 0xff, 0x05, 0x05 }; +const Color GREEN = { 0x05, 0xff, 0x05 }; +const Color BLUE = { 0x05, 0x05, 0xff }; const Color YELLOW = { 0xff, 0xff, 0x33 }; -const Color ORANGE = { 0xff, 0xcc, 0x00 }; -const Color VIOLET = { 0x55, 0x00, 0xff }; - -unsigned int SIZE; -unsigned int HEIGHT; -unsigned int WIDTH; - -int *rand_tab = 0; -//unsigned short int rand_pos = 0; -/* -inline unsigned int RAND(void) -{ - rand_pos++; - return rand_tab[rand_pos]; -} - -inline unsigned int iRAND(int i) -{ - rand_pos++; - return (rand_tab[rand_pos])%i; -} -*/ +const Color ORANGE = { 0xff, 0xcc, 0x05 }; +const Color VIOLET = { 0x55, 0x05, 0xff }; diff --git a/src/post/goom/graphic.h b/src/post/goom/graphic.h deleted file mode 100644 index e66ba9e49..000000000 --- a/src/post/goom/graphic.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef GRAPHIC_H -#define GRAPHIC_H - -typedef unsigned int Uint; - -typedef struct -{ - unsigned short r, v, b; -} -Color; - -extern const Color BLACK; -extern const Color WHITE; -extern const Color RED; -extern const Color BLUE; -extern const Color GREEN; -extern const Color YELLOW; -extern const Color ORANGE; -extern const Color VIOLET; - -inline void setPixelRGB (Uint * buffer, Uint x, Uint y, Color c); -inline void getPixelRGB (Uint * buffer, Uint x, Uint y, Color * c); - -#endif /* GRAPHIC_H */ diff --git a/src/post/goom/ifs.c b/src/post/goom/ifs.c index 3ad1e3478..a955b95d2 100644 --- a/src/post/goom/ifs.c +++ b/src/post/goom/ifs.c @@ -1,9 +1,6 @@ -/* -*- Mode: C; tab-width: 4 -*- */ -/* ifs --- modified iterated functions system */ - -#if !defined( lint ) && !defined( SABER ) -static const char sccsid[] = "@(#)ifs.c 5.00 2002/04/11 baffe"; -#endif +/* + * ifs.c --- modified iterated functions system for goom. + */ /*- * Copyright (c) 1997 by Massimino Pascal @@ -26,20 +23,36 @@ static const char sccsid[] = "@(#)ifs.c 5.00 2002/04/11 baffe"; * When shown ifs, Diana Rose (4 years old) said, "It looks like dancing." * * Revision History: - * 11-Apr-2002: Make ifs.c system-indendant. (ifs.h added) + * 13-Dec-2003: Added some goom specific stuffs (to make ifs a VisualFX). + * 11-Apr-2002: jeko@ios-software.com: Make ifs.c system-indendant. (ifs.h added) * 01-Nov-2000: Allocation checks * 10-May-1997: jwz@jwz.org: turned into a standalone program. * Made it render into an offscreen bitmap and then copy * that onto the screen, to reduce flicker. */ -//#ifdef STANDALONE +/* #ifdef STANDALONE */ #include #include #include +#include "goom_config.h" + +#ifdef HAVE_MMX +#include "mmx.h" +#endif + +#include "goom_graphic.h" #include "ifs.h" +#include "goom_tools.h" + +typedef struct _ifsPoint +{ + gint32 x, y; +} +IFSPoint; + #define MODE_ifs @@ -51,35 +64,13 @@ static const char sccsid[] = "@(#)ifs.c 5.00 2002/04/11 baffe"; #define ifs_opts xlockmore_opts #define DEFAULTS "*delay: 20000 \n" \ - "*ncolors: 100 \n" +"*ncolors: 100 \n" #define SMOOTH_COLORS -//#include "xlockmore.h" /* in xscreensaver distribution */ -//#else /* STANDALONE */ -//#include "xlock.h" /* in xlockmore distribution */ -//#endif /* STANDALONE */ - -//#ifdef MODE_ifs - -//ModeSpecOpt ifs_opts = -//{0, (XrmOptionDescRec *) NULL, 0, (argtype *) NULL, (OptionStruct *) NULL}; - -//#ifdef USE_MODULES -//ModStruct ifs_description = -//{"ifs", "init_ifs", "draw_ifs", "release_ifs", -// "init_ifs", "init_ifs", (char *) NULL, &ifs_opts, -// 1000, 1, 1, 1, 64, 1.0, "", -// "Shows a modified iterated function system", 0, NULL}; - -//#endif - -#include "goom_tools.h" - -#define LRAND() ((long) (RAND() & 0x7fffffff)) +#define LRAND() ((long) (goom_random(goomInfo->gRandom) & 0x7fffffff)) #define NRAND(n) ((int) (LRAND() % (n))) -#define MAXRAND (2147483648.0) /* unsigned 1<<31 as a * * - * * float */ +#define MAXRAND (2147483648.0/127.0) /* unsigned 1<<31 / 127.0 (cf goom_tools) as a float */ /*****************************************************/ @@ -102,7 +93,7 @@ typedef int F_PT; /* PREVIOUS VALUE #define MAX_SIMI 6 -* settings for a PC 120Mhz... * + * settings for a PC 120Mhz... * #define MAX_DEPTH_2 10 #define MAX_DEPTH_3 6 #define MAX_DEPTH_4 4 @@ -137,21 +128,23 @@ struct Fractal_Struct int Cur_Pt, Max_Pt; IFSPoint *Buffer1, *Buffer2; -// Pixmap dbuf; -// GC dbuf_gc; }; -static FRACTAL *Root = (FRACTAL *) NULL, *Cur_F; +typedef struct _IFS_DATA { + FRACTAL *Root; + FRACTAL *Cur_F; -/* Used by the Trace recursive method */ -IFSPoint *Buf; -static int Cur_Pt; + /* Used by the Trace recursive method */ + IFSPoint *Buf; + int Cur_Pt; + int initalized; +} IfsData; /*****************************************************/ static DBL -Gauss_Rand (DBL c, DBL A, DBL S) +Gauss_Rand (PluginInfo *goomInfo, DBL c, DBL A, DBL S) { DBL y; @@ -163,7 +156,7 @@ Gauss_Rand (DBL c, DBL A, DBL S) } static DBL -Half_Gauss_Rand (DBL c, DBL A, DBL S) +Half_Gauss_Rand (PluginInfo *goomInfo, DBL c, DBL A, DBL S) { DBL y; @@ -173,15 +166,15 @@ Half_Gauss_Rand (DBL c, DBL A, DBL S) } static void -Random_Simis (FRACTAL * F, SIMI * Cur, int i) +Random_Simis (PluginInfo *goomInfo, FRACTAL * F, SIMI * Cur, int i) { while (i--) { - Cur->c_x = Gauss_Rand (0.0, .8, 4.0); - Cur->c_y = Gauss_Rand (0.0, .8, 4.0); - Cur->r = Gauss_Rand (F->r_mean, F->dr_mean, 3.0); - Cur->r2 = Half_Gauss_Rand (0.0, F->dr2_mean, 2.0); - Cur->A = Gauss_Rand (0.0, 360.0, 4.0) * (M_PI / 180.0); - Cur->A2 = Gauss_Rand (0.0, 360.0, 4.0) * (M_PI / 180.0); + Cur->c_x = Gauss_Rand (goomInfo, 0.0, .8, 4.0); + Cur->c_y = Gauss_Rand (goomInfo, 0.0, .8, 4.0); + Cur->r = Gauss_Rand (goomInfo, F->r_mean, F->dr_mean, 3.0); + Cur->r2 = Half_Gauss_Rand (goomInfo, 0.0, F->dr2_mean, 2.0); + Cur->A = Gauss_Rand (goomInfo, 0.0, 360.0, 4.0) * (M_PI / 180.0); + Cur->A2 = Gauss_Rand (goomInfo, 0.0, 360.0, 4.0) * (M_PI / 180.0); Cur++; } } @@ -209,75 +202,71 @@ free_ifs (FRACTAL * Fractal) /***************************************************************/ void -init_ifs (int width, int height) +init_ifs (PluginInfo *goomInfo, IfsData *data) { int i; FRACTAL *Fractal; + int width = goomInfo->screen.width; + int height = goomInfo->screen.height; -// printf ("initing ifs\n"); - - if (Root == NULL) { - Root = (FRACTAL *) malloc (sizeof (FRACTAL)); - if (Root == NULL) + if (data->Root == NULL) { + data->Root = (FRACTAL *) malloc (sizeof (FRACTAL)); + if (data->Root == NULL) return; - Root->Buffer1 = (IFSPoint *) NULL; - Root->Buffer2 = (IFSPoint *) NULL; + data->Root->Buffer1 = (IFSPoint *) NULL; + data->Root->Buffer2 = (IFSPoint *) NULL; } - Fractal = Root; + Fractal = data->Root; -// fprintf (stderr,"--ifs freeing ex-buffers\n"); free_ifs_buffers (Fractal); -// fprintf (stderr,"--ifs ok\n"); i = (NRAND (4)) + 2; /* Number of centers */ switch (i) { - case 3: - Fractal->Depth = MAX_DEPTH_3; - Fractal->r_mean = .6; - Fractal->dr_mean = .4; - Fractal->dr2_mean = .3; - break; - - case 4: - Fractal->Depth = MAX_DEPTH_4; - Fractal->r_mean = .5; - Fractal->dr_mean = .4; - Fractal->dr2_mean = .3; - break; - - case 5: - Fractal->Depth = MAX_DEPTH_5; - Fractal->r_mean = .5; - Fractal->dr_mean = .4; - Fractal->dr2_mean = .3; - break; - - default: - case 2: - Fractal->Depth = MAX_DEPTH_2; - Fractal->r_mean = .7; - Fractal->dr_mean = .3; - Fractal->dr2_mean = .4; - break; + case 3: + Fractal->Depth = MAX_DEPTH_3; + Fractal->r_mean = .6; + Fractal->dr_mean = .4; + Fractal->dr2_mean = .3; + break; + + case 4: + Fractal->Depth = MAX_DEPTH_4; + Fractal->r_mean = .5; + Fractal->dr_mean = .4; + Fractal->dr2_mean = .3; + break; + + case 5: + Fractal->Depth = MAX_DEPTH_5; + Fractal->r_mean = .5; + Fractal->dr_mean = .4; + Fractal->dr2_mean = .3; + break; + + default: + case 2: + Fractal->Depth = MAX_DEPTH_2; + Fractal->r_mean = .7; + Fractal->dr_mean = .3; + Fractal->dr2_mean = .4; + break; } -// fprintf( stderr, "N=%d\n", i ); Fractal->Nb_Simi = i; Fractal->Max_Pt = Fractal->Nb_Simi - 1; for (i = 0; i <= Fractal->Depth + 2; ++i) Fractal->Max_Pt *= Fractal->Nb_Simi; if ((Fractal->Buffer1 = (IFSPoint *) calloc (Fractal->Max_Pt, - sizeof (IFSPoint))) == NULL) { + sizeof (IFSPoint))) == NULL) { free_ifs (Fractal); return; } if ((Fractal->Buffer2 = (IFSPoint *) calloc (Fractal->Max_Pt, - sizeof (IFSPoint))) == NULL) { + sizeof (IFSPoint))) == NULL) { free_ifs (Fractal); return; } -// printf ("--ifs setting params\n"); Fractal->Speed = 6; Fractal->Width = width; /* modif by JeKo */ Fractal->Height = height; /* modif by JeKo */ @@ -287,107 +276,65 @@ init_ifs (int width, int height) Fractal->Ly = (Fractal->Height - 1) / 2; Fractal->Col = rand () % (width * height); /* modif by JeKo */ - Random_Simis (Fractal, Fractal->Components, 5 * MAX_SIMI); - - /* - * #ifndef NO_DBUF - * if (Fractal->dbuf != None) - * XFreePixmap(display, Fractal->dbuf); - * Fractal->dbuf = XCreatePixmap(display, window, - * Fractal->Width, Fractal->Height, 1); - * /* Allocation checked * - * if (Fractal->dbuf != None) { - * XGCValues gcv; - * - * gcv.foreground = 0; - * gcv.background = 0; - * gcv.graphics_exposures = False; - * gcv.function = GXcopy; - * - * if (Fractal->dbuf_gc != None) - * XFreeGC(display, Fractal->dbuf_gc); - * if ((Fractal->dbuf_gc = XCreateGC(display, Fractal->dbuf, - * GCForeground | GCBackground | GCGraphicsExposures | GCFunction, - * &gcv)) == None) { - * XFreePixmap(display, Fractal->dbuf); - * Fractal->dbuf = None; - * } else { - * XFillRectangle(display, Fractal->dbuf, - * Fractal->dbuf_gc, 0, 0, Fractal->Width, Fractal->Height); - * XSetBackground(display, gc, MI_BLACK_PIXEL(mi)); - * XSetFunction(display, gc, GXcopy); - * } - * } - * #endif - */ - // MI_CLEARWINDOW(mi); - - /* don't want any exposure events from XCopyPlane */ - // XSetGraphicsExposures(display, gc, False); - + Random_Simis (goomInfo, Fractal, Fractal->Components, 5 * MAX_SIMI); } /***************************************************************/ -/* Should be taken care of already... but just in case */ -#if !defined( __GNUC__ ) && !defined(__cplusplus) && !defined(c_plusplus) -#undef inline -#define inline /* */ -#endif static inline void Transform (SIMI * Simi, F_PT xo, F_PT yo, F_PT * x, F_PT * y) { F_PT xx, yy; xo = xo - Simi->Cx; - xo = (xo * Simi->R) >> FIX; // / UNIT; + xo = (xo * Simi->R) >> FIX; /* / UNIT; */ yo = yo - Simi->Cy; - yo = (yo * Simi->R) >> FIX; // / UNIT; + yo = (yo * Simi->R) >> FIX; /* / UNIT; */ xx = xo - Simi->Cx; - xx = (xx * Simi->R2) >> FIX; // / UNIT; + xx = (xx * Simi->R2) >> FIX; /* / UNIT; */ yy = -yo - Simi->Cy; - yy = (yy * Simi->R2) >> FIX; // / UNIT; + yy = (yy * Simi->R2) >> FIX; /* / UNIT; */ *x = - ((xo * Simi->Ct - yo * Simi->St + xx * Simi->Ct2 - yy * Simi->St2) - >> FIX /* / UNIT */ ) + Simi->Cx; + ((xo * Simi->Ct - yo * Simi->St + xx * Simi->Ct2 - yy * Simi->St2) + >> FIX /* / UNIT */ ) + Simi->Cx; *y = - ((xo * Simi->St + yo * Simi->Ct + xx * Simi->St2 + yy * Simi->Ct2) - >> FIX /* / UNIT */ ) + Simi->Cy; + ((xo * Simi->St + yo * Simi->Ct + xx * Simi->St2 + yy * Simi->Ct2) + >> FIX /* / UNIT */ ) + Simi->Cy; } /***************************************************************/ static void -Trace (FRACTAL * F, F_PT xo, F_PT yo) +Trace (FRACTAL * F, F_PT xo, F_PT yo, IfsData *data) { F_PT x, y, i; SIMI *Cur; - Cur = Cur_F->Components; - for (i = Cur_F->Nb_Simi; i; --i, Cur++) { + Cur = data->Cur_F->Components; + for (i = data->Cur_F->Nb_Simi; i; --i, Cur++) { Transform (Cur, xo, yo, &x, &y); - Buf->x = F->Lx + ((x * F->Lx) >> (FIX+1) /* /(UNIT*2) */ ); - Buf->y = F->Ly - ((y * F->Ly) >> (FIX+1) /* /(UNIT*2) */ ); - Buf++; + data->Buf->x = F->Lx + ((x * F->Lx) >> (FIX+1) /* /(UNIT*2) */ ); + data->Buf->y = F->Ly - ((y * F->Ly) >> (FIX+1) /* /(UNIT*2) */ ); + data->Buf++; - Cur_Pt++; + data->Cur_Pt++; if (F->Depth && ((x - xo) >> 4) && ((y - yo) >> 4)) { F->Depth--; - Trace (F, x, y); + Trace (F, x, y, data); F->Depth++; } } } static void -Draw_Fractal ( /* ModeInfo * mi */ ) +Draw_Fractal (IfsData *data) { - FRACTAL *F = Root; + FRACTAL *F = data->Root; int i, j; F_PT x, y, xo, yo; SIMI *Cur, *Simi; @@ -406,9 +353,9 @@ Draw_Fractal ( /* ModeInfo * mi */ ) } - Cur_Pt = 0; - Cur_F = F; - Buf = F->Buffer2; + data->Cur_Pt = 0; + data->Cur_F = F; + data->Buf = F->Buffer2; for (Cur = F->Components, i = F->Nb_Simi; i; --i, Cur++) { xo = Cur->Cx; yo = Cur->Cy; @@ -416,58 +363,30 @@ Draw_Fractal ( /* ModeInfo * mi */ ) if (Simi == Cur) continue; Transform (Simi, xo, yo, &x, &y); - Trace (F, x, y); + Trace (F, x, y, data); } } /* Erase previous */ -/* if (F->Cur_Pt) { - XSetForeground(display, gc, MI_BLACK_PIXEL(mi)); - if (F->dbuf != None) { - XSetForeground(display, F->dbuf_gc, 0); -*/ - /* XDrawPoints(display, F->dbuf, F->dbuf_gc, F->Buffer1, F->Cur_Pt, * * * * - * CoordModeOrigin); */ -/* XFillRectangle(display, F->dbuf, F->dbuf_gc, 0, 0, - F->Width, F->Height); - } else - XDrawPoints(display, window, gc, F->Buffer1, F->Cur_Pt, CoordModeOrigin); - } - if (MI_NPIXELS(mi) < 2) - XSetForeground(display, gc, MI_WHITE_PIXEL(mi)); - else - XSetForeground(display, gc, MI_PIXEL(mi, F->Col % MI_NPIXELS(mi))); - if (Cur_Pt) { - if (F->dbuf != None) { - XSetForeground(display, F->dbuf_gc, 1); - XDrawPoints(display, F->dbuf, F->dbuf_gc, F->Buffer2, Cur_Pt, - CoordModeOrigin); - } else - XDrawPoints(display, window, gc, F->Buffer2, Cur_Pt, CoordModeOrigin); - } - if (F->dbuf != None) - XCopyPlane(display, F->dbuf, window, gc, 0, 0, F->Width, F->Height, 0, 0, 1); -*/ - - F->Cur_Pt = Cur_Pt; - Buf = F->Buffer1; + F->Cur_Pt = data->Cur_Pt; + data->Buf = F->Buffer1; F->Buffer1 = F->Buffer2; - F->Buffer2 = Buf; + F->Buffer2 = data->Buf; } IFSPoint * -draw_ifs ( /* ModeInfo * mi */ int *nbpt) +draw_ifs (PluginInfo *goomInfo, int *nbpt, IfsData *data) { int i; DBL u, uu, v, vv, u0, u1, u2, u3; SIMI *S, *S1, *S2, *S3, *S4; FRACTAL *F; - if (Root == NULL) + if (data->Root == NULL) return NULL; - F = Root; // [/*MI_SCREEN(mi)*/0]; + F = data->Root; if (F->Buffer1 == NULL) return NULL; @@ -495,9 +414,7 @@ draw_ifs ( /* ModeInfo * mi */ int *nbpt) S->A2 = u0 * S1->A2 + u1 * S2->A2 + u2 * S3->A2 + u3 * S4->A2; } - // MI_IS_DRAWN(mi) = True; - - Draw_Fractal ( /* mi */ ); + Draw_Fractal (data); if (F->Count >= 1000 / F->Speed) { S = F->Components; @@ -516,9 +433,9 @@ draw_ifs ( /* ModeInfo * mi */ int *nbpt) *S1 = *S4; } - Random_Simis (F, F->Components + 3 * F->Nb_Simi, F->Nb_Simi); + Random_Simis (goomInfo, F, F->Components + 3 * F->Nb_Simi, F->Nb_Simi); - Random_Simis (F, F->Components + 4 * F->Nb_Simi, F->Nb_Simi); + Random_Simis (goomInfo, F, F->Components + 4 * F->Nb_Simi, F->Nb_Simi); F->Count = 0; } @@ -527,23 +444,315 @@ draw_ifs ( /* ModeInfo * mi */ int *nbpt) F->Col++; - /* #1 code added by JeKo */ - (*nbpt) = Cur_Pt; + (*nbpt) = data->Cur_Pt; return F->Buffer2; - /* #1 end */ } /***************************************************************/ -void -release_ifs (void) +static void release_ifs (IfsData *data) { - if (Root != NULL) { - free_ifs(Root); - (void) free ((void *) Root); - Root = (FRACTAL *) NULL; - } + if (data->Root != NULL) { + free_ifs (data->Root); + (void) free ((void *) data->Root); + data->Root = (FRACTAL *) NULL; + } } -//#endif /* MODE_ifs */ +#define RAND() goom_random(goomInfo->gRandom) + +static void ifs_update (PluginInfo *goomInfo, Pixel * data, Pixel * back, int increment, IfsData *fx_data) +{ + static int couleur = 0xc0c0c0c0; + static int v[4] = { 2, 4, 3, 2 }; + static int col[4] = { 2, 4, 3, 2 }; + +#define MOD_MER 0 +#define MOD_FEU 1 +#define MOD_MERVER 2 + static int mode = MOD_MERVER; + static int justChanged = 0; + static int cycle = 0; + int cycle10; + + int nbpt; + IFSPoint *points; + int i; + + int couleursl = couleur; + int width = goomInfo->screen.width; + int height = goomInfo->screen.height; + + cycle++; + if (cycle >= 80) + cycle = 0; + + if (cycle < 40) + cycle10 = cycle / 10; + else + cycle10 = 7 - cycle / 10; + + { + unsigned char *tmp = (unsigned char *) &couleursl; + + for (i = 0; i < 4; i++) { + *tmp = (*tmp) >> cycle10; + tmp++; + } + } + + points = draw_ifs (goomInfo, &nbpt, fx_data); + nbpt--; + +#ifdef HAVE_MMX + movd_m2r (couleursl, mm1); + punpckldq_r2r (mm1, mm1); + for (i = 0; i < nbpt; i += increment) { + int x = points[i].x; + int y = points[i].y; + + if ((x < width) && (y < height) && (x > 0) && (y > 0)) { + int pos = x + (y * width); + movd_m2r (back[pos], mm0); + paddusb_r2r (mm1, mm0); + movd_r2m (mm0, data[pos]); + } + } + emms();/*__asm__ __volatile__ ("emms");*/ +#else + for (i = 0; i < nbpt; i += increment) { + int x = (int) points[i].x & 0x7fffffff; + int y = (int) points[i].y & 0x7fffffff; + + if ((x < width) && (y < height)) { + int pos = x + (int) (y * width); + int tra = 0, i = 0; + unsigned char *bra = (unsigned char *) &back[pos]; + unsigned char *dra = (unsigned char *) &data[pos]; + unsigned char *cra = (unsigned char *) &couleursl; + + for (; i < 4; i++) { + tra = *cra; + tra += *bra; + if (tra > 255) + tra = 255; + *dra = tra; + ++dra; + ++cra; + ++bra; + } + } + } +#endif /*MMX*/ + justChanged--; + + col[ALPHA] = couleur >> (ALPHA * 8) & 0xff; + col[BLEU] = couleur >> (BLEU * 8) & 0xff; + col[VERT] = couleur >> (VERT * 8) & 0xff; + col[ROUGE] = couleur >> (ROUGE * 8) & 0xff; + + if (mode == MOD_MER) { + col[BLEU] += v[BLEU]; + if (col[BLEU] > 255) { + col[BLEU] = 255; + v[BLEU] = -(RAND() % 4) - 1; + } + if (col[BLEU] < 32) { + col[BLEU] = 32; + v[BLEU] = (RAND() % 4) + 1; + } + + col[VERT] += v[VERT]; + if (col[VERT] > 200) { + col[VERT] = 200; + v[VERT] = -(RAND() % 3) - 2; + } + if (col[VERT] > col[BLEU]) { + col[VERT] = col[BLEU]; + v[VERT] = v[BLEU]; + } + if (col[VERT] < 32) { + col[VERT] = 32; + v[VERT] = (RAND() % 3) + 2; + } + + col[ROUGE] += v[ROUGE]; + if (col[ROUGE] > 64) { + col[ROUGE] = 64; + v[ROUGE] = -(RAND () % 4) - 1; + } + if (col[ROUGE] < 0) { + col[ROUGE] = 0; + v[ROUGE] = (RAND () % 4) + 1; + } + + col[ALPHA] += v[ALPHA]; + if (col[ALPHA] > 0) { + col[ALPHA] = 0; + v[ALPHA] = -(RAND () % 4) - 1; + } + if (col[ALPHA] < 0) { + col[ALPHA] = 0; + v[ALPHA] = (RAND () % 4) + 1; + } + + if (((col[VERT] > 32) && (col[ROUGE] < col[VERT] + 40) + && (col[VERT] < col[ROUGE] + 20) && (col[BLEU] < 64) + && (RAND () % 20 == 0)) && (justChanged < 0)) { + mode = RAND () % 3 ? MOD_FEU : MOD_MERVER; + justChanged = 250; + } + } + else if (mode == MOD_MERVER) { + col[BLEU] += v[BLEU]; + if (col[BLEU] > 128) { + col[BLEU] = 128; + v[BLEU] = -(RAND () % 4) - 1; + } + if (col[BLEU] < 16) { + col[BLEU] = 16; + v[BLEU] = (RAND () % 4) + 1; + } + + col[VERT] += v[VERT]; + if (col[VERT] > 200) { + col[VERT] = 200; + v[VERT] = -(RAND () % 3) - 2; + } + if (col[VERT] > col[ALPHA]) { + col[VERT] = col[ALPHA]; + v[VERT] = v[ALPHA]; + } + if (col[VERT] < 32) { + col[VERT] = 32; + v[VERT] = (RAND () % 3) + 2; + } + + col[ROUGE] += v[ROUGE]; + if (col[ROUGE] > 128) { + col[ROUGE] = 128; + v[ROUGE] = -(RAND () % 4) - 1; + } + if (col[ROUGE] < 0) { + col[ROUGE] = 0; + v[ROUGE] = (RAND () % 4) + 1; + } + + col[ALPHA] += v[ALPHA]; + if (col[ALPHA] > 255) { + col[ALPHA] = 255; + v[ALPHA] = -(RAND () % 4) - 1; + } + if (col[ALPHA] < 0) { + col[ALPHA] = 0; + v[ALPHA] = (RAND () % 4) + 1; + } + + if (((col[VERT] > 32) && (col[ROUGE] < col[VERT] + 40) + && (col[VERT] < col[ROUGE] + 20) && (col[BLEU] < 64) + && (RAND () % 20 == 0)) && (justChanged < 0)) { + mode = RAND () % 3 ? MOD_FEU : MOD_MER; + justChanged = 250; + } + } + else if (mode == MOD_FEU) { + + col[BLEU] += v[BLEU]; + if (col[BLEU] > 64) { + col[BLEU] = 64; + v[BLEU] = -(RAND () % 4) - 1; + } + if (col[BLEU] < 0) { + col[BLEU] = 0; + v[BLEU] = (RAND () % 4) + 1; + } + + col[VERT] += v[VERT]; + if (col[VERT] > 200) { + col[VERT] = 200; + v[VERT] = -(RAND () % 3) - 2; + } + if (col[VERT] > col[ROUGE] + 20) { + col[VERT] = col[ROUGE] + 20; + v[VERT] = -(RAND () % 3) - 2; + v[ROUGE] = (RAND () % 4) + 1; + v[BLEU] = (RAND () % 4) + 1; + } + if (col[VERT] < 0) { + col[VERT] = 0; + v[VERT] = (RAND () % 3) + 2; + } + + col[ROUGE] += v[ROUGE]; + if (col[ROUGE] > 255) { + col[ROUGE] = 255; + v[ROUGE] = -(RAND () % 4) - 1; + } + if (col[ROUGE] > col[VERT] + 40) { + col[ROUGE] = col[VERT] + 40; + v[ROUGE] = -(RAND () % 4) - 1; + } + if (col[ROUGE] < 0) { + col[ROUGE] = 0; + v[ROUGE] = (RAND () % 4) + 1; + } + + col[ALPHA] += v[ALPHA]; + if (col[ALPHA] > 0) { + col[ALPHA] = 0; + v[ALPHA] = -(RAND () % 4) - 1; + } + if (col[ALPHA] < 0) { + col[ALPHA] = 0; + v[ALPHA] = (RAND () % 4) + 1; + } + + if (((col[ROUGE] < 64) && (col[VERT] > 32) && (col[VERT] < col[BLEU]) + && (col[BLEU] > 32) + && (RAND () % 20 == 0)) && (justChanged < 0)) { + mode = RAND () % 2 ? MOD_MER : MOD_MERVER; + justChanged = 250; + } + } + + couleur = (col[ALPHA] << (ALPHA * 8)) + | (col[BLEU] << (BLEU * 8)) + | (col[VERT] << (VERT * 8)) + | (col[ROUGE] << (ROUGE * 8)); +} + +/** VISUAL_FX WRAPPER FOR IFS */ + +void ifs_vfx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { + + IfsData *data = (IfsData*)_this->fx_data; + if (!data->initalized) { + data->initalized = 1; + init_ifs(goomInfo, data); + } + ifs_update (goomInfo, dest, src, goomInfo->update.ifs_incr, data); + /*TODO: trouver meilleur soluce pour increment (mettre le code de gestion de l'ifs dans ce fichier: ifs_vfx_apply) */ +} + +void ifs_vfx_init(VisualFX *_this) { + + IfsData *data = (IfsData*)malloc(sizeof(IfsData)); + data->Root = (FRACTAL*)NULL; + data->initalized = 0; + _this->fx_data = data; +} + +void ifs_vfx_free(VisualFX *_this) { + IfsData *data = (IfsData*)_this->fx_data; + release_ifs(data); + free(data); +} + +VisualFX ifs_visualfx_create() { + VisualFX vfx; + vfx.init = ifs_vfx_init; + vfx.free = ifs_vfx_free; + vfx.apply = ifs_vfx_apply; + return vfx; +} diff --git a/src/post/goom/ifs.h b/src/post/goom/ifs.h index 6ab2af057..909838bd3 100644 --- a/src/post/goom/ifs.h +++ b/src/post/goom/ifs.h @@ -6,30 +6,22 @@ #define IFS_H #include "goom_config.h" +#include "goom_graphic.h" +#include "goom_plugin_info.h" +#include "goom_visual_fx.h" -typedef struct _ifsPoint -{ - gint32 x, y; -} -IFSPoint; +VisualFX ifs_visualfx_create(); -// init ifs for a (width)x(height) output. -void init_ifs (int width, int height); +/* init ifs for a (width)x(height) output. * / +void init_ifs (PluginInfo *goomInfo, int width, int height); -// draw an ifs on the buffer (which size is width * height) -// increment means that we draw 1/increment of the ifs's points -void ifs_update (guint32 * buffer, guint32 * back, int width, int height, - int increment); +/ * draw an ifs on the buffer (which size is width * height) + increment means that we draw 1/increment of the ifs's points * / +void ifs_update (PluginInfo *goomInfo, Pixel * buffer, Pixel * back, int width, int height, int increment); -// free all ifs's data. -void release_ifs (void); - - -/* DONT USE !!! deprecated - * return a an array of points. - * WARNING !!! do not free it !!! it also has an internal use.. - */ -IFSPoint *draw_ifs (int *nbPoints); +/ * free all ifs's data. * / +void release_ifs (); +*/ #endif diff --git a/src/post/goom/ifs_display.c b/src/post/goom/ifs_display.c deleted file mode 100644 index ed570f59a..000000000 --- a/src/post/goom/ifs_display.c +++ /dev/null @@ -1,268 +0,0 @@ -#include "ifs.h" -#include "goom_config.h" - -#ifdef HAVE_MMX -#include "mmx.h" -#endif - -#include "goom_tools.h" - -void -ifs_update (guint32 * data, guint32 * back, int width, int height, - int increment) -{ - static int couleur = 0xc0c0c0c0; - static int v[4] = { 2, 4, 3, 2 }; - static int col[4] = { 2, 4, 3, 2 }; - -#define MOD_MER 0 -#define MOD_FEU 1 -#define MOD_MERVER 2 - static int mode = MOD_MERVER; - static int justChanged = 0; - static int cycle = 0; - int cycle10; - - int nbpt; - IFSPoint *points; - int i; - - int couleursl = couleur; - - cycle++; - if (cycle >= 80) - cycle = 0; - - if (cycle < 40) - cycle10 = cycle / 10; - else - cycle10 = 7 - cycle / 10; - - { - unsigned char *tmp = (unsigned char *) &couleursl; - - for (i = 0; i < 4; i++) { - *tmp = (*tmp) >> cycle10; - tmp++; - } - } - - points = draw_ifs (&nbpt); - nbpt--; - -#ifdef HAVE_MMX - movd_m2r (couleursl, mm1); - punpckldq_r2r (mm1, mm1); - for (i = 0; i < nbpt; i += increment) { - int x = points[i].x; - int y = points[i].y; - - if ((x < width) && (y < height) && (x > 0) && (y > 0)) { - int pos = x + (y * width); - movd_m2r (back[pos], mm0); - paddusb_r2r (mm1, mm0); - movd_r2m (mm0, data[pos]); - } - } - emms();/*__asm__ __volatile__ ("emms");*/ -#else - for (i = 0; i < nbpt; i += increment) { - int x = (int) points[i].x & 0x7fffffff; - int y = (int) points[i].y & 0x7fffffff; - - if ((x < width) && (y < height)) { - int pos = x + (int) (y * width); - int tra = 0, i = 0; - unsigned char *bra = (unsigned char *) &back[pos]; - unsigned char *dra = (unsigned char *) &data[pos]; - unsigned char *cra = (unsigned char *) &couleursl; - - for (; i < 4; i++) { - tra = *cra; - tra += *bra; - if (tra > 255) - tra = 255; - *dra = tra; - ++dra; - ++cra; - ++bra; - } - } - } -#endif /*MMX*/ - justChanged--; - - col[ALPHA] = couleur >> (ALPHA * 8) & 0xff; - col[BLEU] = couleur >> (BLEU * 8) & 0xff; - col[VERT] = couleur >> (VERT * 8) & 0xff; - col[ROUGE] = couleur >> (ROUGE * 8) & 0xff; - - if (mode == MOD_MER) { - col[BLEU] += v[BLEU]; - if (col[BLEU] > 255) { - col[BLEU] = 255; - v[BLEU] = -(RAND() % 4) - 1; - } - if (col[BLEU] < 32) { - col[BLEU] = 32; - v[BLEU] = (RAND() % 4) + 1; - } - - col[VERT] += v[VERT]; - if (col[VERT] > 200) { - col[VERT] = 200; - v[VERT] = -(RAND() % 3) - 2; - } - if (col[VERT] > col[BLEU]) { - col[VERT] = col[BLEU]; - v[VERT] = v[BLEU]; - } - if (col[VERT] < 32) { - col[VERT] = 32; - v[VERT] = (RAND() % 3) + 2; - } - - col[ROUGE] += v[ROUGE]; - if (col[ROUGE] > 64) { - col[ROUGE] = 64; - v[ROUGE] = -(RAND () % 4) - 1; - } - if (col[ROUGE] < 0) { - col[ROUGE] = 0; - v[ROUGE] = (RAND () % 4) + 1; - } - - col[ALPHA] += v[ALPHA]; - if (col[ALPHA] > 0) { - col[ALPHA] = 0; - v[ALPHA] = -(RAND () % 4) - 1; - } - if (col[ALPHA] < 0) { - col[ALPHA] = 0; - v[ALPHA] = (RAND () % 4) + 1; - } - - if (((col[VERT] > 32) && (col[ROUGE] < col[VERT] + 40) - && (col[VERT] < col[ROUGE] + 20) && (col[BLEU] < 64) - && (RAND () % 20 == 0)) && (justChanged < 0)) { - mode = RAND () % 3 ? MOD_FEU : MOD_MERVER; - justChanged = 250; - } - } - else if (mode == MOD_MERVER) { - col[BLEU] += v[BLEU]; - if (col[BLEU] > 128) { - col[BLEU] = 128; - v[BLEU] = -(RAND () % 4) - 1; - } - if (col[BLEU] < 16) { - col[BLEU] = 16; - v[BLEU] = (RAND () % 4) + 1; - } - - col[VERT] += v[VERT]; - if (col[VERT] > 200) { - col[VERT] = 200; - v[VERT] = -(RAND () % 3) - 2; - } - if (col[VERT] > col[ALPHA]) { - col[VERT] = col[ALPHA]; - v[VERT] = v[ALPHA]; - } - if (col[VERT] < 32) { - col[VERT] = 32; - v[VERT] = (RAND () % 3) + 2; - } - - col[ROUGE] += v[ROUGE]; - if (col[ROUGE] > 128) { - col[ROUGE] = 128; - v[ROUGE] = -(RAND () % 4) - 1; - } - if (col[ROUGE] < 0) { - col[ROUGE] = 0; - v[ROUGE] = (RAND () % 4) + 1; - } - - col[ALPHA] += v[ALPHA]; - if (col[ALPHA] > 255) { - col[ALPHA] = 255; - v[ALPHA] = -(RAND () % 4) - 1; - } - if (col[ALPHA] < 0) { - col[ALPHA] = 0; - v[ALPHA] = (RAND () % 4) + 1; - } - - if (((col[VERT] > 32) && (col[ROUGE] < col[VERT] + 40) - && (col[VERT] < col[ROUGE] + 20) && (col[BLEU] < 64) - && (RAND () % 20 == 0)) && (justChanged < 0)) { - mode = RAND () % 3 ? MOD_FEU : MOD_MER; - justChanged = 250; - } - } - else if (mode == MOD_FEU) { - - col[BLEU] += v[BLEU]; - if (col[BLEU] > 64) { - col[BLEU] = 64; - v[BLEU] = -(RAND () % 4) - 1; - } - if (col[BLEU] < 0) { - col[BLEU] = 0; - v[BLEU] = (RAND () % 4) + 1; - } - - col[VERT] += v[VERT]; - if (col[VERT] > 200) { - col[VERT] = 200; - v[VERT] = -(RAND () % 3) - 2; - } - if (col[VERT] > col[ROUGE] + 20) { - col[VERT] = col[ROUGE] + 20; - v[VERT] = -(RAND () % 3) - 2; - v[ROUGE] = (RAND () % 4) + 1; - v[BLEU] = (RAND () % 4) + 1; - } - if (col[VERT] < 0) { - col[VERT] = 0; - v[VERT] = (RAND () % 3) + 2; - } - - col[ROUGE] += v[ROUGE]; - if (col[ROUGE] > 255) { - col[ROUGE] = 255; - v[ROUGE] = -(RAND () % 4) - 1; - } - if (col[ROUGE] > col[VERT] + 40) { - col[ROUGE] = col[VERT] + 40; - v[ROUGE] = -(RAND () % 4) - 1; - } - if (col[ROUGE] < 0) { - col[ROUGE] = 0; - v[ROUGE] = (RAND () % 4) + 1; - } - - col[ALPHA] += v[ALPHA]; - if (col[ALPHA] > 0) { - col[ALPHA] = 0; - v[ALPHA] = -(RAND () % 4) - 1; - } - if (col[ALPHA] < 0) { - col[ALPHA] = 0; - v[ALPHA] = (RAND () % 4) + 1; - } - - if (((col[ROUGE] < 64) && (col[VERT] > 32) && (col[VERT] < col[BLEU]) - && (col[BLEU] > 32) - && (RAND () % 20 == 0)) && (justChanged < 0)) { - mode = RAND () % 2 ? MOD_MER : MOD_MERVER; - justChanged = 250; - } - } - - couleur = (col[ALPHA] << (ALPHA * 8)) - | (col[BLEU] << (BLEU * 8)) - | (col[VERT] << (VERT * 8)) - | (col[ROUGE] << (ROUGE * 8)); -} diff --git a/src/post/goom/lines.c b/src/post/goom/lines.c index 5d3d2dba6..a6a268337 100644 --- a/src/post/goom/lines.c +++ b/src/post/goom/lines.c @@ -8,17 +8,15 @@ #include #include "goom_tools.h" #include "drawmethods.h" +#include "goom_plugin_info.h" -extern unsigned int resolx, c_resoly; - -static inline unsigned char -lighten (unsigned char value, float power) +static inline unsigned char lighten (unsigned char value, float power) { int val = value; float t = (float) val * log10(power) / 2.0; if (t > 0) { - val = (int) t; // (32.0f * log (t)); + val = (int) t; /* (32.0f * log (t)); */ if (val > 255) val = 255; if (val < 0) @@ -30,8 +28,7 @@ lighten (unsigned char value, float power) } } -static void -lightencolor (int *col, float power) +static void lightencolor (guint32 *col, float power) { unsigned char *color; @@ -106,8 +103,6 @@ void goom_lines_set_res (GMLine * gml, int rx, int ry) { if (gml != NULL) { - //int i; - gml->screenX = rx; gml->screenY = ry; @@ -144,11 +139,11 @@ goom_lines_move (GMLine * l) l->power += l->powinc; if (l->power < 1.1f) { l->power = 1.1f; - l->powinc = (float) (iRAND (20) + 10) / 300.0f; + l->powinc = (float) (goom_irand(l->goomInfo->gRandom,20) + 10) / 300.0f; } if (l->power > 17.5f) { l->power = 17.5f; - l->powinc = -(float) (iRAND (20) + 10) / 300.0f; + l->powinc = -(float) (goom_irand(l->goomInfo->gRandom,20) + 10) / 300.0f; } l->amplitude = (99.0f * l->amplitude + l->amplitudeF) / 100.0f; @@ -163,20 +158,17 @@ goom_lines_switch_to (GMLine * gml, int IDdest, gml->param = param; gml->amplitudeF = amplitude; gml->color2 = getcouleur (col); -// printf ("couleur %d : %x\n",col,gml->color2); } GMLine * -goom_lines_init (int rx, int ry, - int IDsrc, float paramS, int coulS, - int IDdest, float paramD, int coulD) +goom_lines_init (PluginInfo *goomInfo, int rx, int ry, + int IDsrc, float paramS, int coulS, + int IDdest, float paramD, int coulD) { - //int i; - //unsigned char *color; - //unsigned char power = 4; - GMLine *l = (GMLine *) malloc (sizeof (GMLine)); + l->goomInfo = goomInfo; + l->points = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer)); l->points2 = (GMUnitPointer *) malloc (512 * sizeof (GMUnitPointer)); l->nbPoints = 512; @@ -211,8 +203,7 @@ goom_lines_free (GMLine ** l) l = NULL; } -void -goom_lines_draw (GMLine * line, gint16 data[512], unsigned int *p) +void goom_lines_draw (PluginInfo *plug, GMLine * line, gint16 data[512], Pixel *p) { if (line != NULL) { int i, x1, y1; @@ -237,8 +228,7 @@ goom_lines_draw (GMLine * line, gint16 data[512], unsigned int *p) x2 = (int) (pt->x + cosa * line->amplitude * data[i]); y2 = (int) (pt->y + sina * line->amplitude * data[i]); - draw_line (p, x1, y1, x2, y2, color, line->screenX, line->screenY); - DRAWMETHOD_DONE (); + plug->methods.draw_line (p, x1, y1, x2, y2, color, line->screenX, line->screenY); x1 = x2; y1 = y2; diff --git a/src/post/goom/lines.h b/src/post/goom/lines.h index 3401cb38a..9c6df9240 100644 --- a/src/post/goom/lines.h +++ b/src/post/goom/lines.h @@ -1,24 +1,25 @@ +#ifndef _LINES_H +#define _LINES_H + /* * lines.h - * iGoom - * - * Created by guillaum on Tue Aug 14 2001. - * Copyright (c) 2001 ios. All rights reserved. + * Goom + * Copyright (c) 2000-2003 iOS-software. All rights reserved. */ -#include "graphic.h" +#include "goom_typedefs.h" +#include "goom_graphic.h" #include "goom_config.h" -typedef struct _GMUNITPOINTER +struct _GMUNITPOINTER { float x; float y; float angle; -} -GMUnitPointer; +}; -// tableau de points -typedef struct _GMLINE +/* tableau de points */ +struct _GMLINE { GMUnitPointer *points; @@ -29,9 +30,7 @@ typedef struct _GMLINE float amplitude; int nbPoints; - guint32 color; /* pr l'instant je stocke la ouuleur * * a * - * * * terme, on stockera le mode couleur.. - * et * * * l'on animera */ + guint32 color; /* pour l'instant je stocke la couleur a terme, on stockera le mode couleur et l'on animera */ guint32 color2; int screenX; @@ -39,21 +38,22 @@ typedef struct _GMLINE float power; float powinc; -} -GMLine; -// les ID possibles + PluginInfo *goomInfo; +}; + +/* les ID possibles */ #define GML_CIRCLE 0 -// (param = radius) +/* (param = radius) */ #define GML_HLINE 1 -// (param = y) +/* (param = y) */ #define GML_VLINE 2 -// (param = x) +/* (param = x) */ -// les modes couleur possible (si tu mets un autre c'est noir) +/* les modes couleur possible (si tu mets un autre c'est noir) */ #define GML_BLEUBLANC 0 #define GML_RED 1 @@ -64,18 +64,18 @@ GMLine; #define GML_BLACK 6 /* construit un effet de line (une ligne horitontale pour commencer) */ -GMLine *goom_lines_init (int rx, int ry, - int IDsrc, float paramS, int modeCoulSrc, - int IDdest, float paramD, int modeCoulDest); +GMLine *goom_lines_init (PluginInfo *goomInfo, int rx, int ry, + int IDsrc, float paramS, int modeCoulSrc, + int IDdest, float paramD, int modeCoulDest); void goom_lines_switch_to (GMLine * gml, int IDdest, float param, - float amplitude, - int modeCoul); + float amplitude, + int modeCoul); void goom_lines_set_res (GMLine * gml, int rx, int ry); void goom_lines_free (GMLine ** gml); -void goom_lines_draw (GMLine * gml, gint16 data[512], unsigned int *p); +void goom_lines_draw (PluginInfo *plugInfo, GMLine * gml, gint16 data[512], Pixel *p); -//void goom_lines_conf(gint16 config [25]); +#endif /* _LINES_H */ diff --git a/src/post/goom/mathtools.c b/src/post/goom/mathtools.c new file mode 100644 index 000000000..b2b02ea05 --- /dev/null +++ b/src/post/goom/mathtools.c @@ -0,0 +1,84 @@ +/*---------------------------------------------------------------------------*/ +/* +** mathtools.c +** Goom Project +** +** Created by Jeko on Sun Jul 20 2003 + ** Copyright (c) 2003 iOS. All rights reserved. +*/ +/*---------------------------------------------------------------------------*/ + +#include "mathtools.h" + +float sin256[256] = { + 0,0.0245412,0.0490677,0.0735646,0.0980171,0.122411,0.14673,0.170962 + ,0.19509,0.219101,0.24298,0.266713,0.290285,0.313682,0.33689,0.359895 + ,0.382683,0.405241,0.427555,0.449611,0.471397,0.492898,0.514103,0.534998 + ,0.55557,0.575808,0.595699,0.615232,0.634393,0.653173,0.671559,0.689541 + ,0.707107,0.724247,0.740951,0.757209,0.77301,0.788346,0.803208,0.817585 + ,0.83147,0.844854,0.857729,0.870087,0.881921,0.893224,0.903989,0.91421 + ,0.92388,0.932993,0.941544,0.949528,0.95694,0.963776,0.970031,0.975702 + ,0.980785,0.985278,0.989177,0.99248,0.995185,0.99729,0.998795,0.999699 + ,1,0.999699,0.998795,0.99729,0.995185,0.99248,0.989177,0.985278 + ,0.980785,0.975702,0.970031,0.963776,0.95694,0.949528,0.941544,0.932993 + ,0.92388,0.91421,0.903989,0.893224,0.881921,0.870087,0.857729,0.844854 + ,0.83147,0.817585,0.803208,0.788346,0.77301,0.757209,0.740951,0.724247 + ,0.707107,0.689541,0.671559,0.653173,0.634393,0.615232,0.595699,0.575808 + ,0.55557,0.534998,0.514103,0.492898,0.471397,0.449611,0.427555,0.405241 + ,0.382683,0.359895,0.33689,0.313682,0.290285,0.266713,0.24298,0.219101 + ,0.19509,0.170962,0.14673,0.122411,0.0980171,0.0735646,0.0490677,0.0245412 + ,1.22465e-16,-0.0245412,-0.0490677,-0.0735646,-0.0980171,-0.122411,-0.14673,-0.170962 + ,-0.19509,-0.219101,-0.24298,-0.266713,-0.290285,-0.313682,-0.33689,-0.359895 + ,-0.382683,-0.405241,-0.427555,-0.449611,-0.471397,-0.492898,-0.514103,-0.534998 + ,-0.55557,-0.575808,-0.595699,-0.615232,-0.634393,-0.653173,-0.671559,-0.689541 + ,-0.707107,-0.724247,-0.740951,-0.757209,-0.77301,-0.788346,-0.803208,-0.817585 + ,-0.83147,-0.844854,-0.857729,-0.870087,-0.881921,-0.893224,-0.903989,-0.91421 + ,-0.92388,-0.932993,-0.941544,-0.949528,-0.95694,-0.963776,-0.970031,-0.975702 + ,-0.980785,-0.985278,-0.989177,-0.99248,-0.995185,-0.99729,-0.998795,-0.999699 + ,-1,-0.999699,-0.998795,-0.99729,-0.995185,-0.99248,-0.989177,-0.985278 + ,-0.980785,-0.975702,-0.970031,-0.963776,-0.95694,-0.949528,-0.941544,-0.932993 + ,-0.92388,-0.91421,-0.903989,-0.893224,-0.881921,-0.870087,-0.857729,-0.844854 + ,-0.83147,-0.817585,-0.803208,-0.788346,-0.77301,-0.757209,-0.740951,-0.724247 + ,-0.707107,-0.689541,-0.671559,-0.653173,-0.634393,-0.615232,-0.595699,-0.575808 + ,-0.55557,-0.534998,-0.514103,-0.492898,-0.471397,-0.449611,-0.427555,-0.405241 + ,-0.382683,-0.359895,-0.33689,-0.313682,-0.290285,-0.266713,-0.24298,-0.219101 + ,-0.19509,-0.170962,-0.14673,-0.122411,-0.0980171,-0.0735646,-0.0490677,-0.0245412 + +}; + +float cos256[256] = { + 0,0.999699,0.998795,0.99729,0.995185,0.99248,0.989177,0.985278 + ,0.980785,0.975702,0.970031,0.963776,0.95694,0.949528,0.941544,0.932993 + ,0.92388,0.91421,0.903989,0.893224,0.881921,0.870087,0.857729,0.844854 + ,0.83147,0.817585,0.803208,0.788346,0.77301,0.757209,0.740951,0.724247 + ,0.707107,0.689541,0.671559,0.653173,0.634393,0.615232,0.595699,0.575808 + ,0.55557,0.534998,0.514103,0.492898,0.471397,0.449611,0.427555,0.405241 + ,0.382683,0.359895,0.33689,0.313682,0.290285,0.266713,0.24298,0.219101 + ,0.19509,0.170962,0.14673,0.122411,0.0980171,0.0735646,0.0490677,0.0245412 + ,6.12323e-17,-0.0245412,-0.0490677,-0.0735646,-0.0980171,-0.122411,-0.14673,-0.170962 + ,-0.19509,-0.219101,-0.24298,-0.266713,-0.290285,-0.313682,-0.33689,-0.359895 + ,-0.382683,-0.405241,-0.427555,-0.449611,-0.471397,-0.492898,-0.514103,-0.534998 + ,-0.55557,-0.575808,-0.595699,-0.615232,-0.634393,-0.653173,-0.671559,-0.689541 + ,-0.707107,-0.724247,-0.740951,-0.757209,-0.77301,-0.788346,-0.803208,-0.817585 + ,-0.83147,-0.844854,-0.857729,-0.870087,-0.881921,-0.893224,-0.903989,-0.91421 + ,-0.92388,-0.932993,-0.941544,-0.949528,-0.95694,-0.963776,-0.970031,-0.975702 + ,-0.980785,-0.985278,-0.989177,-0.99248,-0.995185,-0.99729,-0.998795,-0.999699 + ,-1,-0.999699,-0.998795,-0.99729,-0.995185,-0.99248,-0.989177,-0.985278 + ,-0.980785,-0.975702,-0.970031,-0.963776,-0.95694,-0.949528,-0.941544,-0.932993 + ,-0.92388,-0.91421,-0.903989,-0.893224,-0.881921,-0.870087,-0.857729,-0.844854 + ,-0.83147,-0.817585,-0.803208,-0.788346,-0.77301,-0.757209,-0.740951,-0.724247 + ,-0.707107,-0.689541,-0.671559,-0.653173,-0.634393,-0.615232,-0.595699,-0.575808 + ,-0.55557,-0.534998,-0.514103,-0.492898,-0.471397,-0.449611,-0.427555,-0.405241 + ,-0.382683,-0.359895,-0.33689,-0.313682,-0.290285,-0.266713,-0.24298,-0.219101 + ,-0.19509,-0.170962,-0.14673,-0.122411,-0.0980171,-0.0735646,-0.0490677,-0.0245412 + ,-1.83697e-16,0.0245412,0.0490677,0.0735646,0.0980171,0.122411,0.14673,0.170962 + ,0.19509,0.219101,0.24298,0.266713,0.290285,0.313682,0.33689,0.359895 + ,0.382683,0.405241,0.427555,0.449611,0.471397,0.492898,0.514103,0.534998 + ,0.55557,0.575808,0.595699,0.615232,0.634393,0.653173,0.671559,0.689541 + ,0.707107,0.724247,0.740951,0.757209,0.77301,0.788346,0.803208,0.817585 + ,0.83147,0.844854,0.857729,0.870087,0.881921,0.893224,0.903989,0.91421 + ,0.92388,0.932993,0.941544,0.949528,0.95694,0.963776,0.970031,0.975702 + ,0.980785,0.985278,0.989177,0.99248,0.995185,0.99729,0.998795,0.999699 + +}; + diff --git a/src/post/goom/mathtools.h b/src/post/goom/mathtools.h index 7ed0f80ef..0e2293c3f 100755 --- a/src/post/goom/mathtools.h +++ b/src/post/goom/mathtools.h @@ -1,7 +1,11 @@ +#ifndef MATHTOOLS_H +#define MATHTOOLS_H + + #define _double2fixmagic (68719476736.0*1.5) -//2^36 * 1.5, (52-_shiftamt=36) uses limited precisicion to floor +/* 2^36 * 1.5, (52-_shiftamt=36) uses limited precisicion to floor */ #define _shiftamt 16 -//16.16 fixed point representation, +/* 16.16 fixed point representation */ #if BigEndian_ #define iexp_ 0 @@ -9,14 +13,14 @@ #else #define iexp_ 1 #define iman_ 0 -#endif //BigEndian_ +#endif /* BigEndian_ */ +/* TODO: this optimization is very efficient: put it again when all works #ifdef HAVE_MMX -#define F2I(dbl,i) \ -{double d = dbl + _double2fixmagic; i = ((int*)&d)[iman_] >> _shiftamt; } -#else +#define F2I(dbl,i) {double d = dbl + _double2fixmagic; i = ((int*)&d)[iman_] >> _shiftamt;} +#else*/ #define F2I(dbl,i) i=(int)dbl; -#endif +/*#endif*/ #if 0 #define SINCOS(f,s,c) \ @@ -24,3 +28,9 @@ #else #define SINCOS(f,s,c) {s=sin(f);c=cos(f);} #endif + +extern float sin256[256]; +extern float cos256[256]; + +#endif + diff --git a/src/post/goom/mmx.c b/src/post/goom/mmx.c new file mode 100644 index 000000000..3188d9bed --- /dev/null +++ b/src/post/goom/mmx.c @@ -0,0 +1,272 @@ +#define BUFFPOINTNB 16 +#define BUFFPOINTMASK 0xffff +#define BUFFINCR 0xff + +#include "mmx.h" +#include "goom_graphic.h" + +#define sqrtperte 16 +// faire : a % sqrtperte <=> a & pertemask +#define PERTEMASK 0xf +// faire : a / sqrtperte <=> a >> PERTEDEC +#define PERTEDEC 4 + +int mmx_supported () { + return (mm_support()&0x1); +} + +void zoom_filter_mmx (int prevX, int prevY, + unsigned int *expix1, unsigned int *expix2, + int *brutS, int *brutD, int buffratio, + int precalCoef[16][16]) +{ + unsigned int ax = (prevX-1)<> BUFFPOINTNB); + brutSmypos = brutS[myPos2]; + py = brutSmypos + (((brutD[myPos2] - brutSmypos)*buffratio) >> BUFFPOINTNB); + + if ((py>=ay) || (px>=ax)) { + pos=coeffs=0; + } + else { + pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC)); + // coef en modulo 15 + coeffs = precalCoef [px & PERTEMASK][py & PERTEMASK]; + } + + __asm__ __volatile__ ( + "movd %2, %%mm6 \n\t" + + /* recuperation des deux premiers pixels dans mm0 et mm1 */ + "movq (%3,%1,4), %%mm0 \n\t" /* b1-v1-r1-a1-b2-v2-r2-a2 */ + "movq %%mm0, %%mm1 \n\t" /* b1-v1-r1-a1-b2-v2-r2-a2 */ + + /* depackage du premier pixel */ + "punpcklbw %%mm7, %%mm0 \n\t" /* 00-b2-00-v2-00-r2-00-a2 */ + + "movq %%mm6, %%mm5 \n\t" /* ??-??-??-??-c4-c3-c2-c1 */ + /* depackage du 2ieme pixel */ + "punpckhbw %%mm7, %%mm1 \n\t" /* 00-b1-00-v1-00-r1-00-a1 */ + + /* extraction des coefficients... */ + "punpcklbw %%mm5, %%mm6 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */ + "movq %%mm6, %%mm4 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */ + "movq %%mm6, %%mm5 \n\t" /* c4-c4-c3-c3-c2-c2-c1-c1 */ + + "punpcklbw %%mm5, %%mm6 \n\t" /* c2-c2-c2-c2-c1-c1-c1-c1 */ + "punpckhbw %%mm5, %%mm4 \n\t" /* c4-c4-c4-c4-c3-c3-c3-c3 */ + + "movq %%mm6, %%mm3 \n\t" /* c2-c2-c2-c2-c1-c1-c1-c1 */ + + "punpcklbw %%mm7, %%mm6 \n\t" /* 00-c1-00-c1-00-c1-00-c1 */ + "punpckhbw %%mm7, %%mm3 \n\t" /* 00-c2-00-c2-00-c2-00-c2 */ + + /* multiplication des pixels par les coefficients */ + "pmullw %%mm6, %%mm0 \n\t" /* c1*b2-c1*v2-c1*r2-c1*a2 */ + "pmullw %%mm3, %%mm1 \n\t" /* c2*b1-c2*v1-c2*r1-c2*a1 */ + "paddw %%mm1, %%mm0 \n\t" + + /* ...extraction des 2 derniers coefficients */ + "movq %%mm4, %%mm5 \n\t" /* c4-c4-c4-c4-c3-c3-c3-c3 */ + "punpcklbw %%mm7, %%mm4 \n\t" /* 00-c3-00-c3-00-c3-00-c3 */ + "punpckhbw %%mm7, %%mm5 \n\t" /* 00-c4-00-c4-00-c4-00-c4 */ + + /* ajouter la longueur de ligne a esi */ + "addl 8(%%ebp),%1 \n\t" + + /* recuperation des 2 derniers pixels */ + "movq (%3,%1,4), %%mm1 \n\t" + "movq %%mm1, %%mm2 \n\t" + + /* depackage des pixels */ + "punpcklbw %%mm7, %%mm1 \n\t" + "punpckhbw %%mm7, %%mm2 \n\t" + + /* multiplication pas les coeffs */ + "pmullw %%mm4, %%mm1 \n\t" + "pmullw %%mm5, %%mm2 \n\t" + + /* ajout des valeurs obtenues à la valeur finale */ + "paddw %%mm1, %%mm0 \n\t" + "paddw %%mm2, %%mm0 \n\t" + + /* division par 256 = 16+16+16+16, puis repackage du pixel final */ + "psrlw $8, %%mm0 \n\t" + "packuswb %%mm7, %%mm0 \n\t" + + "movd %%mm0,%0 \n\t" + :"=g"(expix2[loop]) + :"r"(pos),"r"(coeffs),"r"(expix1) + + ); + + emms(); + } +} + +#define DRAWMETHOD_PLUS_MMX(_out,_backbuf,_col) \ +{ \ + movd_m2r(_backbuf, mm0); \ + paddusb_m2r(_col, mm0); \ + movd_r2m(mm0, _out); \ +} + +#define DRAWMETHOD DRAWMETHOD_PLUS_MMX(*p,*p,col) + +void draw_line_mmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) +{ + int x, y, dx, dy, yy, xx; + Pixel *p; + + if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx)) + goto end_of_line; + + dx = x2 - x1; + dy = y2 - y1; + if (x1 >= x2) { + int tmp; + + tmp = x1; + x1 = x2; + x2 = tmp; + tmp = y1; + y1 = y2; + y2 = tmp; + dx = x2 - x1; + dy = y2 - y1; + } + + /* vertical line */ + if (dx == 0) { + if (y1 < y2) { + p = &(data[(screenx * y1) + x1]); + for (y = y1; y <= y2; y++) { + DRAWMETHOD; + p += screenx; + } + } + else { + p = &(data[(screenx * y2) + x1]); + for (y = y2; y <= y1; y++) { + DRAWMETHOD; + p += screenx; + } + } + goto end_of_line; + } + /* horizontal line */ + if (dy == 0) { + if (x1 < x2) { + p = &(data[(screenx * y1) + x1]); + for (x = x1; x <= x2; x++) { + DRAWMETHOD; + p++; + } + goto end_of_line; + } + else { + p = &(data[(screenx * y1) + x2]); + for (x = x2; x <= x1; x++) { + DRAWMETHOD; + p++; + } + goto end_of_line; + } + } + /* 1 */ + /* \ */ + /* \ */ + /* 2 */ + if (y2 > y1) { + /* steep */ + if (dy > dx) { + dx = ((dx << 16) / dy); + x = x1 << 16; + for (y = y1; y <= y2; y++) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p++; + /* DRAWMETHOD; */ + } + x += dx; + } + goto end_of_line; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + } + } + /* 2 */ + /* / */ + /* / */ + /* 1 */ + else { + /* steep */ + if (-dy > dx) { + dx = ((dx << 16) / -dy); + x = (x1 + 1) << 16; + for (y = y1; y >= y2; y--) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p--; + /* DRAWMETHOD; */ + } + x += dx; + } + goto end_of_line; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + goto end_of_line; + } + } +end_of_line: + emms(); + /* __asm__ __volatile__ ("emms"); */ +} + diff --git a/src/post/goom/mmx.h b/src/post/goom/mmx.h index 2a0ca62a4..fe095de12 100755 --- a/src/post/goom/mmx.h +++ b/src/post/goom/mmx.h @@ -54,6 +54,183 @@ typedef union { float s[2]; /* Single-precision (32-bit) value */ } __attribute__ ((aligned (8))) mmx_t; /* On an 8-byte (64-bit) boundary */ + + +/* Function to test if multimedia instructions are supported... +*/ +inline extern int +mm_support(void) +{ + /* Returns 1 if MMX instructions are supported, + 3 if Cyrix MMX and Extended MMX instructions are supported + 5 if AMD MMX and 3DNow! instructions are supported + 13 if AMD Extended MMX, &3dNow supported + 0 if hardware does not support any of these + */ + register int rval = 0; + + __asm__ __volatile__ ( + /* See if CPUID instruction is supported ... */ + /* ... Get copies of EFLAGS into eax and ecx */ + "pushf\n\t" + "popl %%eax\n\t" + "movl %%eax, %%ecx\n\t" + + /* ... Toggle the ID bit in one copy and store */ + /* to the EFLAGS reg */ + "xorl $0x200000, %%eax\n\t" + "push %%eax\n\t" + "popf\n\t" + + /* ... Get the (hopefully modified) EFLAGS */ + "pushf\n\t" + "popl %%eax\n\t" + + /* ... Compare and test result */ + "xorl %%eax, %%ecx\n\t" + "testl $0x200000, %%ecx\n\t" + "jz NotSupported1\n\t" /* CPUID not supported */ + + + /* Get standard CPUID information, and + go to a specific vendor section */ + "movl $0, %%eax\n\t" + "cpuid\n\t" + + /* Check for Intel */ + "cmpl $0x756e6547, %%ebx\n\t" + "jne TryAMD\n\t" + "cmpl $0x49656e69, %%edx\n\t" + "jne TryAMD\n\t" + "cmpl $0x6c65746e, %%ecx\n" + "jne TryAMD\n\t" + "jmp Intel\n\t" + + /* Check for AMD */ + "\nTryAMD:\n\t" + "cmpl $0x68747541, %%ebx\n\t" + "jne TryCyrix\n\t" + "cmpl $0x69746e65, %%edx\n\t" + "jne TryCyrix\n\t" + "cmpl $0x444d4163, %%ecx\n" + "jne TryCyrix\n\t" + "jmp AMD\n\t" + + /* Check for Cyrix */ + "\nTryCyrix:\n\t" + "cmpl $0x69727943, %%ebx\n\t" + "jne NotSupported2\n\t" + "cmpl $0x736e4978, %%edx\n\t" + "jne NotSupported3\n\t" + "cmpl $0x64616574, %%ecx\n\t" + "jne NotSupported4\n\t" + /* Drop through to Cyrix... */ + + + /* Cyrix Section */ + /* See if extended CPUID level 80000001 is supported */ + /* The value of CPUID/80000001 for the 6x86MX is undefined + according to the Cyrix CPU Detection Guide (Preliminary + Rev. 1.01 table 1), so we'll check the value of eax for + CPUID/0 to see if standard CPUID level 2 is supported. + According to the table, the only CPU which supports level + 2 is also the only one which supports extended CPUID levels. + */ + "cmpl $0x2, %%eax\n\t" + "jne MMXtest\n\t" /* Use standard CPUID instead */ + + /* Extended CPUID supported (in theory), so get extended + features */ + "movl $0x80000001, %%eax\n\t" + "cpuid\n\t" + "testl $0x00800000, %%eax\n\t" /* Test for MMX */ + "jz NotSupported5\n\t" /* MMX not supported */ + "testl $0x01000000, %%eax\n\t" /* Test for Ext'd MMX */ + "jnz EMMXSupported\n\t" + "movl $1, %0\n\n\t" /* MMX Supported */ + "jmp Return\n\n" + "EMMXSupported:\n\t" + "movl $3, %0\n\n\t" /* EMMX and MMX Supported */ + "jmp Return\n\t" + + + /* AMD Section */ + "AMD:\n\t" + + /* See if extended CPUID is supported */ + "movl $0x80000000, %%eax\n\t" + "cpuid\n\t" + "cmpl $0x80000000, %%eax\n\t" + "jl MMXtest\n\t" /* Use standard CPUID instead */ + + /* Extended CPUID supported, so get extended features */ + "movl $0x80000001, %%eax\n\t" + "cpuid\n\t" + "testl $0x00800000, %%edx\n\t" /* Test for MMX */ + "jz NotSupported6\n\t" /* MMX not supported */ + "testl $0x80000000, %%edx\n\t" /* Test for 3DNow! */ + "jnz ThreeDNowSupported\n\t" + "movl $1, %0\n\n\t" /* MMX Supported */ + "jmp Return\n\n" + "ThreeDNowSupported:\n\t" + "testl $0x40000000, %%edx\n\t" /* Test AMD Extended MMX */ + "jnz AMDXMMXSupported\n\t" + "movl $5, %0\n\n\t" /* 3DNow! and MMX Supported */ + "jmp Return\n\t" + "AMDXMMXSupported:\n\t" + "movl $13, %0\n\n\t" /* XMMX, 3DNow! and MMX Supported */ + "jmp Return\n\t" + + + /* Intel Section */ + "Intel:\n\t" + + /* Check for MMX */ + "MMXtest:\n\t" + "movl $1, %%eax\n\t" + "cpuid\n\t" + "testl $0x00800000, %%edx\n\t" /* Test for MMX */ + "jz NotSupported7\n\t" /* MMX Not supported */ + "movl $1, %0\n\n\t" /* MMX Supported */ + "jmp Return\n\t" + + /* Nothing supported */ + "\nNotSupported1:\n\t" + "#movl $101, %0\n\n\t" + "\nNotSupported2:\n\t" + "#movl $102, %0\n\n\t" + "\nNotSupported3:\n\t" + "#movl $103, %0\n\n\t" + "\nNotSupported4:\n\t" + "#movl $104, %0\n\n\t" + "\nNotSupported5:\n\t" + "#movl $105, %0\n\n\t" + "\nNotSupported6:\n\t" + "#movl $106, %0\n\n\t" + "\nNotSupported7:\n\t" + "#movl $107, %0\n\n\t" + "movl $0, %0\n\n\t" + + "Return:\n\t" + : "=X" (rval) + : /* no input */ + : "eax", "ebx", "ecx", "edx" + ); + + /* Return */ + return(rval); +} + +/* Function to test if mmx instructions are supported... +*/ +inline extern int +mmx_ok(void) +{ + /* Returns 1 if MMX instructions are supported, 0 otherwise */ + return ( mm_support() & 0x1 ); +} + + /* Helper functions for the instruction macros that follow... (note that memory-to-register, m2r, instructions are nearly as efficient as register-to-register, r2r, instructions; @@ -521,12 +698,14 @@ typedef union { #define emms() \ { \ printf("emms()\n"); \ - __asm__ __volatile__ ("emms"); \ + __asm__ __volatile__ ("emms" \ + "st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)"); \ } #else -#define emms() __asm__ __volatile__ ("emms") +#define emms() __asm__ __volatile__ ("emms"::: \ + "st(1)","st(2)","st(3)","st(4)","st(5)","st(6)","st(7)") #endif diff --git a/src/post/goom/plugin_info.c b/src/post/goom/plugin_info.c new file mode 100644 index 000000000..31627f96f --- /dev/null +++ b/src/post/goom/plugin_info.c @@ -0,0 +1,214 @@ +#include "goom_plugin_info.h" +#include "cpu_info.h" +#include "default_scripts.h" +#include "drawmethods.h" +#include +#include + + +#ifdef CPU_POWERPC +#include +#include +#include "ppc_zoom_ultimate.h" +#include "ppc_drawings.h" +#endif /* CPU_POWERPC */ + + +#ifdef CPU_X86 +/* TODO: PUT THIS IN SEPARATE HEADERS */ +extern int xmmx_supported (); +extern int mmx_supported (); +extern void draw_line_mmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny); +extern void zoom_filter_mmx (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); +extern void zoom_filter_xmmx (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); +/* END TODO */ +#endif /* CPU_X86 */ + + + + +/* prototypes of methods */ + +void zoom_filter_c (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); +void create_output_with_brightness(Pixel *src, Pixel *output_buffer, int screensize, int iff); + + +static void setOptimizedMethods(PluginInfo *p) { + + unsigned int cpuFlavour = cpu_flavour(); + + /* set default methods */ + p->methods.draw_line = draw_line; + p->methods.zoom_filter = zoom_filter_c; + p->methods.create_output_with_brightness = create_output_with_brightness; + +#ifdef CPU_X86 + if (cpuFlavour & CPU_OPTION_XMMX) { +#ifdef VERBOSE + printf ("Extented MMX detected. Using the fastest methods !\n"); +#endif + p->methods.draw_line = draw_line_mmx; + p->methods.zoom_filter = zoom_filter_xmmx; + } + else if (cpuFlavour & CPU_OPTION_MMX) { +#ifdef VERBOSE + printf ("MMX detected. Using fast methods !\n"); +#endif + p->methods.draw_line = draw_line_mmx; + p->methods.zoom_filter = zoom_filter_mmx; + } +#ifdef VERBOSE + else + printf ("Too bad ! No SIMD optimization available for your CPU.\n"); +#endif +#endif /* CPU_X86 */ + +#ifdef CPU_POWERPC + + if (cpuFlavour & CPU_OPTION_64_BITS) { + p->methods.create_output_with_brightness = ppc_brightness_G5; + p->methods.zoom_filter = ppc_zoom_generic; + } + else if (cpuFlavour & CPU_OPTION_ALTIVEC) { + p->methods.create_output_with_brightness = ppc_brightness_G4; + p->methods.zoom_filter = ppc_zoom_G4; + } + else + { + p->methods.create_output_with_brightness = ppc_brightness_generic; + p->methods.zoom_filter = ppc_zoom_generic; + } +#endif /* CPU_POWERPC */ + +} + +void plugin_info_init(PluginInfo *pp, int nbVisuals) { + + PluginInfo p; + int i; + + p.sound.speedvar = p.sound.accelvar = p.sound.totalgoom = 0; + p.sound.prov_max = 0; + p.sound.goom_limit = 1; + p.sound.allTimesMax = 1; + + p.sound.volume_p = secure_f_feedback("Sound Volume"); + p.sound.accel_p = secure_f_feedback("Sound Acceleration"); + p.sound.speed_p = secure_f_feedback("Sound Speed"); + p.sound.goom_limit_p = secure_f_feedback("Goom Limit"); + p.sound.last_goom_p = secure_f_feedback("Goom Detection"); + p.sound.last_biggoom_p = secure_f_feedback("Big Goom Detection"); + p.sound.goom_power_p = secure_f_feedback("Goom Power"); + + p.sound.biggoom_speed_limit_p = secure_i_param("Big Goom Speed Limit"); + IVAL(p.sound.biggoom_speed_limit_p) = 10; + IMIN(p.sound.biggoom_speed_limit_p) = 0; + IMAX(p.sound.biggoom_speed_limit_p) = 100; + ISTEP(p.sound.biggoom_speed_limit_p) = 1; + + p.sound.biggoom_factor_p = secure_i_param("Big Goom Factor"); + IVAL(p.sound.biggoom_factor_p) = 10; + IMIN(p.sound.biggoom_factor_p) = 0; + IMAX(p.sound.biggoom_factor_p) = 100; + ISTEP(p.sound.biggoom_factor_p) = 1; + + p.sound.params = plugin_parameters ("Sound", 11); + + p.nbParams = 0; + p.nbVisuals = nbVisuals; + p.visuals = (VisualFX**)malloc(sizeof(VisualFX*)*nbVisuals); + + *pp = p; + pp->sound.params.params[0] = &pp->sound.biggoom_speed_limit_p; + pp->sound.params.params[1] = &pp->sound.biggoom_factor_p; + pp->sound.params.params[2] = 0; + pp->sound.params.params[3] = &pp->sound.volume_p; + pp->sound.params.params[4] = &pp->sound.accel_p; + pp->sound.params.params[5] = &pp->sound.speed_p; + pp->sound.params.params[6] = 0; + pp->sound.params.params[7] = &pp->sound.goom_limit_p; + pp->sound.params.params[8] = &pp->sound.goom_power_p; + pp->sound.params.params[9] = &pp->sound.last_goom_p; + pp->sound.params.params[10] = &pp->sound.last_biggoom_p; + + pp->statesNumber = 8; + pp->statesRangeMax = 510; + { + GoomState states[8] = { + {1,0,0,1,4, 0, 100}, + {1,0,0,0,1, 101, 140}, + {1,0,0,1,2, 141, 200}, + {0,1,0,1,2, 201, 260}, + {0,1,0,1,0, 261, 330}, + {0,1,1,1,4, 331, 400}, + {0,0,1,0,5, 401, 450}, + {0,0,1,1,1, 451, 510}}; + for (i=0;i<8;++i) + pp->states[i] = states[i]; + } + pp->curGState = &(pp->states[6]); + + /* datas for the update loop */ + pp->update.lockvar = 0; + pp->update.goomvar = 0; + pp->update.loopvar = 0; + pp->update.stop_lines = 0; + pp->update.ifs_incr = 1; /* dessiner l'ifs (0 = non: > = increment) */ + pp->update.decay_ifs = 0; /* disparition de l'ifs */ + pp->update.recay_ifs = 0; /* dedisparition de l'ifs */ + pp->update.cyclesSinceLastChange = 0; + pp->update.drawLinesDuration = 80; + pp->update.lineMode= pp->update.drawLinesDuration; + + pp->update.switchMultAmount = (29.0f/30.0f); + pp->update.switchIncrAmount = 0x7f; + pp->update.switchMult = 1.0f; + pp->update.switchIncr = pp->update.switchIncrAmount; + + pp->update.stateSelectionRnd = 0; + pp->update.stateSelectionBlocker = 0; + pp->update.previousZoomSpeed = 128; + pp->update.timeOfTitleDisplay = 0; + + pp->update_message.affiche = 0; + + { + ZoomFilterData zfd = { + 127, 8, 16, + 1, 1, 0, NORMAL_MODE, + 0, 0, 0, 0, 0 + }; + pp->update.zoomFilterData = zfd; + } + + setOptimizedMethods(pp); + + pp->scanner = goom_script_scanner_new(); + pp->main_scanner = goom_script_scanner_new(); + pp->main_script_str = GOOM_MAIN_SCRIPT; + + for (i = 0; i < 0xffff; i++) { + pp->sintable[i] = (int) (1024 * sin ((double) i * 360 / (sizeof (pp->sintable) / sizeof (pp->sintable[0]) - 1) * 3.141592 / 180) + .5); + /* sintable [us] = (int)(1024.0f * sin (us*2*3.31415f/0xffff)) ; */ + } +} + +void plugin_info_add_visual(PluginInfo *p, int i, VisualFX *visual) { + p->visuals[i] = visual; + if (i == p->nbVisuals-1) { + ++i; + p->nbParams = 1; + while (i--) { + if (p->visuals[i]->params) + p->nbParams++; + } + p->params = (PluginParameters *)malloc(sizeof(PluginParameters)*p->nbParams); + i = p->nbVisuals; + p->nbParams = 1; + p->params[0] = p->sound.params; + while (i--) { + if (p->visuals[i]->params) + p->params[p->nbParams++] = *(p->visuals[i]->params); + } + } +} diff --git a/src/post/goom/ppc_drawings.h b/src/post/goom/ppc_drawings.h new file mode 100644 index 000000000..ee438c289 --- /dev/null +++ b/src/post/goom/ppc_drawings.h @@ -0,0 +1,18 @@ +/* + * ppc_drawings.h + * Goom + * + * Created by Guillaume Borios on Sun Dec 28 2003. + * Copyright (c) 2003 iOS. All rights reserved. + * + */ + +/* Generic PowerPC Code */ +void ppc_brightness_generic(Pixel *src, Pixel *dest, int size, int coeff); + +/* G4 Specific PowerPC Code (Possible use of Altivec and Data Streams) */ +void ppc_brightness_G4(Pixel *src, Pixel *dest, int size, int coeff); + +/* G5 Specific PowerPC Code (Possible use of Altivec) */ +void ppc_brightness_G5(Pixel *src, Pixel *dest, int size, int coeff); + diff --git a/src/post/goom/ppc_drawings.s b/src/post/goom/ppc_drawings.s new file mode 100644 index 000000000..37d749381 --- /dev/null +++ b/src/post/goom/ppc_drawings.s @@ -0,0 +1,370 @@ +; PowerPC optimized drawing methods for Goom +; © 2003 Guillaume Borios +; This Source Code is released under the terms of the General Public License + +; Change log : +; 30 May 2003 : File creation + +; Section definition : We use a read only code section for the whole file +.text + + +; -------------------------------------------------------------------------------------- +; Single 32b pixel drawing macros +; Usage : +; DRAWMETHOD_XXXX_MACRO *pixelIN, *pixelOUT, COLOR, WR1, WR2, WR3, WR4 +; Only the work registers (WR) can be touched by the macros +; +; Available methods : +; DRAWMETHOD_DFLT_MACRO : Default drawing method (Actually OVRW) +; DRAWMETHOD_PLUS_MACRO : RVB Saturated per channel addition (SLOWEST) +; DRAWMETHOD_HALF_MACRO : 50% Transparency color drawing +; DRAWMETHOD_OVRW_MACRO : Direct COLOR drawing (FASTEST) +; DRAWMETHOD_B_OR_MACRO : Bitwise OR +; DRAWMETHOD_BAND_MACRO : Bitwise AND +; DRAWMETHOD_BXOR_MACRO : Bitwise XOR +; DRAWMETHOD_BNOT_MACRO : Bitwise NOT +; -------------------------------------------------------------------------------------- + +.macro DRAWMETHOD_OVRW_MACRO + stw $2,0($1) ;; *$1 <- $2 +.endmacro + +.macro DRAWMETHOD_B_OR_MACRO + lwz $3,0($0) ;; $3 <- *$0 + or $3,$3,$2 ;; $3 <- $3 | $2 + stw $3,0($1) ;; *$1 <- $3 +.endmacro + +.macro DRAWMETHOD_BAND_MACRO + lwz $3,0($0) ;; $3 <- *$0 + and $3,$3,$2 ;; $3 <- $3 & $2 + stw $3,0($1) ;; *$1 <- $3 +.endmacro + +.macro DRAWMETHOD_BXOR_MACRO + lwz $3,0($0) ;; $3 <- *$0 + xor $3,$3,$2 ;; $3 <- $3 ^ $2 + stw $3,0($1) ;; *$1 <- $3 +.endmacro + +.macro DRAWMETHOD_BNOT_MACRO + lwz $3,0($0) ;; $3 <- *$0 + nand $3,$3,$3 ;; $3 <- ~$3 + stw $3,0($1) ;; *$1 <- $3 +.endmacro + +.macro DRAWMETHOD_PLUS_MACRO + lwz $4,0($0) ;; $4 <- *$0 + andi. $3,$4,0xFF00 ;; $3 <- $4 & 0x0000FF00 + andi. $5,$2,0xFF00 ;; $5 <- $2 & 0x0000FF00 + add $3,$3,$5 ;; $3 <- $3 + $5 + rlwinm $5,$3,15,0,0 ;; $5 <- 0 | ($3[15] << 15) + srawi $5,$5,23 ;; $5 <- $5 >> 23 (algebraic for sign extension) + or $3,$3,$5 ;; $3 <- $3 | $5 + lis $5,0xFF ;; $5 <- 0x00FF00FF + addi $5,$5,0xFF + and $4,$4,$5 ;; $4 <- $4 & $5 + and $6,$2,$5 ;; $6 <- $2 & $5 + add $4,$4,$6 ;; $4 <- $4 + $6 + rlwinm $6,$4,7,0,0 ;; $6 <- 0 | ($4[7] << 7) + srawi $6,$6,15 ;; $6 <- $6 >> 15 (algebraic for sign extension) + rlwinm $5,$4,23,0,0 ;; $5 <- 0 | ($4[23] << 23) + srawi $5,$5,31 ;; $5 <- $5 >> 31 (algebraic for sign extension) + rlwimi $6,$5,0,24,31 ;; $6[24..31] <- $5[24..31] + or $4,$4,$6 ;; $4 <- $4 | $6 + rlwimi $4,$3,0,16,23 ;; $4[16..23] <- $3[16..23] + stw $4,0($1) ;; *$1 <- $4 +.endmacro + +.macro DRAWMETHOD_HALF_MACRO + lwz $4,0($0) ;; $4 <- *$0 + andi. $3,$4,0xFF00 ;; $3 <- $4 & 0x0000FF00 + andi. $5,$2,0xFF00 ;; $5 <- $2 & 0x0000FF00 + add $3,$3,$5 ;; $3 <- $3 + $5 + lis $5,0xFF ;; $5 <- 0x00FF00FF + addi $5,$5,0xFF + and $4,$4,$5 ;; $4 <- $4 & $5 + and $5,$2,$5 ;; $5 <- $2 & $5 + add $4,$4,$5 ;; $4 <- $4 + $5 + srwi $4,$4,1 ;; $4 <- $4 >> 1 + rlwimi $4,$3,31,16,23 ;; $4[16..23] <- $3[15..22] + stw $4,0($1) ;; *$1 <- $4 +.endmacro + +.macro DRAWMETHOD_DFLT_MACRO + DRAWMETHOD_PLUS_MACRO +.endmacro + +; -------------------------------------------------------------------------------------- + + + +; ************************************************************************************** +; void DRAWMETHOD_PLUS_PPC(unsigned int * buf, unsigned int _col); +; void DRAWMETHOD_PLUS_2_PPC(unsigned * in, unsigned int * out, unsigned int _col); +; ************************************************************************************** +.globl _DRAWMETHOD_PLUS_2_PPC +.align 3 +_DRAWMETHOD_PLUS_2_PPC: + DRAWMETHOD_PLUS_MACRO r3,r4,r5,r6,r7,r8,r9 + blr ;; return + +.globl _DRAWMETHOD_PLUS_PPC +.align 3 +_DRAWMETHOD_PLUS_PPC: + DRAWMETHOD_PLUS_MACRO r3,r3,r4,r5,r6,r7,r9 + blr ;; return + + +; ************************************************************************************** +; void DRAWMETHOD_HALF_PPC(unsigned int * buf, unsigned int _col); +; void DRAWMETHOD_HALF_2_PPC(unsigned * in, unsigned int * out, unsigned int _col); +; ************************************************************************************** +.globl _DRAWMETHOD_HALF_2_PPC +.align 3 +_DRAWMETHOD_HALF_2_PPC: + DRAWMETHOD_HALF_MACRO r3,r4,r5,r6,r7,r8 + blr ;; return + +.globl _DRAWMETHOD_HALF_PPC +.align 3 +_DRAWMETHOD_HALF_PPC: + DRAWMETHOD_HALF_MACRO r3,r3,r4,r5,r6,r7 + blr ;; return + + +; ************************************************************************************** +; void DRAW_LINE_PPC(unsigned int *data, int x1, int y1, int x2, int y2, unsigned int col, +; unsigned int screenx, unsigned int screeny) +; ************************************************************************************** +.globl _DRAW_LINE_PPC +.align 3 +_DRAW_LINE_PPC: + ;; NOT IMPLEMENTED YET + blr ;; return + + +; ************************************************************************************** +; void _ppc_brightness(Pixel * src, Pixel * dest, unsigned int size, unsigned int coeff) +; ************************************************************************************** + + +.const_data +.align 4 +vectorZERO: + .long 0,0,0,0 + .long 0x10101000, 0x10101001, 0x10101002, 0x10101003 + .long 0x10101004, 0x10101005, 0x10101006, 0x10101007 + .long 0x10101008, 0x10101009, 0x1010100A, 0x1010100B + .long 0x1010100C, 0x1010100D, 0x1010100E, 0x1010100F + + +.text + +.globl _ppc_brightness_G4 +.align 3 +_ppc_brightness_G4: + + +;; PowerPC Altivec code + srwi r5,r5,2 + mtctr r5 + +;;vrsave + mfspr r11,256 + lis r12,0xCFFC + mtspr 256,r12 + + lis r9,ha16(vectorZERO) + addi r9,r9,lo16(vectorZERO) + + vxor v0,v0,v0 ;; V0 = NULL vector + + addi r9,r9,16 + lvx v10,0,r9 + addi r9,r9,16 + lvx v11,0,r9 + addi r9,r9,16 + lvx v12,0,r9 + addi r9,r9,16 + lvx v13,0,r9 + + lis r9,ha16(vectortmpwork) + addi r9,r9,lo16(vectortmpwork) + stw r6,0(r9) + li r6,8 + stw r6,4(r9) + lvx v9,0,r9 + li r9,128 + vspltw v8,v9,0 + vspltw v9,v9,1 + +;; elt counter + li r9,0 + lis r7,0x0F01 + b L6 +.align 4 +L7: + lvx v1,r9,r3 + + vperm v4,v1,v0,v10 + ;********************* + add r10,r9,r3 + ;********************* + vperm v5,v1,v0,v11 + vperm v6,v1,v0,v12 + vperm v7,v1,v0,v13 + + vmulouh v4,v4,v8 + ;********************* + dst r10,r7,0 + ;********************* + vmulouh v5,v5,v8 + vmulouh v6,v6,v8 + vmulouh v7,v7,v8 + vsrw v4,v4,v9 + vsrw v5,v5,v9 + vsrw v6,v6,v9 + vsrw v7,v7,v9 + + vpkuwus v4,v4,v5 + vpkuwus v6,v6,v7 + vpkuhus v1,v4,v6 + + stvx v1,r9,r4 + addi r9,r9,16 + + bdnz L7 + + mtspr 256,r11 + blr + + +.globl _ppc_brightness_G5 +.align 3 +_ppc_brightness_G5: + + +;; PowerPC Altivec G5 code + srwi r5,r5,2 + mtctr r5 + +;;vrsave + mfspr r11,256 + lis r12,0xCFFC + mtspr 256,r12 + + lis r9,ha16(vectorZERO) + addi r9,r9,lo16(vectorZERO) + + vxor v0,v0,v0 ;; V0 = NULL vector + + addi r9,r9,16 + lvx v10,0,r9 + addi r9,r9,16 + lvx v11,0,r9 + addi r9,r9,16 + lvx v12,0,r9 + addi r9,r9,16 + lvx v13,0,r9 + + lis r9,ha16(vectortmpwork) + addi r9,r9,lo16(vectortmpwork) + stw r6,0(r9) + li r6,8 + stw r6,4(r9) + lvx v9,0,r9 + li r9,128 + vspltw v8,v9,0 + vspltw v9,v9,1 + +;; elt counter + li r9,0 + lis r7,0x0F01 + b L6 +.align 4 +L6: + lvx v1,r9,r3 + + vperm v4,v1,v0,v10 + ;********************* + add r10,r9,r3 + ;********************* + vperm v5,v1,v0,v11 + vperm v6,v1,v0,v12 + vperm v7,v1,v0,v13 + + vmulouh v4,v4,v8 + vmulouh v5,v5,v8 + vmulouh v6,v6,v8 + vmulouh v7,v7,v8 + vsrw v4,v4,v9 + vsrw v5,v5,v9 + vsrw v6,v6,v9 + vsrw v7,v7,v9 + + vpkuwus v4,v4,v5 + vpkuwus v6,v6,v7 + vpkuhus v1,v4,v6 + + stvx v1,r9,r4 + addi r9,r9,16 + + bdnz L6 + + mtspr 256,r11 + blr + + +.globl _ppc_brightness_generic +.align 3 +_ppc_brightness_generic: + lis r12,0x00FF + ori r12,r12,0x00FF + subi r3,r3,4 + subi r4,r4,4 + mtctr r5 + b L1 +.align 4 +L1: + lwzu r7,4(r3) + + rlwinm r8,r7,16,24,31 + rlwinm r9,r7,24,24,31 + mullw r8,r8,r6 + rlwinm r10,r7,0,24,31 + mullw r9,r9,r6 + srwi r8,r8,8 + mullw r10,r10,r6 + srwi r9,r9,8 + + rlwinm. r11,r8,0,0,23 + beq L2 + li r8,0xFF +L2: + srwi r10,r10,8 + rlwinm. r11,r9,0,0,23 + beq L3 + li r9,0xFF +L3: + rlwinm r7,r8,16,8,15 + rlwinm. r11,r10,0,0,23 + beq L4 + li r10,0xFF +L4: + rlwimi r7,r9,8,16,23 + rlwimi r7,r10,0,24,31 + + stwu r7,4(r4) + bdnz L1 + + blr + + + +.static_data +.align 4 +vectortmpwork: + .long 0,0,0,0 + diff --git a/src/post/goom/ppc_zoom_ultimate.h b/src/post/goom/ppc_zoom_ultimate.h new file mode 100644 index 000000000..d6932e7e6 --- /dev/null +++ b/src/post/goom/ppc_zoom_ultimate.h @@ -0,0 +1,14 @@ +/* + * ppc_zoom_ultimate.h + * Goom + * + * Created by Guillaume Borios on Sun Dec 28 2003. + * Copyright (c) 2003 iOS. All rights reserved. + * + */ + +/* Generic PowerPC Code */ +void ppc_zoom_generic (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); + +/* G4 Specific PowerPC Code (Possible use of Altivec and Data Streams) */ +void ppc_zoom_G4 (int sizeX, int sizeY, Pixel *src, Pixel *dest, int *brutS, int *brutD, int buffratio, int precalCoef[16][16]); \ No newline at end of file diff --git a/src/post/goom/ppc_zoom_ultimate.s b/src/post/goom/ppc_zoom_ultimate.s index f52d2a831..7b349906e 100644 --- a/src/post/goom/ppc_zoom_ultimate.s +++ b/src/post/goom/ppc_zoom_ultimate.s @@ -1,213 +1,305 @@ +; PowerPC optimized zoom for Goom +; © 2001-2003 Guillaume Borios +; This Source Code is released under the terms of the General Public License + +; Change log : +; 21 Dec 2003 : Use of altivec is now determined with a parameter + +; Section definition : We use a read only section .text -;.section text,__TEXT -.globl _ppc_zoom ;// name of the function to call by C program -; notes : -; this routine dynamically computes and applies a zoom filter -; do not use r0, r1, r2 and r3 -; registers are not saved so the call to this function must be the last thing done in the calling C function +; name of the function to call by C program : ppc_zoom +; We declare this label as a global to extend its scope outside this file +.globl _ppc_zoom_generic +.globl _ppc_zoom_G4 + +; Description : +; This routine dynamically computes and applies a zoom filter ; parameters : -; r3 <=> unsigned int * frompixmap -; r4 <=> unsigned int * topixmap -; r5 <=> unsigned int sizeX (in pixels) -; r6 <=> unsigned int sizeY (in pixels) +; r3 <=> unsigned int sizeX (in pixels) +; r4 <=> unsigned int sizeY (in pixels) +; r5 <=> unsigned int * frompixmap +; r6 <=> unsigned int * topixmap ; r7 <=> unsigned int * brutS ; r8 <=> unsigned int * brutD ; r9 <=> unsigned int buffratio ; r10 <=> int [16][16] precalccoeffs ; globals after init -; r3 <=> frompixmap - 1 byte needed for preincremental fetch (replaces r3) -; r4 <=> topixmap - 1 byte needed for preincremental fetch (replaces r4) -; r5 <=> ax = x max in 16th of pixels (replaces old r5) -; r6 <=> ay = y max in 16th of pixels (replaces old r6) -; r15 <=> row size in bytes -; r16 <=> 0xFF00FF (mask for parallel 32 bits pixs computing) +; r5 <=> frompixmap - 1 byte needed for preincremental fetch (replaces r5) +; r6 <=> topixmap - 1 byte needed for preincremental fetch (replaces r6) +; r3 <=> ax = x max in 16th of pixels (replaces old r3) +; r4 <=> ay = y max in 16th of pixels (replaces old r4) +; r20 <=> row size in bytes +; r12 <=> 0xFF00FF (mask for parallel 32 bits pixs computing) ; r30 <=> brutS - 1 byte needed for preincremental fetch (replaces r7) ; r31 <=> brutD - 1 byte needed for preincremental fetch (replaces r8) -; free reg -; r13 -; r18 - - -_ppc_zoom: ; symbole global sur lequel on va linker - -; avant tout, on va sauver les registres -stw r13,-76(r1) -stw r14,-72(r1) -stw r15,-68(r1) -stw r16,-64(r1) -stw r17,-60(r1) -stw r18,-56(r1) -stw r19,-52(r1) -stw r20,-48(r1) -stw r21,-44(r1) -stw r22,-40(r1) -stw r23,-36(r1) -stw r24,-32(r1) -stw r25,-28(r1) -stw r26,-24(r1) -stw r27,-20(r1) -stw r28,-16(r1) -stw r29,-12(r1) -stw r30,-8(r1) -stw r31,-4(r1) +; ABI notes : +; r1 is the Stack Pointer (SP) => Do not use +; r13..r31 are non-volatiles => Do not use + +_ppc_zoom_generic: +; Saves the used non volatile registers in the Mach-O stack s Red-Zone +stmw r18,-56(r1) ; init -dcbt 0,r8 -li r14,0 ; valeur par defaut si out of range : 0 (Noir) +li r18,0 ; Default value if out of range : 0 (Black) mr r11,r10 -lis r16,0xFF -mullw r17,r5,r6 ; calcul du nombre de pixels a faire -dcbt 0,r7 -subi r30,r8,4 -mulli r15,r5,4 -srawi r19,r15,2 -ori r16,r16,0xFF -subi r5,r5,1 -subi r6,r6,1 -mtspr ctr,r17 ; on met le nombre de pixels a faire dans le compteur de la boucle -subi r31,r7,4 -subi r4,r4,4 -mulli r5,r5,16 -mulli r6,r6,16 -li r13,32 +lis r12,0xFF +mullw r2,r3,r4 ; Number of pixels to compute +subi r30,r8,0 +slwi r20,r3,2 +srawi r19,r20,2 +ori r12,r12,0xFF +subi r3,r3,1 +subi r4,r4,1 +mtspr ctr,r2 ; Init the loop count (one loop per pixel computed) +subi r31,r7,0 +subi r6,r6,4 +slwi r3,r3,4 +slwi r4,r4,4 ;pre init for loop -lwzu r17,4(r31) ; px -lwzu r8,4(r30) ; px2 -lwzu r10,4(r30) ; py2 +lwz r2,0(r31) ; px +lwz r29,4(r31) ; py +lwz r8,0(r30) ; px2 +lwz r10,4(r30) ; py2 -1: - -lwzu r29,4(r31) ; py +L1: ; computes dynamically the position to fetch -sub r8,r8,r17 +sub r8,r8,r2 sub r10,r10,r29 mullw r8,r8,r9 +addi r31,r31,8 mullw r10,r10,r9 +addi r30,r30,8 + srawi r8,r8,16 srawi r10,r10,16 -add r17,r17,r8 +add r2,r2,r8 add r29,r29,r10 - ; if px>ax or py>ay goto outofrange -cmpl cr1,0,r17,r5 +; computes the attenuation coeffs and the original point address +rlwinm r10,r2,6,28-6,31-6 ; r10 <- (r2 << 2) & 0x000002D0 (r10=(r2%16)*4*16) +cmpl cr4,0,r2,r3 +rlwimi r10, r29, 2, 28-2, 31-2 ; r10 <- ((r29 << 2) & 0x0000002D) | (r10 & !0x0000002D) (r10=(r10%16)*4 | r10) +cmpl cr7,0,r29,r4 +srawi r29,r29,4 ; pos computing +bge- cr4,L4 +srawi r2,r2,4 ; pos computing +mullw r29, r29,r19 ; pos computing +bge- cr7,L4 + +; Channels notation : 00112233 (AARRVVBB) + +add r2,r2,r29 ; pos computing +lwzx r10,r11,r10 ; Loads coefs +slwi r2,r2,2 ; pos computing +add r2,r2,r5 ; pos computing +rlwinm r21,r10,0,24,31 ; Isolates coef1 (??????11 -> 00000011) +lwz r25,0(r2) ; Loads col1 -> r25 +lwz r26,4(r2) ; Loads col2 -> r26 +rlwinm r22,r10,24,24,31 ; Isolates coef2 (????22?? -> 00000022) +rlwinm r23,r10,16,24,31 ; Isolates coef3 (??33???? -> 00000033) +add r2,r2,r20 ; Adds one line for future load of col3 and col4 +and r8, r25,r12 ; Masks col1 channels 1 & 3 : 0x00XX00XX +rlwinm r24,r10,8,24,31 ; Isolates coef4 (44?????? -> 00000044) +andi. r25,r25,0xFF00 ; Masks col1 channel 2 : 0x0000XX00 +mullw r8, r8, r21 ; Applies coef1 on col1 channels 1 & 3 + + +; computes final pixel color +and r10,r26,r12 ; Masks col2 channels 1 & 3 : 0x00XX00XX +lwz r27,0(r2) ; Loads col3 -> r27 +mullw r10,r10,r22 ; Applies coef2 on col2 channels 1 & 3 +mullw r25,r25,r21 ; Applies coef1 on col1 channel 2 +andi. r29,r26,0xFF00 ; Masks col2 channel 2 : 0x0000XX00 +mullw r29,r29,r22 ; Applies coef2 on col2 channel 2 +lwz r28,4(r2) ; Loads col4 -> r28 +add r8 ,r8 ,r10 ; Adds col1 & col2 channels 1 & 3 +and r10,r27,r12 ; Masks col3 channels 1 & 3 : 0x00XX00XX +add r25,r25,r29 ; Adds col1 & col2 channel 2 +mullw r10,r10,r23 ; Applies coef3 on col3 channels 1 & 3 +andi. r29,r27,0xFF00 ; Masks col3 channel 2 : 0x0000XX00 +mullw r29,r29,r23 ; Applies coef3 on col3 channel 2 +lwz r2,0(r31) ; px +add r7 ,r8 ,r10 ; Adds col3 to (col1 + col2) channels 1 & 3 +and r10,r28,r12 ; Masks col4 channels 1 & 3 : 0x00XX00XX +mullw r10,r10,r24 ; Applies coef4 on col4 channels 1 & 3 +add r25,r25,r29 ; Adds col 3 to (col1 + col2) channel 2 +lwz r8,0(r30) ; px2 +andi. r28,r28,0xFF00 ; Masks col4 channel 2 : 0x0000XX00 +add r7 ,r7 ,r10 ; Adds col4 to (col1 + col2 + col3) channels 1 & 3 +lwz r10,4(r30) ; py2 +mullw r28,r28,r24 ; Applies coef4 on col4 channel 2 +srawi r7, r7, 8 ; (sum of channels 1 & 3) >> 8 +lwz r29,4(r31) ; py +add r25,r25,r28 ; Adds col 4 to (col1 + col2 + col3) channel 2 +rlwimi r7, r25, 24, 16, 23 ; (((sum of channels 2) >> 8 ) & 0x0000FF00) | ((sum of channels 1 and 3) & 0xFFFF00FF) +stwu r7,4(r6) ; Stores the computed pixel +bdnz L1 ; Iterate again if needed +b L3 ;goto end ; If not, returns from the function + + +; if out of range +L4: +stwu r18,4(r6) +lwz r8,0(r30) ; px2 +lwz r10,4(r30) ; py2 +lwz r2,0(r31) ; px +lwz r29,4(r31) ; py +bdnz L1 + + +L3: + +; Restore saved registers and return +lmw r18,-56(r1) +blr + + + + + + +_ppc_zoom_G4: + +; Saves the used non volatile registers in the Mach-O stack s Red-Zone +stmw r17,-60(r1) + +; init +li r18,0 ; Default value if out of range : 0 (Black) +mr r11,r10 +lis r12,0xFF +mullw r2,r3,r4 ; Number of pixels to compute +subi r30,r8,0 +slwi r20,r3,2 +srawi r19,r20,2 +ori r12,r12,0xFF +subi r3,r3,1 +subi r4,r4,1 +mtspr ctr,r2 ; Init the loop count (one loop per pixel computed) +subi r31,r7,0 +subi r6,r6,4 +slwi r3,r3,4 +slwi r4,r4,4 + +;pre init for loop +lwz r2,0(r31) ; px +lwz r29,4(r31) ; py +lwz r8,0(r30) ; px2 +lwz r10,4(r30) ; py2 + +;********************* +lis r17,0x0F01 + +L100: + +; computes dynamically the position to fetch +;mullw r8,r8,r29 +;mullw r2,r2,r29 +;add r2,r8,r2 +;srawi r2,r2,17 + +sub r8,r8,r2 +sub r10,r10,r29 +mullw r8,r8,r9 +addi r31,r31,8 +mullw r10,r10,r9 +addi r30,r30,8 + +dst r30,r17,0 + +srawi r8,r8,16 +srawi r10,r10,16 +add r2,r2,r8 +add r29,r29,r10 + +dst r31,r17,1 + +; if px>ax or py>ay goto outofrange ; computes the attenuation coeffs and the original point address -andi. r10,r29,0x0F ;coefv -cmpl cr2,0,r29,r6 -andi. r8,r17,0x0F ;coefh +rlwinm r10,r2,6,28-6,31-6 ; r10 <- (r2 << 2) & 0x000002D0 (r10=(r2%16)*4*16) +cmpl cr4,0,r2,r3 +rlwimi r10, r29, 2, 28-2, 31-2 ; r10 <- ((r29 << 2) & 0x0000002D) | (r10 & !0x0000002D) (r10=(r29%16)*4 | r10) +cmpl cr7,0,r29,r4 srawi r29,r29,4 ; pos computing -bgt- cr1,Loutofrange -srawi r17,r17,4 ; pos computing -mulli r10,r10,4 -bgt- cr2,Loutofrange +bge- cr4,L400 +srawi r2,r2,4 ; pos computing mullw r29, r29,r19 ; pos computing +bge- cr7,L400 -; NOTA : notation des couches : 00112233 (AARRVVBB) - -mulli r8,r8,4*16 -add r17,r17,r29 ; pos computing -add r10,r10,r8 -slwi r17,r17,2 ; pos computing -add r10,r10,r11 -dcbt 0,r10 -add r17,r17,r3 ; pos computing -lwz r10,0(r10) ; chargement des coefs -dcbt 0,r17 -andi. r21,r10,0xFF ; isolation du coef1 -srwi r10,r10,8 ; isolation du coeff2 etape 1/2 -lwz r25,0(r17) ; chargement de col1 ->r25 -andi. r22,r10,0xFF ; isolation du coef2 etape 2/2 -srwi r10,r10,8 ; isolation du coef3 etape 1/2 -and r8, r25,r16 ; masquage de col1 couches 1 & 3 : 0x00XX00XX -lwz r26,4(r17) ; chargement de col2 ->r26 -andi. r23,r10,0xFF ; isolation du coef3 etape 2/2 -mullw r8, r8, r21 ; application du coef1 sur col1 couches 1 & 3 -srwi r10,r10,8 ; isolation du coef4 etape 1/2 -andi. r25,r25,0xFF00 ; masquage de col1 couche 2 : 0x0000XX00 -add r17,r17,r15 ; ajout d'une ligne pour chargement futur de col3 -dcbt 0,r17 -andi. r24,r10,0xFF ; isolation du coef4 etape 2/2 +; Channels notation : 00112233 (AARRVVBB) +add r2,r2,r29 ; pos computing +lwzx r10,r11,r10 ; Loads coefs +slwi r2,r2,2 ; pos computing +add r2,r2,r5 ; pos computing +rlwinm r21,r10,0,24,31 ; Isolates coef1 (??????11 -> 00000011) +lwz r25,0(r2) ; Loads col1 -> r25 +lwz r26,4(r2) ; Loads col2 -> r26 +rlwinm r22,r10,24,24,31 ; Isolates coef2 (????22?? -> 00000022) +rlwinm r23,r10,16,24,31 ; Isolates coef3 (??33???? -> 00000033) +add r2,r2,r20 ; Adds one line for future load of col3 and col4 +and r8, r25,r12 ; Masks col1 channels 1 & 3 : 0x00XX00XX +rlwinm r24,r10,8,24,31 ; Isolates coef4 (44?????? -> 00000044) +dst r2,r17,2 +andi. r25,r25,0xFF00 ; Masks col1 channel 2 : 0x0000XX00 +mullw r8, r8, r21 ; Applies coef1 on col1 channels 1 & 3 ; computes final pixel color -and r10,r26,r16 ; masquage de col2 couches 1 & 3 : 0x00XX00XX -lwz r27,0(r17) ; chargement de col3 ->r27 -mullw r25,r25,r21 ; application du coef1 sur col1 couche 2 -mullw r10,r10,r22 ; application du coef2 sur col2 couches 1 & 3 -andi. r29,r26,0xFF00 ; masquage de col2 couche 2 : 0x0000XX00 -lwz r28,4(r17) ; chargement de col4 ->r28 -add r8 ,r8 ,r10 ; ajout de col1 & col2 couches 1 & 3 -mullw r29,r29,r22 ; application du coef2 sur col2 couche 2 -and r10,r27,r16 ; masquage de col3 couches 1 & 3 : 0x00XX00XX -add r25,r25,r29 ; ajout de col1 & col2 couche 2 -mullw r10,r10,r23 ; application du coef3 sur col3 couches 1 & 3 -andi. r29,r27,0xFF00 ; masquage de col3 couche 2 : 0x0000XX00 -add r8 ,r8 ,r10 ; ajout de col3 à (col1 + col2) couches 1 & 3 -mullw r29,r29,r23 ; application du coef3 sur col3 couche 2 -and r10,r28,r16 ; masquage de col4 couches 1 & 3 : 0x00XX00XX -add r25,r25,r29 ; ajout de col 3 à (col1 + col2) couche 2 -mullw r10,r10,r24 ; application du coef4 sur col4 couches 1 & 3 -andi. r28,r28,0xFF00 ; masquage de col4 couche 2 : 0x0000XX00 -add r8 ,r8 ,r10 ; ajout de col4 à (col1 + col2 + col3) couches 1 & 3 -lwzu r17,4(r31) ; px -dcbt 0,r31 -mullw r28,r28,r24 ; application du coef4 sur col4 couche 2 - -srawi r7, r8, 8 ; (somme des couches 1 & 3) >> 8 -add r25,r25,r28 ; ajout de col 4 à (col1 + col2 + col3) couche 2 -lwzu r8,4(r30) ; px2 -and r7, r7, r16 ; masquage de la valeur résiduelle dans le résultat des couches 1 & 3 - -srawi r25, r25, 8 ; (somme des couches 2) >> 8 -lwzu r10,4(r30) ; py2 -andi. r25,r25,0xFF00 ; masquage de la valeur résiduelle dans le résultat des couches 2 -or r7, r25, r7 ; association des couches (1 & 3) et 2 -stwu r7,4(r4) ; stockage du résultat final -bdnz+ 1boucle ; itération suivante si besoin -b Lend;goto end ; sinon sortie de boucle pour fin +and r10,r26,r12 ; Masks col2 channels 1 & 3 : 0x00XX00XX +lwz r27,0(r2) ; Loads col3 -> r27 +mullw r10,r10,r22 ; Applies coef2 on col2 channels 1 & 3 +mullw r25,r25,r21 ; Applies coef1 on col1 channel 2 +andi. r29,r26,0xFF00 ; Masks col2 channel 2 : 0x0000XX00 +mullw r29,r29,r22 ; Applies coef2 on col2 channel 2 +lwz r28,4(r2) ; Loads col4 -> r28 +add r8 ,r8 ,r10 ; Adds col1 & col2 channels 1 & 3 +and r10,r27,r12 ; Masks col3 channels 1 & 3 : 0x00XX00XX +add r25,r25,r29 ; Adds col1 & col2 channel 2 +mullw r10,r10,r23 ; Applies coef3 on col3 channels 1 & 3 +andi. r29,r27,0xFF00 ; Masks col3 channel 2 : 0x0000XX00 +mullw r29,r29,r23 ; Applies coef3 on col3 channel 2 +lwz r2,0(r31) ; px +add r7 ,r8 ,r10 ; Adds col3 to (col1 + col2) channels 1 & 3 +and r10,r28,r12 ; Masks col4 channels 1 & 3 : 0x00XX00XX +mullw r10,r10,r24 ; Applies coef4 on col4 channels 1 & 3 +add r25,r25,r29 ; Adds col 3 to (col1 + col2) channel 2 +lwz r8,0(r30) ; px2 +andi. r28,r28,0xFF00 ; Masks col4 channel 2 : 0x0000XX00 +add r7 ,r7 ,r10 ; Adds col4 to (col1 + col2 + col3) channels 1 & 3 +lwz r10,4(r30) ; py2 +mullw r28,r28,r24 ; Applies coef4 on col4 channel 2 +srawi r7, r7, 8 ; (sum of channels 1 & 3) >> 8 +lwz r29,4(r31) ; py +add r25,r25,r28 ; Adds col 4 to (col1 + col2 + col3) channel 2 +rlwimi r7, r25, 24, 16, 23 ; (((sum of channels 2) >> 8 ) & 0x0000FF00) | ((sum of channels 1 and 3) & 0xFFFF00FF) +stwu r7,4(r6) ; Stores the computed pixel +bdnz L100 ; Iterate again if needed +b L300 ;goto end ; If not, returns from the function ; if out of range -Loutofrange: -stwu r14,4(r4) -dcbtst r13,r4 ;touch for store -lwzu r8,4(r30) ; px2 -lwzu r10,4(r30) ; py2 -lwzu r17,4(r31) ; px -bdnz+ 1boucle - - -Lend: ; Fin de la routine, on restore les registres utilisés entre 13 et 31 - -lwz r14,-76(r1) -lwz r14,-72(r1) -lwz r15,-68(r1) -lwz r16,-64(r1) -lwz r17,-60(r1) -lwz r18,-56(r1) -lwz r19,-52(r1) -lwz r20,-48(r1) -lwz r21,-44(r1) -lwz r22,-40(r1) -lwz r23,-36(r1) -lwz r24,-32(r1) -lwz r25,-28(r1) -lwz r26,-24(r1) -lwz r27,-20(r1) -lwz r28,-16(r1) -lwz r29,-12(r1) -lwz r30,-8(r1) -lwz r31,-4(r1) - - -blr ; et on retourne \ No newline at end of file +L400: +stwu r18,4(r6) +lwz r8,0(r30) ; px2 +lwz r10,4(r30) ; py2 +lwz r2,0(r31) ; px +lwz r29,4(r31) ; py +bdnz L100 + + +L300: + +; Restore saved registers and return +lmw r17,-60(r1) +blr diff --git a/src/post/goom/sound_tester.c b/src/post/goom/sound_tester.c new file mode 100644 index 000000000..5b6c0fac5 --- /dev/null +++ b/src/post/goom/sound_tester.c @@ -0,0 +1,135 @@ +#include "sound_tester.h" + +#include +#include + +/* some constants */ +#define BIG_GOOM_DURATION 100 +#define BIG_GOOM_SPEED_LIMIT 0.1f + +#define ACCEL_MULT 0.95f +#define SPEED_MULT 0.99f + + +void evaluate_sound(gint16 data[2][512], SoundInfo *info) { + + int i; + float difaccel; + + /* find the max */ + int incvar = 0; + for (i = 0; i < 512; i+=2) { + if (incvar < data[0][i]) + incvar = data[0][i]; + } + + if (incvar > info->allTimesMax) + info->allTimesMax = incvar; + + /* volume sonore */ + info->volume = (float)incvar / (float)info->allTimesMax; + memcpy(info->samples[0],data[0],512*sizeof(short)); + memcpy(info->samples[1],data[1],512*sizeof(short)); + + difaccel = info->accelvar; + info->accelvar = info->volume; /* accel entre 0 et 1 */ + + /* transformations sur la vitesse du son */ + if (info->speedvar > 1.0f) + info->speedvar = 1.0f; + + if (info->speedvar < 0.1f) + info->accelvar *= (1.0f - (float)info->speedvar); + else if (info->speedvar < 0.3f) + info->accelvar *= (0.9f - (float)(info->speedvar-0.1f)/2.0f); + else + info->accelvar *= (0.8f - (float)(info->speedvar-0.3f)/4.0f); + + /* adoucissement de l'acceleration */ + info->accelvar *= ACCEL_MULT; + if (info->accelvar < 0) + info->accelvar = 0; + + difaccel = info->accelvar - difaccel; + if (difaccel < 0) + difaccel = - difaccel; + + /* mise a jour de la vitesse */ + info->speedvar = (info->speedvar + difaccel * 0.5f) / 2; + info->speedvar *= SPEED_MULT; + if (info->speedvar < 0) + info->speedvar = 0; + if (info->speedvar > 1) + info->speedvar = 1; + + /* temps du goom */ + info->timeSinceLastGoom++; + info->timeSinceLastBigGoom++; + info->cycle++; + + /* detection des nouveaux gooms */ + if ((info->speedvar > (float)IVAL(info->biggoom_speed_limit_p)/100.0f) + && (info->accelvar > info->bigGoomLimit) + && (info->timeSinceLastBigGoom > BIG_GOOM_DURATION)) { + info->timeSinceLastBigGoom = 0; + } + + if (info->accelvar > info->goom_limit) { + /* TODO: tester && (info->timeSinceLastGoom > 20)) { */ + info->totalgoom ++; + info->timeSinceLastGoom = 0; + info->goomPower = info->accelvar - info->goom_limit; + } + + if (info->accelvar > info->prov_max) + info->prov_max = info->accelvar; + + if (info->goom_limit>1) + info->goom_limit=1; + + /* toute les 2 secondes : vérifier si le taux de goom est correct + * et le modifier sinon.. */ + if (info->cycle % 64 == 0) { + if (info->speedvar<0.01f) + info->goom_limit *= 0.91; + if (info->totalgoom > 4) { + info->goom_limit+=0.02; + } + if (info->totalgoom > 7) { + info->goom_limit*=1.03f; + info->goom_limit+=0.03; + } + if (info->totalgoom > 16) { + info->goom_limit*=1.05f; + info->goom_limit+=0.04; + } + if (info->totalgoom == 0) { + info->goom_limit = info->prov_max - 0.02; + } + if ((info->totalgoom == 1) && (info->goom_limit > 0.02)) + info->goom_limit-=0.01; + info->totalgoom = 0; + info->bigGoomLimit = info->goom_limit * (1.0f + (float)IVAL(info->biggoom_factor_p)/500.0f); + info->prov_max = 0; + } + + /* mise a jour des parametres pour la GUI */ + FVAL(info->volume_p) = info->volume; + info->volume_p.change_listener(&info->volume_p); + FVAL(info->speed_p) = info->speedvar * 4; + info->speed_p.change_listener(&info->speed_p); + FVAL(info->accel_p) = info->accelvar; + info->accel_p.change_listener(&info->accel_p); + + FVAL(info->goom_limit_p) = info->goom_limit; + info->goom_limit_p.change_listener(&info->goom_limit_p); + FVAL(info->goom_power_p) = info->goomPower; + info->goom_power_p.change_listener(&info->goom_power_p); + FVAL(info->last_goom_p) = 1.0-((float)info->timeSinceLastGoom/20.0f); + info->last_goom_p.change_listener(&info->last_goom_p); + FVAL(info->last_biggoom_p) = 1.0-((float)info->timeSinceLastBigGoom/40.0f); + info->last_biggoom_p.change_listener(&info->last_biggoom_p); + + /* bigGoomLimit ==goomLimit*9/8+7 ? */ + } + diff --git a/src/post/goom/sound_tester.h b/src/post/goom/sound_tester.h new file mode 100644 index 000000000..51545a80e --- /dev/null +++ b/src/post/goom/sound_tester.h @@ -0,0 +1,11 @@ +#ifndef _SOUND_TESTER_H +#define _SOUND_TESTER_H + +#include "goom_plugin_info.h" +#include "goom_config.h" + +/** change les donnees du SoundInfo */ +void evaluate_sound(gint16 data[2][512], SoundInfo *sndInfo); + +#endif + diff --git a/src/post/goom/surf3d.c b/src/post/goom/surf3d.c index 356fe3e31..ba8c69094 100755 --- a/src/post/goom/surf3d.c +++ b/src/post/goom/surf3d.c @@ -1,4 +1,5 @@ #include "surf3d.h" +#include "goom_plugin_info.h" #include #include #include @@ -12,7 +13,7 @@ grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) { s->vertex = malloc (x*y*sizeof(v3d)); s->svertex = malloc (x*y*sizeof(v3d)); s->center = center; - + g->defx=defx; g->sizex=sizex; g->defz=defz; @@ -32,47 +33,31 @@ grid3d *grid3d_new (int sizex, int defx, int sizez, int defz, v3d center) { return g; } -//#undef HAVE_MMX -#include "drawmethods.h" +void grid3d_draw (PluginInfo *plug, grid3d *g, int color, int colorlow, + int dist, Pixel *buf, Pixel *back, int W,int H) { -void surf3d_draw (surf3d *s, int color, int dist, int *buf, int *back, int W,int H) { - int i; - int *p1; - int *p2; - v2d v2; - - for (i=0;inbvertex;i++) { - V3D_TO_V2D(s->svertex[i],v2,W,H,dist); - p1 = buf + v2.x + (v2.y*W); - p2 = back + v2.x + (v2.y*W); - if ((v2.x>=0) && (v2.y>=0) && (v2.xsurf.nbvertex * sizeof(v2d)); + v3d_to_v2d(g->surf.svertex, g->surf.nbvertex, W, H, dist, v2_array); for (x=0;xdefx;x++) { int z; - V3D_TO_V2D(g->surf.svertex[x],v2x,W,H,dist); + v2x = v2_array[x]; for (z=1;zdefz;z++) { - V3D_TO_V2D(g->surf.svertex[z*g->defx + x],v2,W,H,dist); + v2 = v2_array[z*g->defx + x]; if (((v2.x != -666) || (v2.y!=-666)) && ((v2x.x != -666) || (v2x.y!=-666))) { - draw_line(buf,v2x.x,v2x.y,v2.x,v2.y, colorlow, W, H); - draw_line(back,v2x.x,v2x.y,v2.x,v2.y, color, W, H); - DRAWMETHOD_DONE(); + plug->methods.draw_line (buf,v2x.x,v2x.y,v2.x,v2.y, colorlow, W, H); + plug->methods.draw_line (back,v2x.x,v2x.y,v2.x,v2.y, color, W, H); } v2x = v2; } } + + free(v2_array); } void surf3d_rotate (surf3d *s, float angle) { diff --git a/src/post/goom/surf3d.h b/src/post/goom/surf3d.h index 557b8b74f..482b6a090 100755 --- a/src/post/goom/surf3d.h +++ b/src/post/goom/surf3d.h @@ -2,6 +2,8 @@ #define _SURF3D_H #include "v3d.h" +#include "goom_graphic.h" +#include "goom_typedefs.h" typedef struct { v3d *vertex; @@ -29,7 +31,7 @@ void grid3d_update (grid3d *s, float angle, float *vals, float dist); /* low level */ void surf3d_draw (surf3d *s, int color, int dist, int *buf, int *back, int W,int H); -void grid3d_draw (grid3d *g, int color, int colorlow, int dist, int *buf, int *back, int W,int H); +void grid3d_draw (PluginInfo *plug, grid3d *g, int color, int colorlow, int dist, Pixel *buf, Pixel *back, int W,int H); void surf3d_rotate (surf3d *s, float angle); void surf3d_translate (surf3d *s); diff --git a/src/post/goom/surface.c b/src/post/goom/surface.c deleted file mode 100755 index 59bdf019e..000000000 --- a/src/post/goom/surface.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "surface.h" -#include -#include - -Surface * surface_new (int w, int h) { - Surface * s = (Surface*)malloc(sizeof(Surface)); - s->realstart = (int*)malloc(w*h*4 + 128); - s->buf = (int*)((uintptr_t)s->realstart + 128 - (((uintptr_t)s->realstart) % 128)); - s->size = w*h; - s->width = w; - s->height = h; - return s; -} - -void surface_delete (Surface **s) { - free ((*s)->realstart); - free (*s); - *s = NULL; -} diff --git a/src/post/goom/surface.h b/src/post/goom/surface.h deleted file mode 100755 index 61c73d19a..000000000 --- a/src/post/goom/surface.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _SURFACE_H -#define _SURFACE_H - -typedef struct { - int * buf; - int width; - int height; - int size; - - int * realstart; -} Surface; - -Surface * surface_new (int w, int h) ; -void surface_delete (Surface **s) ; - -#endif diff --git a/src/post/goom/tentacle3d.c b/src/post/goom/tentacle3d.c index ffb73d6ba..600511327 100755 --- a/src/post/goom/tentacle3d.c +++ b/src/post/goom/tentacle3d.c @@ -4,6 +4,8 @@ #include "surf3d.h" #include "goom_tools.h" #include "goom_config.h" +#include "goom_plugin_info.h" +#include "tentacle3d.h" #define D 256.0f @@ -11,40 +13,119 @@ #define definitionx 15 #define definitionz 45 -static float cycle = 0.0f; -static grid3d *grille[nbgrid]; -static float *vals; +typedef struct _TENTACLE_FX_DATA { + PluginParam enabled_bp; + PluginParameters params; -void tentacle_free (void) { + float cycle; + grid3d *grille[nbgrid]; + float *vals; + +#define NB_TENTACLE_COLORS 3 + int colors[NB_TENTACLE_COLORS]; + + int col; + int dstcol; + float lig; + float ligs; + + /* statics from pretty_move */ + float distt; + float distt2; + float rot; /* entre 0 et 2 * M_PI */ + int happens; + int rotation; + int lock; +} TentacleFXData; + +void tentacle_new (TentacleFXData *data); +void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, + short[2][512], float, int drawit, TentacleFXData *data); +void tentacle_free (TentacleFXData *data); + +/* + * VisualFX wrapper for the tentacles + */ + +void tentacle_fx_init(VisualFX *_this) { + + TentacleFXData *data = (TentacleFXData*)malloc(sizeof(TentacleFXData)); + + data->enabled_bp = secure_b_param("Enabled", 1); + data->params = plugin_parameters ("3D Tentacles", 1); + data->params.params[0] = &data->enabled_bp; + + data->cycle = 0.0f; + data->col = (0x28<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x5f<<(BLEU*8)); + data->dstcol = 0; + data->lig = 1.15f; + data->ligs = 0.1f; + + data->distt = 10.0f; + data->distt2 = 0.0f; + data->rot = 0.0f; /* entre 0 et 2 * M_PI */ + data->happens = 0; + + data->rotation = 0; + data->lock = 0; + data->colors[0] = (0x18<<(ROUGE*8))|(0x4c<<(VERT*8))|(0x2f<<(BLEU*8)); + data->colors[1] = (0x48<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x6f<<(BLEU*8)); + data->colors[2] = (0x58<<(ROUGE*8))|(0x3c<<(VERT*8))|(0x0f<<(BLEU*8)); + tentacle_new(data); + + _this->params = &data->params; + _this->fx_data = (void*)data; +} + +void tentacle_fx_apply(VisualFX *_this, Pixel *src, Pixel *dest, PluginInfo *goomInfo) { + + tentacle_update(goomInfo, dest, src, goomInfo->screen.width, goomInfo->screen.height, goomInfo->sound.samples, + (float)goomInfo->sound.accelvar, goomInfo->curGState->drawTentacle, (TentacleFXData*)_this->fx_data); +} + +void tentacle_fx_free(VisualFX *_this) { + tentacle_free((TentacleFXData*)_this->fx_data); + free(_this->fx_data); +} + +VisualFX tentacle_fx_create() { + VisualFX fx; + fx.init = tentacle_fx_init; + fx.apply = tentacle_fx_apply; + fx.free = tentacle_fx_free; + return fx; +} + +/* ----- */ + +void tentacle_free (TentacleFXData *data) { /* TODO : un vrai FREE GRID!! */ - free (vals); -// free (grille); + free (data->vals); } -void tentacle_new (void) { +void tentacle_new (TentacleFXData *data) { int tmp; v3d center = {0,-17.0,0}; - vals = malloc ((definitionx+20)*sizeof(float)); - + data->vals = (float*)malloc ((definitionx+20)*sizeof(float)); + for (tmp=0;tmpgrille[tmp] = grid3d_new (x, definitionx, z, definitionz + rand() % 10, center); center.y += 8; } } -static inline unsigned char -lighten (unsigned char value, float power) +static inline unsigned char lighten (unsigned char value, float power) { - int val = value; - float t = (float) val * log10(power) / 2.0; + int val = value; + float t = (float) val * log10(power) / 2.0; if (t > 0) { - val = (int) t; // (32.0f * log (t)); + val = (int) t; /* (32.0f * log (t)); */ if (val > 255) val = 255; if (val < 0) @@ -56,8 +137,7 @@ lighten (unsigned char value, float power) } } -static void -lightencolor (int *col, float power) +static void lightencolor (int *col, float power) { unsigned char *color; @@ -71,12 +151,12 @@ lightencolor (int *col, float power) *color = lighten (*color, power); } -// retourne x>>s , en testant le signe de x +/* retourne x>>s , en testant le signe de x */ #define ShiftRight(_x,_s) ((_x<0) ? -(-_x>>_s) : (_x>>_s)) -static -int evolutecolor (unsigned int src,unsigned int dest, - unsigned int mask, unsigned int incr) { +static int evolutecolor (unsigned int src,unsigned int dest, + unsigned int mask, unsigned int incr) { + int color = src & (~mask); src &= mask; dest &= mask; @@ -90,132 +170,116 @@ int evolutecolor (unsigned int src,unsigned int dest, return (src&mask)|color; } -static void pretty_move (float cycle, - float *dist,float *dist2, - float *rotangle) { - static float distt = 10.0f; - static float distt2 = 0.0f; - static float rot = 0.0f; // entre 0 et 2 * M_PI - static int happens = 0; +static void pretty_move (PluginInfo *goomInfo, float cycle, float *dist, float *dist2, float *rotangle, TentacleFXData *fx_data) { + + /* TODO: remove these STATICS !! */ float tmp; - static int rotation = 0; - static int lock = 0; - - if (happens) - happens -= 1; - else if (lock == 0) { - happens = iRAND(200)?0:100+iRAND(60); - lock = happens * 3 / 2; + + /* many magic numbers here... I don't really like that. */ + if (fx_data->happens) + fx_data->happens -= 1; + else if (fx_data->lock == 0) { + fx_data->happens = goom_irand(goomInfo->gRandom,200)?0:100+goom_irand(goomInfo->gRandom,60); + fx_data->lock = fx_data->happens * 3 / 2; } - else lock --; -// happens = 1; - - tmp = happens?8.0f:0; - *dist2 = distt2 = (tmp + 15.0f*distt2)/16.0f; + else fx_data->lock --; + + tmp = fx_data->happens?8.0f:0; + *dist2 = fx_data->distt2 = (tmp + 15.0f*fx_data->distt2)/16.0f; tmp = 30+D-90.0f*(1.0f+sin(cycle*19/20)); - if (happens) + if (fx_data->happens) tmp *= 0.6f; - *dist = distt = (tmp + 3.0f*distt)/4.0f; + *dist = fx_data->distt = (tmp + 3.0f*fx_data->distt)/4.0f; - if (!happens){ + if (!fx_data->happens){ tmp = M_PI*sin(cycle)/32+3*M_PI/2; } else { - rotation = iRAND(500)?rotation:iRAND(2); - if (rotation) + fx_data->rotation = goom_irand(goomInfo->gRandom,500)?fx_data->rotation:goom_irand(goomInfo->gRandom,2); + if (fx_data->rotation) cycle *= 2.0f*M_PI; else cycle *= -1.0f*M_PI; tmp = cycle - (M_PI*2.0) * floor(cycle/(M_PI*2.0)); } - - if (abs(tmp-rot) > abs(tmp-(rot+2.0*M_PI))) { - rot = (tmp + 15.0f*(rot+2*M_PI)) / 16.0f; - if (rot>2.0*M_PI) - rot -= 2.0*M_PI; - *rotangle = rot; + + if (abs(tmp-fx_data->rot) > abs(tmp-(fx_data->rot+2.0*M_PI))) { + fx_data->rot = (tmp + 15.0f*(fx_data->rot+2*M_PI)) / 16.0f; + if (fx_data->rot>2.0*M_PI) + fx_data->rot -= 2.0*M_PI; + *rotangle = fx_data->rot; } - else if (abs(tmp-rot) > abs(tmp-(rot-2.0*M_PI))) { - rot = (tmp + 15.0f*(rot-2.0*M_PI)) / 16.0f; - if (rot<0.0f) - rot += 2.0*M_PI; - *rotangle = rot; + else if (abs(tmp-fx_data->rot) > abs(tmp-(fx_data->rot-2.0*M_PI))) { + fx_data->rot = (tmp + 15.0f*(fx_data->rot-2.0*M_PI)) / 16.0f; + if (fx_data->rot<0.0f) + fx_data->rot += 2.0*M_PI; + *rotangle = fx_data->rot; } else - *rotangle = rot = (tmp + 15.0f*rot) / 16.0f; + *rotangle = fx_data->rot = (tmp + 15.0f*fx_data->rot) / 16.0f; } -void tentacle_update(int *buf, int *back, int W, int H, - short data[2][512], float rapport, - int drawit) { +void tentacle_update(PluginInfo *goomInfo, Pixel *buf, Pixel *back, int W, int H, + short data[2][512], float rapport, int drawit, TentacleFXData *fx_data) { + int tmp; int tmp2; - - static int colors[] = { - (0x18<<(ROUGE*8))|(0x4c<<(VERT*8))|(0x2f<<(BLEU*8)), - (0x48<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x6f<<(BLEU*8)), - (0x58<<(ROUGE*8))|(0x3c<<(VERT*8))|(0x0f<<(BLEU*8))}; - - static int col = (0x28<<(ROUGE*8))|(0x2c<<(VERT*8))|(0x5f<<(BLEU*8)); - static int dstcol = 0; - static float lig = 1.15f; - static float ligs = 0.1f; int color; int colorlow; float dist,dist2,rotangle; - if ((!drawit) && (ligs>0.0f)) - ligs = -ligs; + if ((!drawit) && (fx_data->ligs>0.0f)) + fx_data->ligs = -fx_data->ligs; + + fx_data->lig += fx_data->ligs; - lig += ligs; + if (fx_data->lig > 1.01f) { + if ((fx_data->lig>10.0f) | (fx_data->lig<1.1f)) fx_data->ligs = -fx_data->ligs; - if (lig > 1.01f) { - if ((lig>10.0f) | (lig<1.1f)) ligs = -ligs; - - if ((lig<6.3f)&&(iRAND(30)==0)) - dstcol=iRAND(3); + if ((fx_data->lig<6.3f)&&(goom_irand(goomInfo->gRandom,30)==0)) + fx_data->dstcol=goom_irand(goomInfo->gRandom,NB_TENTACLE_COLORS); - col = evolutecolor(col,colors[dstcol],0xff,0x01); - col = evolutecolor(col,colors[dstcol],0xff00,0x0100); - col = evolutecolor(col,colors[dstcol],0xff0000,0x010000); - col = evolutecolor(col,colors[dstcol],0xff000000,0x01000000); - - color = col; - colorlow = col; - - lightencolor(&color,lig * 2.0f + 2.0f); - lightencolor(&colorlow,(lig/3.0f)+0.67f); + fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff,0x01); + fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff00,0x0100); + fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff0000,0x010000); + fx_data->col = evolutecolor(fx_data->col,fx_data->colors[fx_data->dstcol],0xff000000,0x01000000); + + color = fx_data->col; + colorlow = fx_data->col; + + lightencolor(&color,fx_data->lig * 2.0f + 2.0f); + lightencolor(&colorlow,(fx_data->lig/3.0f)+0.67f); rapport = 1.0f + 2.0f * (rapport - 1.0f); - rapport *= 1.2f; + rapport *= 1.2f; if (rapport > 1.12f) rapport = 1.12f; - - pretty_move (cycle,&dist,&dist2,&rotangle); + + pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data); for (tmp=0;tmpgRandom,511)],10)) * rapport; + fx_data->vals[tmp2] = val; } - - grid3d_update (grille[tmp],rotangle, vals, dist2); + + grid3d_update (fx_data->grille[tmp], rotangle, fx_data->vals, dist2); } - cycle+=0.01f; + fx_data->cycle+=0.01f; for (tmp=0;tmpgrille[tmp],color,colorlow,dist,buf,back,W,H); } else { - lig = 1.05f; - if (ligs < 0.0f) - ligs = -ligs; - pretty_move (cycle,&dist,&dist2,&rotangle); - cycle+=0.1f; - if (cycle > 1000) - cycle = 0; + fx_data->lig = 1.05f; + if (fx_data->ligs < 0.0f) + fx_data->ligs = -fx_data->ligs; + pretty_move (goomInfo, fx_data->cycle, &dist, &dist2, &rotangle, fx_data); + fx_data->cycle+=0.1f; + if (fx_data->cycle > 1000) + fx_data->cycle = 0; } } diff --git a/src/post/goom/tentacle3d.h b/src/post/goom/tentacle3d.h index e79cbc1d4..adc5f7721 100755 --- a/src/post/goom/tentacle3d.h +++ b/src/post/goom/tentacle3d.h @@ -1,9 +1,8 @@ #ifndef _TENTACLE3D_H #define _TENTACLE3D_H -void tentacle_new (void); -void tentacle_update(int *buf, int *back, int W, int H, - short[2][512], float, int drawit); -void tentacle_free (void); +#include "goom_visual_fx.h" + +VisualFX tentacle_fx_create(); #endif diff --git a/src/post/goom/v3d.c b/src/post/goom/v3d.c new file mode 100644 index 000000000..1614e8afd --- /dev/null +++ b/src/post/goom/v3d.c @@ -0,0 +1,15 @@ +#include "v3d.h" + +void v3d_to_v2d(v3d *v3, int nbvertex, int width, int height, float distance, v2d *v2) { + int i; + for (i=0;i 2) { + int Xp, Yp; + F2I((distance * v3[i].x / v3[i].z),Xp); + F2I((distance * v3[i].y / v3[i].z),Yp); + v2[i].x = Xp + (width>>1); + v2[i].y = -Yp + (height>>1); + } + else v2[i].x=v2[i].y=-666; + } +} diff --git a/src/post/goom/v3d.h b/src/post/goom/v3d.h index dcf74fd65..7690847f2 100755 --- a/src/post/goom/v3d.h +++ b/src/post/goom/v3d.h @@ -8,13 +8,17 @@ #include "mathtools.h" typedef struct { - float x,y,z; + float x,y,z; } v3d; typedef struct { - int x,y; + int x,y; } v2d; +typedef struct { + double x,y; +} v2g; + /* * projete le vertex 3D sur le plan d'affichage * retourne (0,0) si le point ne doit pas etre affiche. @@ -23,7 +27,7 @@ typedef struct { */ #define V3D_TO_V2D(v3,v2,width,height,distance) \ { \ - int Xp, Yp; \ + int Xp, Yp; \ if (v3.z > 2) { \ F2I((distance * v3.x / v3.z),Xp) ; \ F2I((distance * v3.y / v3.z),Yp) ; \ @@ -33,6 +37,8 @@ typedef struct { else v2.x=v2.y=-666; \ } +void v3d_to_v2d(v3d *src, int nbvertex, int width, int height, float distance, v2d *v2_array); + /* * rotation selon Y du v3d vi d'angle a (cosa=cos(a), sina=sin(a)) * centerz = centre de rotation en z diff --git a/src/post/goom/xine_goom.c b/src/post/goom/xine_goom.c index 45f90925d..ae39e005a 100644 --- a/src/post/goom/xine_goom.c +++ b/src/post/goom/xine_goom.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_goom.c,v 1.53 2004/05/29 14:45:26 mroi Exp $ + * $Id: xine_goom.c,v 1.54 2004/06/27 11:58:47 mroi Exp $ * * GOOM post plugin. * @@ -39,8 +39,7 @@ #include "xineutils.h" #include "post.h" -#include "goom_config.h" -#include "goom_core.h" +#include "goom.h" #define NUMSAMPLES 512 #define FPS 10 @@ -78,6 +77,9 @@ struct post_plugin_goom_s { /* private metronom for syncing the video */ metronom_t *metronom; + /* goom context */ + PluginInfo *goom; + int data_idx; gint16 data [2][512]; audio_buffer_t buf; /* dummy buffer just to hold a copy of audio data */ @@ -269,7 +271,7 @@ static post_plugin_t *goom_open_plugin(post_class_t *class_gen, int inputs, this->width_back = this->width; this->height_back = this->height; - goom_init (this->width_back, this->height_back, 0); + this->goom = goom_init (this->width_back, this->height_back); this->ratio = (double)this->width_back/(double)this->height_back; @@ -320,7 +322,7 @@ static void goom_dispose(post_plugin_t *this_gen) if (_x_post_dispose(this_gen)) { this->class->ip = NULL; - goom_close(); + goom_close(this->goom); this->metronom->exit(this->metronom); @@ -470,7 +472,7 @@ static void goom_port_put_buffer (xine_audio_port_t *port_gen, if (!this->skip_frame) { /* Try to be fast */ - goom_frame = (uint8_t *)goom_update (this->data, 0, 0, NULL, NULL); + goom_frame = (uint8_t *)goom_update (this->goom, this->data, 0, 0, NULL, NULL); dest_ptr = frame -> base[0]; goom_frame_end = goom_frame + 4 * (this->width_back * this->height_back); @@ -540,8 +542,8 @@ static void goom_port_put_buffer (xine_audio_port_t *port_gen, width = this->width; height = this->height; if ((width != this->width_back) || (height != this->height_back)) { - goom_close(); - goom_init (this->width, this->height, 0); + goom_close(this->goom); + this->goom = goom_init (this->width, this->height); this->width_back = width; this->height_back = height; this->ratio = (double)width/(double)height; diff --git a/src/post/goom/xmmx.c b/src/post/goom/xmmx.c new file mode 100644 index 000000000..87589e863 --- /dev/null +++ b/src/post/goom/xmmx.c @@ -0,0 +1,395 @@ +/* a definir pour avoir exactement le meme resultat que la fonction C + * (un chouillat plus lent) + */ +#define STRICT_COMPAT + +//#define HAVE_ATHLON + +#define BUFFPOINTNB 16 +#define BUFFPOINTMASK 0xffff +#define BUFFINCR 0xff + +#define sqrtperte 16 +/* faire : a % sqrtperte <=> a & pertemask*/ +#define PERTEMASK 0xf +/* faire : a / sqrtperte <=> a >> PERTEDEC*/ +#define PERTEDEC 4 + + +/*#define MMX_TRACE*/ +#include "mmx.h" +/*#include "xmmx.h"*/ +#include "goom_graphic.h" + +int xmmx_supported () { + return (mm_support()&0x8)>>3; +} + +void zoom_filter_xmmx (int prevX, int prevY, + unsigned int *expix1, unsigned int *expix2, + int *lbruS, int *lbruD, int buffratio, + int precalCoef[16][16]) +{ + int bufsize = prevX * prevY; /* taille du buffer */ + volatile int loop; /* variable de boucle */ + + mmx_t *brutS = (mmx_t*)lbruS; /* buffer de transformation source */ + mmx_t *brutD = (mmx_t*)lbruD; /* buffer de transformation dest */ + + volatile mmx_t prevXY; + volatile mmx_t ratiox; + /* volatile mmx_t interpix; */ + + expix1[0]=expix1[prevX-1]=expix1[prevX*prevY-1]=expix1[prevX*prevY-prevX]=0; + + prevXY.ud[0] = (prevX-1)<>16 format [X|Y] + * modified = mm0,mm1,mm2 + */ + + __asm__ __volatile__ ( + "movq %0,%%mm0\n" + "movq %1,%%mm1\n" + : :"X"(brutS[loop]),"X"(brutD[loop]) + ); /* mm0 = S */ + + psubd_r2r (mm0,mm1); /* mm1 = D - S */ + movq_r2r (mm1, mm2); /* mm2 = D - S */ + + pslld_i2r (16,mm1); + mmx_r2r (pmulhuw, mm6, mm1); /* mm1 = ?? */ + pmullw_r2r (mm6, mm2); + + paddd_r2r (mm2, mm1); /* mm1 = (D - S) * buffratio >> 16 */ + pslld_i2r (16,mm0); + + paddd_r2r (mm1, mm0); /* mm0 = S + mm1 */ + psrld_i2r (16, mm0); + + /* + * pre : mm0 : position vector on screen + * prevXY : coordinate of the lower-right point on screen + * post : clipped mm0 + * modified : mm0,mm1,mm2 + */ + movq_m2r (prevXY,mm1); + pcmpgtd_r2r (mm0, mm1); /* mm0 en X contient : + 1111 si prevXY > px + 0000 si prevXY <= px + (idem pour y) */ +#ifdef STRICT_COMPAT + movq_r2r (mm1,mm2); + punpckhdq_r2r (mm2,mm2); + punpckldq_r2r (mm1,mm1); + pand_r2r (mm2, mm0); +#endif + pand_r2r (mm1, mm0); /* on met a zero la partie qui deborde */ + + /* + * pre : mm0 : clipped position on screen + * + * post : mm3 & mm4 : coefs for this position + * mm1 : X vector [0|X] + * + * modif : eax,ebx + */ + __asm__ __volatile__ ( + "movd %%mm0,%%ebx\n" + "movq %%mm0,%%mm1\n" + + "andl $15,%%ebx\n" + "psrlq $32,%%mm1\n" + + "shll $6,%%ebx\n" + "movd %%mm1,%%eax\n" + + "addl %0,%%ebx\n" + "andl $15,%%eax\n" + + "movd (%%ebx,%%eax,4),%%mm3\n" + ::"X"(precalCoef):"eax","ebx"); + + /* + * extraction des coefficients... + * + * pre : coef dans mm3 + * + * post : coef extraits dans mm3 (c1 & c2) + * et mm4 (c3 & c4) + * + * modif : mm5 + */ + + /* entrelace avec portion d'apres (cf les '^') + movq_r2r (mm3, mm5); / * ??-??-??-??-c4-c3-c2-c1 * / + punpcklbw_r2r (mm5, mm3); / * c4-c4-c3-c3-c2-c2-c1-c1 * / + movq_r2r (mm3, mm4); / * c4-c4-c3-c3-c2-c2-c1-c1 * / + movq_r2r (mm3, mm5); / * c4-c4-c3-c3-c2-c2-c1-c1 * / + + punpcklbw_r2r (mm5, mm3); / * c2-c2-c2-c2-c1-c1-c1-c1 * / + punpckhbw_r2r (mm5, mm4); / * c4-c4-c4-c4-c3-c3-c3-c3 * / + */ + + /* + * pre : mm0 : Y pos [*|Y] + * mm1 : X pos [*|X] + * + * post : mm0 : expix1[position] + * mm2 : expix1[position+largeur] + * + * modif : eax,ebx + */ + psrld_i2r (PERTEDEC,mm0); + psrld_i2r (PERTEDEC,mm1); + __asm__ __volatile__ ( + "movd %%mm1,%%eax\n" + /*^*/ "movq %%mm3,%%mm5\n" /*^*/ + + "mull %1\n" + "movd %%mm0,%%ebx\n" + /*^*/ "punpcklbw %%mm5, %%mm3\n" /*^*/ + + "addl %%ebx,%%eax\n" + /*^*/ "movq %%mm3,%%mm4\n" /*^*/ + /*^*/ "movq %%mm3,%%mm5\n" /*^*/ + + "movl %0,%%ebx\n" + /*^*/ "punpcklbw %%mm5,%%mm3\n" /*^*/ + + "movq (%%ebx,%%eax,4),%%mm0\n" + /*^*/ "punpckhbw %%mm5,%%mm4\n" /*^*/ + + "addl %1,%%eax\n" + "movq (%%ebx,%%eax,4),%%mm2\n" + + : : "X"(expix1), "X"(prevX):"eax","ebx" + ); + + /* + * pre : mm0 : expix1[position] + * mm2 : expix1[position+largeur] + * mm3 & mm4 : coefs + */ + + /* recopie des deux premiers pixels dans mm0 et mm1 */ + movq_r2r (mm0, mm1); /* b1-v1-r1-a1-b2-v2-r2-a2 */ + + /* depackage du premier pixel */ + punpcklbw_r2r (mm7, mm0); /* 00-b2-00-v2-00-r2-00-a2 */ + + /* extraction des coefficients... */ + + movq_r2r (mm3, mm5); /* c2-c2-c2-c2-c1-c1-c1-c1 */ + + /*^en parrallele^*/ /* depackage du 2ieme pixel */ + /*^*/ punpckhbw_r2r (mm7, mm1); /* 00-b1-00-v1-00-r1-00-a1 */ + + punpcklbw_r2r (mm7, mm5); /* 00-c1-00-c1-00-c1-00-c1 */ + punpckhbw_r2r (mm7, mm3); /* 00-c2-00-c2-00-c2-00-c2 */ + + /* multiplication des pixels par les coefficients */ + pmullw_r2r (mm5, mm0); /* c1*b2-c1*v2-c1*r2-c1*a2 */ + pmullw_r2r (mm3, mm1); /* c2*b1-c2*v1-c2*r1-c2*a1 */ + paddw_r2r (mm1, mm0); + + /* ...extraction des 2 derniers coefficients */ + movq_r2r (mm4, mm5); /* c4-c4-c4-c4-c3-c3-c3-c3 */ + punpcklbw_r2r (mm7, mm4); /* 00-c3-00-c3-00-c3-00-c3 */ + punpckhbw_r2r (mm7, mm5); /* 00-c4-00-c4-00-c4-00-c4 */ + + /* recuperation des 2 derniers pixels */ + movq_r2r (mm2, mm1); + + /* depackage des pixels */ + punpcklbw_r2r (mm7, mm1); + punpckhbw_r2r (mm7, mm2); + + /* multiplication pas les coeffs */ + pmullw_r2r (mm4, mm1); + pmullw_r2r (mm5, mm2); + + /* ajout des valeurs obtenues à la valeur finale */ + paddw_r2r (mm1, mm0); + paddw_r2r (mm2, mm0); + + /* division par 256 = 16+16+16+16, puis repackage du pixel final */ + psrlw_i2r (8, mm0); + packuswb_r2r (mm7, mm0); + + movd_r2m (mm0,expix2[loop]); + + ++loop; + } +/*#ifdef HAVE_ATHLON*/ + __asm__ __volatile__ ("femms\n"); +/*#else + emms(); +#endif*/ +} + +#define DRAWMETHOD_PLUS_XMMX(_out,_backbuf,_col) \ +{ \ + movd_m2r(_backbuf, mm0); \ + paddusb_m2r(_col, mm0); \ + movd_r2m(mm0, _out); \ +} + +#define DRAWMETHOD DRAWMETHOD_PLUS_XMMX(*p,*p,col) + +void draw_line_xmmx (Pixel *data, int x1, int y1, int x2, int y2, int col, int screenx, int screeny) +{ + int x, y, dx, dy, yy, xx; + Pixel *p; + + if ((y1 < 0) || (y2 < 0) || (x1 < 0) || (x2 < 0) || (y1 >= screeny) || (y2 >= screeny) || (x1 >= screenx) || (x2 >= screenx)) + goto end_of_line; + + dx = x2 - x1; + dy = y2 - y1; + if (x1 >= x2) { + int tmp; + + tmp = x1; + x1 = x2; + x2 = tmp; + tmp = y1; + y1 = y2; + y2 = tmp; + dx = x2 - x1; + dy = y2 - y1; + } + + /* vertical line */ + if (dx == 0) { + if (y1 < y2) { + p = &(data[(screenx * y1) + x1]); + for (y = y1; y <= y2; y++) { + DRAWMETHOD; + p += screenx; + } + } + else { + p = &(data[(screenx * y2) + x1]); + for (y = y2; y <= y1; y++) { + DRAWMETHOD; + p += screenx; + } + } + goto end_of_line; + } + /* horizontal line */ + if (dy == 0) { + if (x1 < x2) { + p = &(data[(screenx * y1) + x1]); + for (x = x1; x <= x2; x++) { + DRAWMETHOD; + p++; + } + goto end_of_line; + } + else { + p = &(data[(screenx * y1) + x2]); + for (x = x2; x <= x1; x++) { + DRAWMETHOD; + p++; + } + goto end_of_line; + } + } + /* 1 */ + /* \ */ + /* \ */ + /* 2 */ + if (y2 > y1) { + /* steep */ + if (dy > dx) { + dx = ((dx << 16) / dy); + x = x1 << 16; + for (y = y1; y <= y2; y++) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p++; + /* DRAWMETHOD; */ + } + x += dx; + } + goto end_of_line; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + } + } + /* 2 */ + /* / */ + /* / */ + /* 1 */ + else { + /* steep */ + if (-dy > dx) { + dx = ((dx << 16) / -dy); + x = (x1 + 1) << 16; + for (y = y1; y >= y2; y--) { + xx = x >> 16; + p = &(data[(screenx * y) + xx]); + DRAWMETHOD; + if (xx < (screenx - 1)) { + p--; + /* DRAWMETHOD; */ + } + x += dx; + } + goto end_of_line; + } + /* shallow */ + else { + dy = ((dy << 16) / dx); + y = y1 << 16; + for (x = x1; x <= x2; x++) { + yy = y >> 16; + p = &(data[(screenx * yy) + x]); + DRAWMETHOD; + if (yy < (screeny - 1)) { + p += screeny; + /* DRAWMETHOD; */ + } + y += dy; + } + goto end_of_line; + } + } +end_of_line: + __asm__ __volatile__ ("femms\n"); +} + diff --git a/src/post/goom/xmmx.h b/src/post/goom/xmmx.h deleted file mode 100755 index 0e8d5a714..000000000 --- a/src/post/goom/xmmx.h +++ /dev/null @@ -1,354 +0,0 @@ -/* xmmx.h - - eXtended MultiMedia eXtensions GCC interface library for IA32. - - To use this library, simply include this header file - and compile with GCC. You MUST have inlining enabled - in order for xmmx_ok() to work; this can be done by - simply using -O on the GCC command line. - - Compiling with -DXMMX_TRACE will cause detailed trace - output to be sent to stderr for each mmx operation. - This adds lots of code, and obviously slows execution to - a crawl, but can be very useful for debugging. - - THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY - EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT - LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY - AND FITNESS FOR ANY PARTICULAR PURPOSE. - - 1999 by R. Fisher - Based on libmmx, 1997-99 by H. Dietz and R. Fisher - - Notes: - It appears that the latest gas has the pand problem fixed, therefore - I'll undefine BROKEN_PAND by default. -*/ - -#ifndef _XMMX_H -#define _XMMX_H - -/* Warning: at this writing, the version of GAS packaged - with most Linux distributions does not handle the - parallel AND operation mnemonic correctly. If the - symbol BROKEN_PAND is defined, a slower alternative - coding will be used. If execution of mmxtest results - in an illegal instruction fault, define this symbol. -*/ -#undef BROKEN_PAND - - -/* The type of an value that fits in an (Extended) MMX register - (note that long long constant values MUST be suffixed - by LL and unsigned long long values by ULL, lest - they be truncated by the compiler) -*/ -#ifndef _MMX_H -typedef union { - long long q; /* Quadword (64-bit) value */ - unsigned long long uq; /* Unsigned Quadword */ - int d[2]; /* 2 Doubleword (32-bit) values */ - unsigned int ud[2]; /* 2 Unsigned Doubleword */ - short w[4]; /* 4 Word (16-bit) values */ - unsigned short uw[4]; /* 4 Unsigned Word */ - char b[8]; /* 8 Byte (8-bit) values */ - unsigned char ub[8]; /* 8 Unsigned Byte */ - float s[2]; /* Single-precision (32-bit) value */ -} __attribute__ ((aligned (8))) mmx_t; /* On an 8-byte (64-bit) boundary */ -#endif - -/* Helper functions for the instruction macros that follow... - (note that memory-to-register, m2r, instructions are nearly - as efficient as register-to-register, r2r, instructions; - however, memory-to-memory instructions are really simulated - as a convenience, and are only 1/3 as efficient) -*/ -#ifdef XMMX_TRACE - -/* Include the stuff for printing a trace to stderr... -*/ - -#include - -#define mmx_i2r(op, imm, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace.uq = (imm); \ - fprintf(stderr, #op "_i2r(" #imm "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2r(op, mem, reg) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mem); \ - fprintf(stderr, #op "_m2r(" #mem "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #reg "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (mem)); \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #reg "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2m(op, reg, mem) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #reg ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #op "_r2m(" #reg "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (mem); \ - fprintf(stderr, #mem "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ - : /* nothing */ ); \ - mmx_trace = (mem); \ - fprintf(stderr, #mem "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_r2r(op, regs, regd) \ - { \ - mmx_t mmx_trace; \ - __asm__ __volatile__ ("movq %%" #regs ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #op "_r2r(" #regs "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #regd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd); \ - __asm__ __volatile__ ("movq %%" #regd ", %0" \ - : "=X" (mmx_trace) \ - : /* nothing */ ); \ - fprintf(stderr, #regd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#define mmx_m2m(op, mems, memd) \ - { \ - mmx_t mmx_trace; \ - mmx_trace = (mems); \ - fprintf(stderr, #op "_m2m(" #mems "=0x%08x%08x, ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - mmx_trace = (memd); \ - fprintf(stderr, #memd "=0x%08x%08x) => ", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)); \ - mmx_trace = (memd); \ - fprintf(stderr, #memd "=0x%08x%08x\n", \ - mmx_trace.d[1], mmx_trace.d[0]); \ - } - -#else - -/* These macros are a lot simpler without the tracing... -*/ - -#define mmx_i2r(op, imm, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (imm) ) - -#define mmx_m2r(op, mem, reg) \ - __asm__ __volatile__ (#op " %0, %%" #reg \ - : /* nothing */ \ - : "X" (mem)) - -#define mmx_m2ir(op, mem, rs) \ - __asm__ __volatile__ (#op " %0, %%" #rs \ - : /* nothing */ \ - : "X" (mem) ) - -#define mmx_r2m(op, reg, mem) \ - __asm__ __volatile__ (#op " %%" #reg ", %0" \ - : "=X" (mem) \ - : /* nothing */ ) - -#define mmx_r2r(op, regs, regd) \ - __asm__ __volatile__ (#op " %" #regs ", %" #regd) - -#define mmx_r2ir(op, rs1, rs2) \ - __asm__ __volatile__ (#op " %%" #rs1 ", %%" #rs2 \ - : /* nothing */ \ - : /* nothing */ ) - -#define mmx_m2m(op, mems, memd) \ - __asm__ __volatile__ ("movq %0, %%mm0\n\t" \ - #op " %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (memd) \ - : "X" (mems)) - -#endif - - - -/* 1x64 MOVe Quadword - (this is both a load and a store... - in fact, it is the only way to store) -*/ -#define movq_m2r(var, reg) mmx_m2r(movq, var, reg) -#define movq_r2m(reg, var) mmx_r2m(movq, reg, var) -#define movq_r2r(regs, regd) mmx_r2r(movq, regs, regd) -#define movq(vars, vard) \ - __asm__ __volatile__ ("movq %1, %%mm0\n\t" \ - "movq %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - -/* 1x32 MOVe Doubleword - (like movq, this is both load and store... - but is most useful for moving things between - mmx registers and ordinary registers) -*/ -#define movd_m2r(var, reg) mmx_m2r(movd, var, reg) -#define movd_r2m(reg, var) mmx_r2m(movd, reg, var) -#define movd_r2r(regs, regd) mmx_r2r(movd, regs, regd) -#define movd(vars, vard) \ - __asm__ __volatile__ ("movd %1, %%mm0\n\t" \ - "movd %%mm0, %0" \ - : "=X" (vard) \ - : "X" (vars)) - - - -/* 4x16 Parallel MAGnitude -*/ -#define pmagw_m2r(var, reg) mmx_m2r(pmagw, var, reg) -#define pmagw_r2r(regs, regd) mmx_r2r(pmagw, regs, regd) -#define pmagw(vars, vard) mmx_m2m(pmagw, vars, vard) - - -/* 4x16 Parallel ADDs using Saturation arithmetic - and Implied destination -*/ -#define paddsiw_m2ir(var, rs) mmx_m2ir(paddsiw, var, rs) -#define paddsiw_r2ir(rs1, rs2) mmx_r2ir(paddsiw, rs1, rs2) -#define paddsiw(vars, vard) mmx_m2m(paddsiw, vars, vard) - - -/* 4x16 Parallel SUBs using Saturation arithmetic - and Implied destination -*/ -#define psubsiw_m2ir(var, rs) mmx_m2ir(psubsiw, var, rs) -#define psubsiw_r2ir(rs1, rs2) mmx_r2ir(psubsiw, rs1, rs2) -#define psubsiw(vars, vard) mmx_m2m(psubsiw, vars, vard) - - -/* 4x16 Parallel MULs giving High 4x16 portions of results - Rounded with 1/2 bit 15. -*/ -#define pmulhrw_m2r(var, reg) mmx_m2r(pmulhrw, var, reg) -#define pmulhrw_r2r(regs, regd) mmx_r2r(pmulhrw, regs, regd) -#define pmulhrw(vars, vard) mmx_m2m(pmulhrw, vars, vard) - - -/* 4x16 Parallel MULs giving High 4x16 portions of results - Rounded with 1/2 bit 15, storing to Implied register -*/ -#define pmulhriw_m2ir(var, rs) mmx_m2ir(pmulhriw, var, rs) -#define pmulhriw_r2ir(rs1, rs2) mmx_r2ir(pmulhriw, rs1, rs2) -#define pmulhriw(vars, vard) mmx_m2m(pmulhriw, vars, vard) - - -/* 4x16 Parallel Muls (and ACcumulate) giving High 4x16 portions - of results Rounded with 1/2 bit 15, accumulating with Implied register -*/ -#define pmachriw_m2ir(var, rs) mmx_m2ir(pmachriw, var, rs) -#define pmachriw_r2ir(rs1, rs2) mmx_r2ir(pmachriw, rs1, rs2) -#define pmachriw(vars, vard) mmx_m2m(pmachriw, vars, vard) - - -/* 8x8u Parallel AVErage -*/ -#define paveb_m2r(var, reg) mmx_m2r(paveb, var, reg) -#define paveb_r2r(regs, regd) mmx_r2r(paveb, regs, regd) -#define paveb(vars, vard) mmx_m2m(paveb, vars, vard) - - -/* 8x8u Parallel DISTance and accumulate with - unsigned saturation to Implied register -*/ -#define pdistib_m2ir(var, rs) mmx_m2ir(pdistib, var, rs) -#define pdistib(vars, vard) mmx_m2m(pdistib, vars, vard) - - -/* 8x8 Parallel conditional MoVe - if implied register field is Zero -*/ -#define pmvzb_m2ir(var, rs) mmx_m2ir(pmvzb, var, rs) - - -/* 8x8 Parallel conditional MoVe - if implied register field is Not Zero -*/ -#define pmvnzb_m2ir(var, rs) mmx_m2ir(pmvnzb, var, rs) - - -/* 8x8 Parallel conditional MoVe - if implied register field is Less than Zero -*/ -#define pmvlzb_m2ir(var, rs) mmx_m2ir(pmvlzb, var, rs) - - -/* 8x8 Parallel conditional MoVe - if implied register field is Greater than or Equal to Zero -*/ -#define pmvgezb_m2ir(var, rs) mmx_m2ir(pmvgezb, var, rs) - - -/* Fast Empty MMx State - (used to clean-up when going from mmx to float use - of the registers that are shared by both; note that - there is no float-to-xmmx operation needed, because - only the float tag word info is corruptible) -*/ -#ifdef XMMX_TRACE - -#define femms() \ - { \ - fprintf(stderr, "femms()\n"); \ - __asm__ __volatile__ ("femms"); \ - } - -#else - -#define femms() __asm__ __volatile__ ("femms") - -#endif - -#endif - diff --git a/src/post/goom/zoom_filter_mmx.c b/src/post/goom/zoom_filter_mmx.c deleted file mode 100644 index cb0f6d829..000000000 --- a/src/post/goom/zoom_filter_mmx.c +++ /dev/null @@ -1,114 +0,0 @@ -#include "goom_config.h" -#include "xineutils.h" -#include "zoom_filter_mmx.h" - -#ifdef HAVE_MMX -#define BUFFPOINTNB 16 -#define BUFFPOINTMASK 0xffff -#define BUFFINCR 0xff - -#define sqrtperte 16 -/* faire : a % sqrtperte <=> a & pertemask */ -#define PERTEMASK 0xf -/* faire : a / sqrtperte <=> a >> PERTEDEC */ -#define PERTEDEC 4 - -int zoom_filter_mmx_supported (void) { - return (xine_mm_accel() & MM_ACCEL_X86_MMX); -} - -void zoom_filter_mmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, - int *brutS, int *brutD, int buffratio, - int precalCoef[16][16]) -{ - unsigned int ax = (prevX-1)<> BUFFPOINTNB); - brutSmypos = brutS[myPos2]; - py = brutSmypos + (((brutD[myPos2] - brutSmypos)*buffratio) >> BUFFPOINTNB); - - if ((py>=ay) || (px>=ax)) { - pos=coeffs=0; - } - else { - pos = ((px >> PERTEDEC) + prevX * (py >> PERTEDEC)); - /* coef en modulo 15 */ - coeffs = precalCoef [px & PERTEMASK][py & PERTEMASK]; - } - - movd_m2r(coeffs, mm6); - ;/* recuperation des deux premiers pixels dans mm0 et mm1 */ - movq_m2r(expix1[pos], mm0); /* b1-v1-r1-a1-b2-v2-r2-a2 */ - movq_r2r(mm0, mm1); /* b1-v1-r1-a1-b2-v2-r2-a2 */ - - ;/* depackage du premier pixel */ - punpcklbw_r2r(mm7, mm0); /* 00-b2-00-v2-00-r2-00-a2 */ - - movq_r2r(mm6, mm5); /* xx-xx-xx-xx-c4-c3-c2-c1 */ - ;/* depackage du 2ieme pixel */ - punpckhbw_r2r(mm7, mm1); /* 00-b1-00-v1-00-r1-00-a1 */ - - ;/* extraction des coefficients... */ - punpcklbw_r2r(mm5, mm6); /* c4-c4-c3-c3-c2-c2-c1-c1 */ - movq_r2r(mm6, mm4); /* c4-c4-c3-c3-c2-c2-c1-c1 */ - movq_r2r(mm6, mm5); /* c4-c4-c3-c3-c2-c2-c1-c1 */ - - punpcklbw_r2r(mm5, mm6); /* c2-c2-c2-c2-c1-c1-c1-c1 */ - punpckhbw_r2r(mm5, mm4); /* c4-c4-c4-c4-c3-c3-c3-c3 */ - - movq_r2r(mm6, mm3); /* c2-c2-c2-c2-c1-c1-c1-c1 */ - punpcklbw_r2r(mm7, mm6); /* 00-c1-00-c1-00-c1-00-c1 */ - punpckhbw_r2r(mm7, mm3); /* 00-c2-00-c2-00-c2-00-c2 */ - - ;/* multiplication des pixels par les coefficients */ - pmullw_r2r(mm6, mm0); /* c1*b2-c1*v2-c1*r2-c1*a2 */ - pmullw_r2r(mm3, mm1); /* c2*b1-c2*v1-c2*r1-c2*a1 */ - paddw_r2r(mm1, mm0); - - ;/* ...extraction des 2 derniers coefficients */ - movq_r2r(mm4, mm5); /* c4-c4-c4-c4-c3-c3-c3-c3 */ - punpcklbw_r2r(mm7, mm4); /* 00-c3-00-c3-00-c3-00-c3 */ - punpckhbw_r2r(mm7, mm5); /* 00-c4-00-c4-00-c4-00-c4 */ - - /* ajouter la longueur de ligne a esi */ - ;/* recuperation des 2 derniers pixels */ - movq_m2r(expix1[pos+prevX], mm1); - movq_r2r(mm1, mm2); - - ;/* depackage des pixels */ - punpcklbw_r2r(mm7, mm1); - punpckhbw_r2r(mm7, mm2); - - ;/* multiplication pas les coeffs */ - pmullw_r2r(mm4, mm1); - pmullw_r2r(mm5, mm2); - - ;/* ajout des valeurs obtenues à la valeur finale */ - paddw_r2r(mm1, mm0); - paddw_r2r(mm2, mm0); - - ;/* division par 256 = 16+16+16+16, puis repackage du pixel final */ - psrlw_i2r(8, mm0); - packuswb_r2r(mm7, mm0); - movd_r2m(mm0,expix2[loop]); - - } - emms(); -} -#endif diff --git a/src/post/goom/zoom_filter_mmx.h b/src/post/goom/zoom_filter_mmx.h deleted file mode 100644 index f81f2dca7..000000000 --- a/src/post/goom/zoom_filter_mmx.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef ZOOM_FILTER_MMX_H -#define ZOOM_FILTER_MMX_H - -void zoom_filter_mmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, - int *brutS, int *brutD, int buffratio, - int precalCoef[16][16]); - -#endif diff --git a/src/post/goom/zoom_filter_xmmx.c b/src/post/goom/zoom_filter_xmmx.c deleted file mode 100755 index ea1218cc7..000000000 --- a/src/post/goom/zoom_filter_xmmx.c +++ /dev/null @@ -1,243 +0,0 @@ -#include "goom_config.h" -#include "xineutils.h" - -/* a definir pour avoir exactement le meme resultat que la fonction C - * (un chouillat plus lent) - */ -#define STRICT_COMPAT -//#define HAVE_ATHLON - -#define BUFFPOINTNB 16 -#define BUFFPOINTMASK 0xffff -#define BUFFINCR 0xff - -#define sqrtperte 16 -// faire : a % sqrtperte <=> a & pertemask -#define PERTEMASK 0xf -// faire : a / sqrtperte <=> a >> PERTEDEC -#define PERTEDEC 4 - - -//#define MMX_TRACE - -int zoom_filter_xmmx_supported (void) { - return (xine_mm_accel() & MM_ACCEL_X86_MMXEXT); -} - -void zoom_filter_xmmx (int prevX, int prevY, - unsigned int *expix1, unsigned int *expix2, - int *lbruS, int *lbruD, int buffratio, - int precalCoef[16][16]) -{ - int bufsize = prevX * prevY; /* taille du buffer */ - volatile int loop; /* variable de boucle */ - - mmx_t *brutS = (mmx_t*)lbruS; /* buffer de transformation source */ - mmx_t *brutD = (mmx_t*)lbruD; /* buffer de transformation dest */ - - volatile mmx_t prevXY; - volatile mmx_t ratiox; - volatile mmx_t interpix; - - expix1[0]=expix1[prevX-1]=expix1[prevX*prevY-1]=expix1[prevX*prevY-prevX]=0; - - prevXY.ud[0] = (prevX-1)<>16 format [X|Y] - * modified = mm0,mm1,mm2 - */ - - __asm__ __volatile__ ( - "movq %0,%%mm0\n" - "movq %1,%%mm1\n" - : :"X"(brutS[loop]),"X"(brutD[loop]) - ); /* mm0 = S */ - - psubd_r2r (mm0,mm1); /* mm1 = D - S */ - movq_r2r (mm1, mm2); /* mm2 = D - S */ - - pslld_i2r (16,mm1); - mmx_r2r (pmulhuw, mm6, mm1); /* mm1 = ?? */ - pmullw_r2r (mm6, mm2); - - paddd_r2r (mm2, mm1); /* mm1 = (D - S) * buffratio >> 16 */ - pslld_i2r (16,mm0); - - paddd_r2r (mm1, mm0); /* mm0 = S + mm1 */ - psrld_i2r (16, mm0); - - /* - * pre : mm0 : position vector on screen - * prevXY : coordinate of the lower-right point on screen - * post : clipped mm0 - * modified : mm0,mm1,mm2 - */ - movq_m2r (prevXY,mm1); - pcmpgtd_r2r (mm0, mm1); /* mm0 en X contient : - 1111 si prevXY > px - 0000 si prevXY <= px - (idem pour y) */ -#ifdef STRICT_COMPAT - movq_r2r (mm1,mm2); - punpckhdq_r2r (mm2,mm2); - punpckldq_r2r (mm1,mm1); - pand_r2r (mm2, mm0); -#endif - pand_r2r (mm1, mm0); /* on met a zero la partie qui deborde */ - - /* - * pre : mm0 : clipped position on screen - * - * post : mm3 & mm4 : coefs for this position - * mm1 : X vector [0|X] - * - * modif : eax,ebx - */ - __asm__ __volatile__ ( - "movd %%mm0,%%ebx\n" - "movq %%mm0,%%mm1\n" - - "andl $15,%%ebx\n" - "psrlq $32,%%mm1\n" - - "shll $6,%%ebx\n" - "movd %%mm1,%%eax\n" - - "addl %0,%%ebx\n" - "andl $15,%%eax\n" - - "movd (%%ebx,%%eax,4),%%mm3\n" - ::"X"(precalCoef):"eax","ebx"); - - /* - * extraction des coefficients... - * - * pre : coef dans mm3 - * - * post : coef extraits dans mm3 (c1 & c2) - * et mm4 (c3 & c4) - * - * modif : mm5 - */ -// entrelace avec portion d'apres (cf les '^') -// movq_r2r (mm3, mm5); /* ??-??-??-??-c4-c3-c2-c1 */ -// punpcklbw_r2r (mm5, mm3); /* c4-c4-c3-c3-c2-c2-c1-c1 */ -// movq_r2r (mm3, mm4); /* c4-c4-c3-c3-c2-c2-c1-c1 */ -// movq_r2r (mm3, mm5); /* c4-c4-c3-c3-c2-c2-c1-c1 */ - -// punpcklbw_r2r (mm5, mm3); /* c2-c2-c2-c2-c1-c1-c1-c1 */ -// punpckhbw_r2r (mm5, mm4); /* c4-c4-c4-c4-c3-c3-c3-c3 */ - - /* - * pre : mm0 : Y pos [*|Y] - * mm1 : X pos [*|X] - * - * post : mm0 : expix1[position] - * mm2 : expix1[position+largeur] - * - * modif : eax,ebx - */ - psrld_i2r (PERTEDEC,mm0); - psrld_i2r (PERTEDEC,mm1); - __asm__ __volatile__ ( - "movd %%mm1,%%eax\n" - /*^*/ "movq %%mm3,%%mm5\n" /*^*/ - - "mull %1\n" - "movd %%mm0,%%ebx\n" - /*^*/ "punpcklbw %%mm5, %%mm3\n" /*^*/ - - "addl %%ebx,%%eax\n" - /*^*/ "movq %%mm3,%%mm4\n" /*^*/ - /*^*/ "movq %%mm3,%%mm5\n" /*^*/ - - "movl %0,%%ebx\n" - /*^*/ "punpcklbw %%mm5,%%mm3\n" /*^*/ - - "movq (%%ebx,%%eax,4),%%mm0\n" - /*^*/ "punpckhbw %%mm5,%%mm4\n" /*^*/ - - "addl %1,%%eax\n" - "movq (%%ebx,%%eax,4),%%mm2\n" - - : : "X"(expix1), "X"(prevX):"eax","ebx" - ); - - /* - * pre : mm0 : expix1[position] - * mm2 : expix1[position+largeur] - * mm3 & mm4 : coefs - */ - - /* recopie des deux premiers pixels dans mm0 et mm1 */ - movq_r2r (mm0, mm1); /* b1-v1-r1-a1-b2-v2-r2-a2 */ - - /* depackage du premier pixel */ - punpcklbw_r2r (mm7, mm0); /* 00-b2-00-v2-00-r2-00-a2 */ - - /* extraction des coefficients... */ - - movq_r2r (mm3, mm5); /* c2-c2-c2-c2-c1-c1-c1-c1 */ - - /*^en parrallele^*/ /* depackage du 2ieme pixel */ - /*^*/ punpckhbw_r2r (mm7, mm1); /* 00-b1-00-v1-00-r1-00-a1 */ - - punpcklbw_r2r (mm7, mm5); /* 00-c1-00-c1-00-c1-00-c1 */ - punpckhbw_r2r (mm7, mm3); /* 00-c2-00-c2-00-c2-00-c2 */ - - /* multiplication des pixels par les coefficients */ - pmullw_r2r (mm5, mm0); /* c1*b2-c1*v2-c1*r2-c1*a2 */ - pmullw_r2r (mm3, mm1); /* c2*b1-c2*v1-c2*r1-c2*a1 */ - paddw_r2r (mm1, mm0); - - /* ...extraction des 2 derniers coefficients */ - movq_r2r (mm4, mm5); /* c4-c4-c4-c4-c3-c3-c3-c3 */ - punpcklbw_r2r (mm7, mm4); /* 00-c3-00-c3-00-c3-00-c3 */ - punpckhbw_r2r (mm7, mm5); /* 00-c4-00-c4-00-c4-00-c4 */ - - /* recuperation des 2 derniers pixels */ - movq_r2r (mm2, mm1); - - /* depackage des pixels */ - punpcklbw_r2r (mm7, mm1); - punpckhbw_r2r (mm7, mm2); - - /* multiplication pas les coeffs */ - pmullw_r2r (mm4, mm1); - pmullw_r2r (mm5, mm2); - - /* ajout des valeurs obtenues à la valeur finale */ - paddw_r2r (mm1, mm0); - paddw_r2r (mm2, mm0); - - /* division par 256 = 16+16+16+16, puis repackage du pixel final */ - psrlw_i2r (8, mm0); - packuswb_r2r (mm7, mm0); - - movd_r2m (mm0,expix2[loop]); - - ++loop; - } -#ifdef HAVE_ATHLON - __asm__ __volatile__ ("femms\n"); -#else - emms(); -#endif -} -- cgit v1.2.3