goom_core.c
来自「linux下的MPEG1」· C语言 代码 · 共 894 行 · 第 1/3 页
C
894 行
/*** 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 <math.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <inttypes.h>#include "goom.h"#include "goom_tools.h"#include "goom_filters.h"#include "lines.h"#include "ifs.h"#include "tentacle3d.h"#include "gfontlib.h"#include "sound_tester.h"#include "goom_plugin_info.h"#include "goom_fx.h"#include "goomsl.h"#include "xine_internal.h"/* #define VERBOSE */#define STOP_SPEED 128/* TODO: put that as variable in PluginInfo */#define TIME_BTW_CHG 300static void choose_a_goom_line (PluginInfo *goomInfo, float *param1, float *param2, int *couleur, int *mode, float *amplitude, int isfar);static void update_message (PluginInfo *goomInfo, char *message);static void init_buffers(PluginInfo *goomInfo, int buffsize){ goomInfo->pixel = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); memset (goomInfo->pixel, 0, buffsize * sizeof (guint32) + 128); goomInfo->back = (guint32 *) malloc (buffsize * sizeof (guint32) + 128); memset (goomInfo->back, 0, buffsize * sizeof (guint32) + 128); goomInfo->conv = (Pixel *) malloc (buffsize * sizeof (guint32) + 128); memset (goomInfo->conv, 0, buffsize * sizeof (guint32) + 128); goomInfo->outputBuf = goomInfo->conv; goomInfo->p1 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->pixel)) / 128) * 128); goomInfo->p2 = (Pixel *) ((1 + ((uintptr_t) (goomInfo->back)) / 128) * 128);}/*************************** INIT ***************************/PluginInfo *goom_init (guint32 resx, guint32 resy){ PluginInfo *goomInfo = (PluginInfo*)malloc(sizeof(PluginInfo)); #ifdef VERBOSE printf ("GOOM: init (%d, %d);\n", resx, resy);#endif plugin_info_init(goomInfo,4); goomInfo->star_fx = flying_star_create(); goomInfo->star_fx.init(&goomInfo->star_fx, goomInfo); goomInfo->zoomFilter_fx = zoomFilterVisualFXWrapper_create (); goomInfo->zoomFilter_fx.init(&goomInfo->zoomFilter_fx, goomInfo); goomInfo->tentacles_fx = tentacle_fx_create(); goomInfo->tentacles_fx.init(&goomInfo->tentacles_fx, goomInfo); goomInfo->convolve_fx = convolve_create(); goomInfo->convolve_fx.init(&goomInfo->convolve_fx, goomInfo); 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); 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 (PluginInfo *goomInfo, guint32 resx, guint32 resy){ 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, goomInfo); goom_lines_set_res (goomInfo->gmline1, resx, goomInfo->screen.height); goom_lines_set_res (goomInfo->gmline2, resx, goomInfo->screen.height);}int goom_set_screenbuffer(PluginInfo *goomInfo, void *buffer){ goomInfo->outputBuf = (Pixel*)buffer; return 1;}/********************************************* UPDATE ********************************************** WARNING: this is a 600 lines function ! (21-11-2003)*/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); }#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 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,34)) { 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;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?