From 67e2e8d7b6029f0afd21961512f70fd366920a0d Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Thu, 28 Jun 2007 12:49:28 +0000 Subject: [PATCH] * Removed malloc() calls from the rotozoom code, put initialisation in the PREPARE rule and did minor cleanup (SCNR). --- src/cacademo.c | 93 ++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/src/cacademo.c b/src/cacademo.c index dcf4de8..d62031b 100644 --- a/src/cacademo.c +++ b/src/cacademo.c @@ -839,7 +839,7 @@ void matrix(enum action action, cucul_canvas_t *cv) } } - +/* Rotozoom effect */ #define TEXTURE_SIZE 256 #define TABLE_SIZE 65536 @@ -850,100 +850,87 @@ void matrix(enum action action, cucul_canvas_t *cv) #define TOFIX(d) ((int)( (d)*(double)(1<>PRECISION); - #include "texture.h" void rotozoom(enum action action, cucul_canvas_t *canvas) { + static uint32_t screen[XSIZ * YSIZ]; + static int cos_tab[TABLE_SIZE], sin_tab[TABLE_SIZE]; + static int y_tab[TEXTURE_SIZE]; + static cucul_dither_t *dither; - static unsigned int *screen, *save; + static uint32_t *texture; + uint32_t *p; static int alphaF, tF; int scaleF; - static int *texture; - static int *cosTable; - static int *sinTable; - static int *yTable; /* register is quite a bad idea on CISC, but not on RISC */ register unsigned int x, y; register unsigned int xxF, yyF, uF, vF, uF_, vF_; - register unsigned int vu, vv; + register unsigned int vu, vv; switch(action) { + case PREPARE: + for(x = 0; x < TABLE_SIZE; x++) + { + cos_tab[x] = TOFIX(cos(x * (360.0f / (float)TABLE_SIZE))); + sin_tab[x] = TOFIX(sin(x * (360.0f / (float)TABLE_SIZE))); + } + for(x = 0; x < TEXTURE_SIZE; x++) + y_tab[x] = x * TEXTURE_SIZE; /* start of lines offsets */ + /* FIXME: this may be an invalid cast */ + texture = (uint32_t *)textureByte; + break; + case INIT: - screen = (unsigned int*)malloc(4 * XSIZ * YSIZ - * sizeof(unsigned char)); - dither = cucul_create_dither(32, - XSIZ, YSIZ, - XSIZ*4, + dither = cucul_create_dither(32, XSIZ, YSIZ, XSIZ * 4, 0x00FF0000, 0x0000FF00, 0x000000FF, 0x00000000); - save = screen; - texture = (int*) textureByte; - - cosTable = malloc(TABLE_SIZE*sizeof(int)); - sinTable = malloc(TABLE_SIZE*sizeof(int)); - yTable = malloc(TEXTURE_SIZE*sizeof(int)); - - for(x=0; x