Changeset 1783
- Timestamp:
- Jun 28, 2007, 2:49:28 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/src/cacademo.c
r1777 r1783 840 840 } 841 841 842 842 /* Rotozoom effect */ 843 843 #define TEXTURE_SIZE 256 844 844 #define TABLE_SIZE 65536 … … 851 851 #define TOINT(a) (a>>PRECISION); 852 852 853 854 853 #include "texture.h" 855 854 856 855 void rotozoom(enum action action, cucul_canvas_t *canvas) 857 856 { 857 static uint32_t screen[XSIZ * YSIZ]; 858 static int cos_tab[TABLE_SIZE], sin_tab[TABLE_SIZE]; 859 static int y_tab[TEXTURE_SIZE]; 860 858 861 static cucul_dither_t *dither; 859 static unsigned int *screen, *save; 862 static uint32_t *texture; 863 uint32_t *p; 860 864 static int alphaF, tF; 861 865 int scaleF; 862 static int *texture;863 static int *cosTable;864 static int *sinTable;865 static int *yTable;866 866 867 867 /* register is quite a bad idea on CISC, but not on RISC */ 868 868 register unsigned int x, y; 869 869 register unsigned int xxF, yyF, uF, vF, uF_, vF_; 870 register unsigned int 870 register unsigned int vu, vv; 871 871 872 872 switch(action) 873 873 { 874 case PREPARE: 875 for(x = 0; x < TABLE_SIZE; x++) 876 { 877 cos_tab[x] = TOFIX(cos(x * (360.0f / (float)TABLE_SIZE))); 878 sin_tab[x] = TOFIX(sin(x * (360.0f / (float)TABLE_SIZE))); 879 } 880 for(x = 0; x < TEXTURE_SIZE; x++) 881 y_tab[x] = x * TEXTURE_SIZE; /* start of lines offsets */ 882 /* FIXME: this may be an invalid cast */ 883 texture = (uint32_t *)textureByte; 884 break; 885 874 886 case INIT: 875 screen = (unsigned int*)malloc(4 * XSIZ * YSIZ 876 * sizeof(unsigned char)); 877 dither = cucul_create_dither(32, 878 XSIZ, YSIZ, 879 XSIZ*4, 887 dither = cucul_create_dither(32, XSIZ, YSIZ, XSIZ * 4, 880 888 0x00FF0000, 881 889 0x0000FF00, 882 890 0x000000FF, 883 891 0x00000000); 884 save = screen;885 texture = (int*) textureByte;886 887 cosTable = malloc(TABLE_SIZE*sizeof(int));888 sinTable = malloc(TABLE_SIZE*sizeof(int));889 yTable = malloc(TEXTURE_SIZE*sizeof(int));890 891 for(x=0; x<TABLE_SIZE; x++) { /* Cos and Sin tables*/892 cosTable[x] = TOFIX(cos(x*(360.0f/(float)TABLE_SIZE)));893 sinTable[x] = TOFIX(sin(x*(360.0f/(float)TABLE_SIZE)));894 }895 for(x=0; x<TEXTURE_SIZE; x++) { /* start of lines offsets */896 yTable[x] = x*TEXTURE_SIZE;897 }898 break;899 900 case PREPARE:901 892 break; 902 893 903 894 case UPDATE: 904 alphaF += 905 tF += 906 scaleF = FMUL(sinTable[tF&0xFFFF], TOFIX(3)) + TOFIX(4);907 xxF = FMUL(cosTable[(alphaF)&0xFFFF], scaleF);908 yyF = FMUL(sinTable[(alphaF)&0xFFFF], scaleF);895 alphaF += 4; 896 tF += 3; 897 scaleF = FMUL(sin_tab[tF & 0xFFFF], TOFIX(3)) + (TOFIX(4)); 898 xxF = FMUL(cos_tab[(alphaF) & 0xFFFF], scaleF); 899 yyF = FMUL(sin_tab[(alphaF) & 0xFFFF], scaleF); 909 900 uF = vF = 0; 910 901 uF_ = vF_ = 0; 911 screen = save; 912 913 y = YSIZ; 914 while(y--) { 915 916 x = XSIZ; 917 while(x--) { 918 919 uF+=xxF; 920 vF+=yyF; 902 p = screen; 903 904 for(y = YSIZ; y--;) 905 { 906 for(x = XSIZ; x--;) 907 { 908 uF += xxF; 909 vF += yyF; 921 910 922 911 vu = TOINT(uF); 923 912 vv = TOINT(vF); 924 vu &=0xFF; /* ARM doesn't like */925 vv &=0xFF; /* chars as local vars */926 927 * screen++ = texture[vu+yTable[vv]];928 913 vu &= 0xFF; /* ARM doesn't like */ 914 vv &= 0xFF; /* chars as local vars */ 915 916 *p++ = texture[vu + y_tab[vv]]; 917 } 929 918 930 919 uF = uF_ -= yyF; … … 932 921 } 933 922 break; 923 934 924 case RENDER: 935 925 cucul_dither_bitmap(canvas, 0, 0, 936 926 cucul_get_canvas_width(canvas), 937 927 cucul_get_canvas_height(canvas), 938 dither, s ave);928 dither, screen); 939 929 break; 940 930 941 931 case FREE: 942 free(cosTable);943 free(sinTable);944 free(save);945 932 cucul_free_dither(dither); 946 933 break; 947 934 } 948 949 } 935 } 936
Note: See TracChangeset
for help on using the changeset viewer.