Browse Source

* Removed malloc() calls from the rotozoom code, put initialisation in the

PREPARE rule and did minor cleanup (SCNR).
tags/v0.99.beta14
Sam Hocevar sam 17 years ago
parent
commit
67e2e8d7b6
1 changed files with 40 additions and 53 deletions
  1. +40
    -53
      src/cacademo.c

+ 40
- 53
src/cacademo.c View File

@@ -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) ))
#define TOINT(a) (a>>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<TABLE_SIZE; x++) { /* Cos and Sin tables*/
cosTable[x] = TOFIX(cos(x*(360.0f/(float)TABLE_SIZE)));
sinTable[x] = TOFIX(sin(x*(360.0f/(float)TABLE_SIZE)));
}
for(x=0; x<TEXTURE_SIZE; x++) { /* start of lines offsets */
yTable[x] = x*TEXTURE_SIZE;
}
break;

case PREPARE:
break;

case UPDATE:
alphaF += 4;
tF += 3;
scaleF = FMUL(sinTable[tF&0xFFFF], TOFIX(3)) + TOFIX(4);
xxF = FMUL(cosTable[(alphaF)&0xFFFF], scaleF);
yyF = FMUL(sinTable[(alphaF)&0xFFFF], scaleF);
alphaF += 4;
tF += 3;
scaleF = FMUL(sin_tab[tF & 0xFFFF], TOFIX(3)) + (TOFIX(4));
xxF = FMUL(cos_tab[(alphaF) & 0xFFFF], scaleF);
yyF = FMUL(sin_tab[(alphaF) & 0xFFFF], scaleF);
uF = vF = 0;
uF_ = vF_ = 0;
screen = save;
p = screen;

y = YSIZ;
while(y--) {

x = XSIZ;
while(x--) {

uF+=xxF;
vF+=yyF;
for(y = YSIZ; y--;)
{
for(x = XSIZ; x--;)
{
uF += xxF;
vF += yyF;

vu = TOINT(uF);
vv = TOINT(vF);
vu&=0xFF; /* ARM doesn't like */
vv&=0xFF; /* chars as local vars */
vu &= 0xFF; /* ARM doesn't like */
vv &= 0xFF; /* chars as local vars */

*screen++ = texture[vu+yTable[vv]];
}
*p++ = texture[vu + y_tab[vv]];
}

uF = uF_ -= yyF;
vF = vF_ += xxF;
}
break;

case RENDER:
cucul_dither_bitmap(canvas, 0, 0,
cucul_get_canvas_width(canvas),
cucul_get_canvas_height(canvas),
dither, save);
dither, screen);
break;

case FREE:
free(cosTable);
free(sinTable);
free(save);
cucul_free_dither(dither);
break;
}

}


Loading…
Cancel
Save