DEMO.DESIGN
Frequently Asked Questions
 
оглавление | demo party в ex-СССР | infused bytes e-mag | новости от ib/news | другие проекты | письмо | win koi lat

следующий фpагмент (2)
=== Cut === /* * "spiral" effect * by shodan@chat.ru */ #include <math.h> #include <stdio.h> #define PI 3.1415926 #define FILTERW 120 #define FILTERH 120 #define FILTERW_2 (FILTERW / 2) #define FILTERH_2 (FILTERH / 2) int FILTER_W = FILTERW; /* for external apply_filter() */ int FILTER_H = FILTERH; double sp_Amp = 2 * PI; /* default spiral parameters */ double sp_Pow = 6; char bmp[64000]; int filter[FILTERW * FILTERH]; extern void setvmode(int); #pragma aux setvmode = \ " int 10h " \ parm [eax] \ modify exact [eax]; void wait_retrace() { while ((inp(0x3DA) & 0x08) == 0); while ((inp(0x3DA) & 0x08) != 0); } void fload(char *name, int size, void *dest) { FILE *f; if ((f=fopen(name, "rb")) == NULL) { printf("error: file %s not found.\n", name); exit(1); } if (fread(dest, 1, size, f) != size) { printf("error: can't read data from %s.\n", name); exit(1); } fclose(f); } extern void apply_filter(char *dest, char *src, int *filter, int x, int y); #pragma aux apply_filter parm [edi] [esi] [ebx] [ecx] [edx] \ modify exact [eax ebx ecx edx esi edi]; /* * Old version of apply_filter() * New one is just ported to assembler, gives a small speed gain though */ /* void apply_filter(char *dst, char *src, int *filter, int x, int y) { int i, j, o = x + 320 * y, *f = filter; char *d = dst + o, *s = src + o; for (i = 0; i < FILTERW; i++) { for (j = 0; j < FILTERH; j++) *d++ = *(s++ + *f++); d += (320 - FILTERW); s += (320 - FILTERW); } } */ void make_filter() { int i, j, i1, j1, v; double r, a, t0, t1; for (i = 0; i < FILTERW; i++) for (j = 0; j < FILTERH; j++) { r = sqrt(((double)i / FILTERW - 0.5) * ((double)i / FILTERW - 0.5) + ((double)j / FILTERH - 0.5) * ((double)j / FILTERH - 0.5)); if (r < 0.5) { a = sp_Amp * pow(1 - 2 * r, sp_Pow); i1 = (i - FILTERW_2) * cos(a) - (j - FILTERH_2) * sin(a) + FILTERW_2 - i; j1 = (i - FILTERW_2) * sin(a) + (j - FILTERH_2) * cos(a) + FILTERH_2 - j; v = i1 + j1 * 320; } else v = 0; filter[i + FILTERW * j] = v; } } void main () { int i = 0, x, y, f = 0, t; char c, p[0x300]; make_filter(); fload("pic.pal", 0x300, (char*)&p); fload("pic.raw", 64000, (char*)&bmp); setvmode(0x13); outp(0x3C8, 0x00); for(i = 0; i < 0x300; i++) outp(0x3C9, p[i]); t = clock(); do { x = (1 + cos ((double)f / 13)) * (160 - FILTERW_2); y = (1 + sin ((double)f / 23)) * (100 - FILTERH_2); wait_retrace(); wait_retrace(); memcpy((char*)0xA0000L, (char*)&bmp, 64000); apply_filter((char*)0xA0000L, (char*)&bmp, (int*)&filter, x, y); f++; c = kbhit() ? getch() : 0; switch(c) { case 'q': case 'Q': sp_Amp += 0.2 * PI; make_filter(); break; case 'w': case 'W': sp_Amp -= 0.2 * PI; make_filter(); break; case 'e': case 'E': sp_Pow += 0.1; make_filter(); break; case 'r': case 'R': sp_Pow -= 0.1; make_filter(); break; case 't': case 'T': sp_Amp = 2 * PI; sp_Pow = 6; make_filter(); break; } } while (c != 0x1B); t = clock() - t; setvmode(0x03); printf("a simple \"spiral\" effect - coded by shodan\ne-mail: andrew@" \ "stu.lipetsk.su\nuse q/w/e/r/t to mess around with amp/pow values\n" \ "%d frames %d.%02d seconds %d.%02d fps amp=%3.1lf*pi pow=%3" \ ".1lf\n", f, t/100, t%100, 100*f/t, 10000*f/t - 100*(100*f/t), sp_Amp / PI, sp_Pow); } === Cut === === Cut === ; Hand-optimized apply_filter() .386p .model flat public apply_filter_ _DATA segment use32 dword public 'DAT' extrn _FILTER_H: dword extrn _FILTER_W: dword _DATA ends _TEXT segment use32 dword public 'CODE' assume cs:_TEXT, ds:_DATA ; void apply_filter(char *dest, char *src, int *filter, int x, int y) { ; in: esi=src edi=dst ebx=filter ecx=x edx=y apply_filter_ proc near shl edx,6 mov eax,edx shl eax,2 add eax,edx add eax,ecx shr edx,6 add esi,eax add edi,eax mov edx,_FILTER_H y_loop: mov ecx,_FILTER_W x_loop: mov eax,[ebx] add ebx,4 mov al,[eax+esi] inc esi mov [edi],al inc edi dec ecx jnz x_loop add edi,320 add esi,320 sub edi,_FILTER_W sub esi,_FILTER_W dec edx jnz y_loop ret apply_filter_ endp _TEXT ends end === Cut === Вот более быстрая (в два раза быстрее) версия apply_filter(). === Cut === ; Hand-optimized apply_filter() ; another 2x speed gain .386p .model flat public apply_filter_ _DATA segment use32 dword public 'DAT' extrn _FILTER_H: dword extrn _FILTER_W: dword _DATA ends _TEXT segment use32 dword public 'CODE' assume cs:_TEXT, ds:_DATA ; void apply_filter(char *dest, char *src, int *filter, int x, int y) { ; in: esi=src edi=dst ebx=filter ecx=x edx=y apply_filter_ proc near push ebp shl edx,6 mov eax,edx shl eax,2 add eax,edx add eax,ecx shr edx,6 add esi,eax add edi,eax mov edx,_FILTER_H y_loop: mov ecx,_FILTER_W push edx shr ecx,2 x_loop: mov eax,[ebx+12] mov ebp,[ebx+8] mov edx,[ebx+4] add ebx,16 mov ah,[eax+esi+3] add edi,4 mov al,[ebp+esi+2] mov ebp,[ebx-16] shl eax,16 mov ah,[edx+esi+1] mov al,[ebp+esi] add esi,4 mov [edi-4],eax dec ecx jnz x_loop pop edx add edi,320 add esi,320 sub edi,_FILTER_W sub esi,_FILTER_W dec edx jnz y_loop pop ebp ret apply_filter_ endp _TEXT ends end === Cut ===

Всего 1 фpагмент(а/ов) |пpедыдущий фpагмент (1)

Если вы хотите дополнить FAQ - пожалуйста пишите.

design/collection/some content by Frog,
DEMO DESIGN FAQ (C) Realm Of Illusion 1994-2000,
При перепечатке материалов этой страницы пожалуйста ссылайтесь на источник: "DEMO.DESIGN FAQ, http://www.enlight.ru/demo/faq".