123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 |
- /*
- LICENSE
- -------
- Copyright 2005 Nullsoft, Inc.
- All rights reserved.
- Redistribution and use in source and binary forms, with or without modification,
- are permitted provided that the following conditions are met:
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of Nullsoft nor the names of its contributors may be used to
- endorse or promote products derived from this software without specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
- IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
- FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
- IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
- OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
- #include <windows.h>
- #include <stdio.h>
- #include <commctrl.h>
- #include <process.h>
- #include "draw.h"
- #include "resource.h"
- #include "cfgwnd.h"
- #include "r_defs.h"
- #include "r_unkn.h"
- #include "r_transition.h"
- #include "render.h"
- #include <math.h>
- #include "../Agave/Language/api_language.h"
- extern char *scanstr_back(char *str, char *toscan, char *defval);
- int transitionmodes[] =
- {
- IDS_RANDOM,
- IDS_CROSS_DISSOLVE,
- IDS_L_R_PUSH,
- IDS_R_L_PUSH,
- IDS_T_B_PUSH,
- IDS_B_T_PUSH,
- IDS_9_RANDOM_BLOCKS,
- IDS_SPLIT_L_R_PUSH,
- IDS_L_R_CENTER_PUSH,
- IDS_L_R_CENTER_SQUEEZE,
- IDS_L_R_WIPE,
- IDS_R_L_WIPE,
- IDS_T_B_WIPE,
- IDS_B_T_WIPE,
- IDS_DOT_DISSOLVE,
- };
- static C_RenderTransitionClass *g_this;
- C_RenderTransitionClass::C_RenderTransitionClass()
- {
- last_file[0]=0;
- l_w=l_h=0;
- memset(fbs,0,sizeof(fbs));
- enabled=0;
- start_time=0;
- _dotransitionflag=0;
- initThread=0;
- }
- C_RenderTransitionClass::~C_RenderTransitionClass()
- {
- int x;
- if (initThread)
- {
- WaitForSingleObject(initThread,INFINITE);
- CloseHandle(initThread);
- initThread=0;
- } for (x = 0; x < 4; x ++)
- {
- if (fbs[x]) GlobalFree(fbs[x]);
- fbs[x]=NULL;
- }
- }
- unsigned int WINAPI C_RenderTransitionClass::m_initThread(LPVOID p)
- {
- C_RenderTransitionClass *_this=(C_RenderTransitionClass*)p;
- FILETIME ft;
- GetSystemTimeAsFileTime(&ft);
- srand(ft.dwLowDateTime|ft.dwHighDateTime^GetCurrentThreadId());
- if (cfg_transitions2&32)
- {
- extern HANDLE g_hThread;
- int d=GetThreadPriority(g_hThread);
- if (d == THREAD_PRIORITY_TIME_CRITICAL) d=THREAD_PRIORITY_HIGHEST;
- else if (d == THREAD_PRIORITY_HIGHEST) d=THREAD_PRIORITY_ABOVE_NORMAL;
- else if (d == THREAD_PRIORITY_ABOVE_NORMAL) d=THREAD_PRIORITY_NORMAL;
- else if (d == THREAD_PRIORITY_NORMAL) d=THREAD_PRIORITY_BELOW_NORMAL;
- else if (d == THREAD_PRIORITY_BELOW_NORMAL) d=THREAD_PRIORITY_LOWEST;
- else if (d == THREAD_PRIORITY_LOWEST) d=THREAD_PRIORITY_IDLE;
- SetThreadPriority(GetCurrentThread(),d);
- }
- int *fb=(int *)GlobalAlloc(GPTR,_this->l_w*_this->l_h*sizeof(int));
- char last_visdata[2][2][576]={0,};
- g_render_effects2->render(last_visdata,0x80000000,fb,fb,_this->l_w,_this->l_h);
- GlobalFree((HGLOBAL)fb);
- _this->_dotransitionflag=2;
- _endthreadex(0);
- return 0;
- }
- int C_RenderTransitionClass::LoadPreset(char *file, int which, C_UndoItem *item)
- {
- if (initThread)
- {
- if (WaitForSingleObject(initThread,0)==WAIT_TIMEOUT)
- {
- DDraw_SetStatusText("loading [wait]...",1000*100);
- return 2;
- }
- CloseHandle(initThread);
- initThread=0;
- }
- EnterCriticalSection(&g_render_cs);
- if (enabled)
- {
- enabled=0;
- }
- int r = 0;
-
- if (item)
- {
- g_render_effects2->__LoadPresetFromUndo(*item,1);
- last_which=which;
- _dotransitionflag=2;
- }
- else
- {
- lstrcpyn(last_file,file,sizeof(last_file));
- if (file[0]) r=g_render_effects2->__LoadPreset(file,1);
- else
- {
- g_render_effects2->clearRenders();
- }
- if (!r && l_w && l_h && (cfg_transitions2&which) && ((cfg_transitions2&128)||DDraw_IsFullScreen()))
- {
- DWORD id;
- last_which=which;
- _dotransitionflag=1;
- initThread=(HANDLE)_beginthreadex(NULL,0,m_initThread,(LPVOID)this,0,(unsigned int*)&id);
- DDraw_SetStatusText("loading...",1000*100);
- }
- else
- {
- last_which=which;
- _dotransitionflag=2;
- }
- if (r)
- {
- char s[MAX_PATH*2];
- wsprintf(s,WASABI_API_LNGSTRING(IDS_ERROR_LOADING_X),scanstr_back(last_file,"\\",last_file-1)+1);
- DDraw_SetStatusText(s);
- _dotransitionflag=3;
- }
- C_UndoStack::clear();
- C_UndoStack::saveundo(1);
- C_UndoStack::cleardirty();
- }
- LeaveCriticalSection(&g_render_cs);
- return !!r;
- }
- #define PI 3.14159265358979323846
- //264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848...
- extern int g_rnd_cnt;
- int C_RenderTransitionClass::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
- {
- if (_dotransitionflag||enabled) g_rnd_cnt=0;
- if (_dotransitionflag==2 || _dotransitionflag == 3)
- {
- int notext=_dotransitionflag==3;
- _dotransitionflag=0;
- if (cfg_transitions&last_which)
- {
- curtrans = (cfg_transition_mode&0x7fff) ? (cfg_transition_mode&0x7fff) : (rand() % ((sizeof(transitionmodes)/sizeof(transitionmodes[0]))-1))+1;
- if (cfg_transition_mode&0x8000) curtrans|=0x8000;
- ep[0]=0;
- ep[1]=2;
- mask=0;
- start_time=0;
- enabled=1;
- }
- C_RenderListClass *temp=g_render_effects;
- g_render_effects=g_render_effects2;
- g_render_effects2=temp;
- extern int need_repop;
- extern char *extension(char *fn);
- need_repop=1;
- PostMessage(g_hwndDlg,WM_USER+20,0,0);
- if (!notext && stricmp("aph",extension(last_file)))
- {
- char buf[512];
- strncpy(buf,scanstr_back(last_file,"\\",last_file-1)+1,510);
- buf[510]=0;
- scanstr_back(buf,".",buf+strlen(buf))[0]=0;
- strcat(buf," ");
- DDraw_SetStatusText(buf);
- }
- }
- if (!enabled)
- {
- int x;
- l_w=w;
- l_h=h;
- if (fbs[0]) for (x = 0; x < 4; x ++)
- {
- if (fbs[x])
- {
- GlobalFree(fbs[x]);
- fbs[x]=NULL;
- }
- }
- if (!initThread && g_render_effects2->getNumRenders())
- {
- g_render_effects2->clearRenders();
- g_render_effects2->freeBuffers();
- }
- return g_render_effects->render(visdata,isBeat,framebuffer,fbout,w,h);
- }
- // handle resize
- if (l_w != w || l_h != h || !fbs[0])
- {
- l_w=w;
- l_h=h;
- int x;
- for (x = 0; x < 4; x ++)
- {
- if (fbs[x]) GlobalFree(fbs[x]);
- fbs[x]=(int*)GlobalAlloc(GPTR,l_w*l_h*sizeof(int));
- }
- }
- if (start_time == 0)
- {
- memcpy(fbs[ep[0]],framebuffer,sizeof(int)*l_w*l_h);
- memcpy(fbs[ep[1]],framebuffer,sizeof(int)*l_w*l_h);
- }
- // maybe there's a faster way than using 3 more buffers without screwing
- // any effect... justin ?
- if (curtrans&0x8000)
- ep[1]^=g_render_effects2->render(visdata,isBeat,fbs[ep[1]],fbs[ep[1]^1],w,h)&1;
- ep[0]^=g_render_effects->render(visdata,isBeat,fbs[ep[0]],fbs[ep[0]^1],w,h)&1;
- int *p = fbs[ep[1]];
- int *d = fbs[ep[0]];
- int *o = framebuffer;
- int x=w*h;
- int ttime=250*cfg_transitions_speed;
- if (ttime<100) ttime=100;
- int n;
- if (!start_time) { n=0; start_time=GetTickCount(); }
- else n=MulDiv(GetTickCount()-start_time,256,ttime);
- if (n >= 255) n=255;
- float sintrans = (float)(sin(((float)n/255)*PI-PI/2)/2+0.5); // used for smoothing transitions
- // now sintrans does a smooth curve
- // from 0 to 1
- switch (curtrans&0x7fff)
- {
- case 1: // Crossfade
- mmx_adjblend_block(o,d,p,x,n);
- break;
- case 2: // Left to right push
- {
- int i = (int)(sintrans*w);
- int j;
- for (j=0;j<h;j++)
- {
- memcpy(framebuffer+(j*w), d+(j*w)+(w-i), i*4);
- memcpy(framebuffer+(j*w)+i, p+(j*w), (w-i)*4);
- }
- }
- break;
- case 3: // Right to left push
- {
- int i = (int)(sintrans*w);
- int j;
- for (j=0;j<h;j++)
- {
- memcpy(framebuffer+(j*w), p+(i+j*w), (w-i)*4);
- memcpy(framebuffer+(j*w)+(w-i), d+(j*w), i*4);
- }
- }
- break;
- case 4: // Top to bottom push
- {
- int i = (int)(sintrans*h);
- memcpy(framebuffer, d+(h-i)*w, w*i*4);
- memcpy(framebuffer+w*i, p, w*(h-i)*4);
- }
- break;
- case 5: // Bottom to Top push
- {
- int i = (int)(sintrans*h);
- memcpy(framebuffer,p+i*w, w*(h-i)*4);
- memcpy(framebuffer+w*(h-i), d, w*i*4);
- }
- break;
- case 6: // 9 random blocks
- {
- if (!(mask&(1<<(10+n/28))))
- {
- int r=0;
- if ((mask & 0x1ff) != 0x1ff)
- {
- do
- {
- r = rand()%9;
- }
- while ((1 << r) & mask);
- }
- mask |= (1<<r)|(1<<(10+n/28));
- }
- int j;
- int tw=w/3, th=h/3;
- int twr=w-2*tw;
- memcpy(framebuffer, p, w*h*4);
- int i;
- for (i=0;i<9;i++)
- {
- if (mask & (1<<i))
- {
- int end=i/3*th+th;
- if (i > 5) end=h;
- for (j=i/3*th;j<end;j++)
- memcpy(framebuffer+(j*w)+(i%3)*tw, d+(j*w)+(i%3)*tw, (i%3==2) ? twr*4 : tw*4);
- }
- }
- }
- break;
- case 7: // Left/Right to Right/Left
- {
- int i = (int)(sintrans*w);
- int j;
- for (j=0;j<h/2;j++)
- {
- memcpy(framebuffer+(i+j*w), p+(j*w), (w-i)*4);
- memcpy(framebuffer+(j*w), d+((j+1)*w)-i, i*4);
- }
- for (j=h/2;j<h;j++)
- {
- memcpy(framebuffer+(j*w), p+(i+j*w), (w-i)*4);
- memcpy(framebuffer+(j*w)+(w-i), d+(j*w), i*4);
- }
- }
- break;
- case 8: // Left/Right to Center
- {
- int i = (int)(sintrans*w/2);
- int j;
- for (j=0;j<h;j++)
- {
- memcpy(framebuffer+(j*w), d+((j+1)*w-i-w/2), i*4);
- memcpy(framebuffer+((j+1)*w-i), d+(j*w+w/2), i*4);
- memcpy(framebuffer+(j*w)+i, p+(j*w)+i, (w-i*2)*4);
- }
- }
- break;
- case 9: // Left/Right to Center, squeeze
- {
- int i = (int)(sintrans*w/2);
- int j;
- for (j=0;j<h;j++)
- {
- if (i)
- {
- int xl=i;
- int xp=0;
- int dxp=((w/2)<<16)/xl;
- int *ot=framebuffer+(j*w);
- int *it=d+(j*w);
- while (xl--)
- {
- *ot++=it[xp>>16];
- xp+=dxp;
- }
- }
- if (i*2 != w)
- {
- int xl=w-i*2;
- int xp=0;
- int dxp=(w<<16)/xl;
- int *ot=framebuffer+(j*w)+i;
- int *it=p+(j*w);
- while (xl--)
- {
- *ot++=it[xp>>16];
- xp+=dxp;
- }
- }
- if (i)
- {
- int xl=i;
- int xp=0;
- int dxp=((w/2)<<16)/xl;
- int *ot=framebuffer+(j*w)+w-i;
- int *it=d+(j*w)+w/2;
- while (xl--)
- {
- *ot++=it[xp>>16];
- xp+=dxp;
- }
- }
- }
- }
- break;
- case 10: // Left to right wipe
- {
- int i = (int)(sintrans*w);
- int j;
- for (j=0;j<h;j++)
- {
- memcpy(framebuffer+(i+j*w), p+(j*w)+i, (w-i)*4);
- memcpy(framebuffer+(j*w), d+(j*w), i*4);
- }
- }
- break;
- case 11: // Right to left wipe
- {
- int i = (int)(sintrans*w);
- int j;
- for (j=0;j<h;j++)
- {
- memcpy(framebuffer+(j*w), p+(j*w), (w-i)*4);
- memcpy(framebuffer+(j*w)+(w-i), d+(j*w)+(w-i), i*4);
- }
- }
- break;
- case 12: // Top to bottom wipe
- {
- int i = (int)(sintrans*h);
- memcpy(framebuffer, d, w*i*4);
- memcpy(framebuffer+w*i, p+w*i, w*(h-i)*4);
- }
- break;
- case 13: // Bottom to top wipe
- {
- int i = (int)(sintrans*h);
- memcpy(framebuffer, p, w*(h-i)*4);
- memcpy(framebuffer+w*(h-i), d+w*(h-i), w*i*4);
- }
- break;
- case 14: // dot dissolve
- {
- int i=((int)(sintrans*5))-5;
- int j;
- int t=0;
- int dir=1;
-
- if (i < 0)
- {
- dir=!dir;
- i++;
- i=-i;
- }
- i=1<<i;
- for (j = 0; j < h; j ++)
- {
- if (t++==i)
- {
- int x=w;
- t=0;
- int t2=0;
- int *of=framebuffer+j*w;
- int *p2=(dir?p:d)+j*w;
- int *d2=(dir?d:p)+j*w;
- while (x--)
- {
- if (t2++==i)
- {
- of[0]=p2[0];
- t2=0;
- }
- else of[0]=d2[0];
- p2++;
- d2++;
- of++;
- }
- }
- else
- memcpy(framebuffer+j*w,(dir?d:p)+j*w,w*sizeof(int));
- }
- }
- break;
- default:
- break;
- }
- if (n == 255)
- {
- int x;
- enabled=0;
- start_time=0;
- for (x = 0; x < 4; x ++)
- {
- if (fbs[x]) GlobalFree(fbs[x]);
- fbs[x]=NULL;
- }
- g_render_effects2->clearRenders();
- g_render_effects2->freeBuffers();
- }
- return 0;
- }
- BOOL CALLBACK C_RenderTransitionClass::g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
- {
- switch (uMsg)
- {
- case WM_INITDIALOG:
- {
- int x;
- for (x = 0; x < sizeof(transitionmodes)/sizeof(transitionmodes[0]); x ++)
- SendDlgItemMessage(hwndDlg,IDC_TRANSITION,CB_ADDSTRING,0,(LPARAM)WASABI_API_LNGSTRING(transitionmodes[x]));
- SendDlgItemMessage(hwndDlg,IDC_TRANSITION,CB_SETCURSEL,(WPARAM)cfg_transition_mode&0x7fff,0);
- SendDlgItemMessage(hwndDlg, IDC_SPEED, TBM_SETRANGE, TRUE, MAKELONG(1, 32));
- SendDlgItemMessage(hwndDlg, IDC_SPEED, TBM_SETPOS, TRUE, cfg_transitions_speed);
- if (cfg_transition_mode&0x8000) CheckDlgButton(hwndDlg,IDC_CHECK9,BST_CHECKED);
- if (cfg_transitions&1) CheckDlgButton(hwndDlg,IDC_CHECK2,BST_CHECKED);
- if (cfg_transitions&2) CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
- if (cfg_transitions&4) CheckDlgButton(hwndDlg,IDC_CHECK8,BST_CHECKED);
- if (cfg_transitions2&1) CheckDlgButton(hwndDlg,IDC_CHECK10,BST_CHECKED);
- if (cfg_transitions2&2) CheckDlgButton(hwndDlg,IDC_CHECK11,BST_CHECKED);
- if (cfg_transitions2&4) CheckDlgButton(hwndDlg,IDC_CHECK3,BST_CHECKED);
- if (cfg_transitions2&32) CheckDlgButton(hwndDlg,IDC_CHECK4,BST_CHECKED);
- if (!(cfg_transitions2&128)) CheckDlgButton(hwndDlg,IDC_CHECK5,BST_CHECKED);
- }
- return 1;
- case WM_COMMAND:
- switch (LOWORD(wParam))
- {
- case IDC_TRANSITION:
- if (HIWORD(wParam) == CBN_SELCHANGE)
- {
- int r=SendDlgItemMessage(hwndDlg,IDC_TRANSITION,CB_GETCURSEL,0,0);
- if (r!=CB_ERR)
- {
- cfg_transition_mode&=~0x7fff;
- cfg_transition_mode |= r;
- }
- }
- break;
- case IDC_CHECK9:
- cfg_transition_mode&=0x7fff;
- cfg_transition_mode |= IsDlgButtonChecked(hwndDlg,IDC_CHECK9)?0x8000:0;
- break;
- case IDC_CHECK2:
- cfg_transitions &= ~1;
- cfg_transitions |= IsDlgButtonChecked(hwndDlg,IDC_CHECK2)?1:0;
- break;
- case IDC_CHECK1:
- cfg_transitions &= ~2;
- cfg_transitions |= IsDlgButtonChecked(hwndDlg,IDC_CHECK1)?2:0;
- break;
- case IDC_CHECK8:
- cfg_transitions &= ~4;
- cfg_transitions |= IsDlgButtonChecked(hwndDlg,IDC_CHECK8)?4:0;
- break;
- case IDC_CHECK10:
- cfg_transitions2 &= ~1;
- cfg_transitions2 |= IsDlgButtonChecked(hwndDlg,IDC_CHECK10)?1:0;
- break;
- case IDC_CHECK11:
- cfg_transitions2 &= ~2;
- cfg_transitions2 |= IsDlgButtonChecked(hwndDlg,IDC_CHECK11)?2:0;
- break;
- case IDC_CHECK3:
- cfg_transitions2 &= ~4;
- cfg_transitions2 |= IsDlgButtonChecked(hwndDlg,IDC_CHECK3)?4:0;
- break;
- case IDC_CHECK4:
- cfg_transitions2 &= ~32;
- cfg_transitions2 |= IsDlgButtonChecked(hwndDlg,IDC_CHECK4)?32:0;
- break;
- case IDC_CHECK5:
- cfg_transitions2 &= ~128;
- cfg_transitions2 |= IsDlgButtonChecked(hwndDlg,IDC_CHECK5)?0:128;
- break;
- }
- break;
- case WM_NOTIFY:
- if (LOWORD(wParam) == IDC_SPEED)
- cfg_transitions_speed = SendDlgItemMessage(hwndDlg, IDC_SPEED, TBM_GETPOS, 0, 0);
- break;
- }
- return 0;
- }
- HWND C_RenderTransitionClass::conf(HINSTANCE hInstance, HWND hwndParent)
- {
- g_this = this;
- return WASABI_API_CREATEDIALOG(IDD_GCFG_TRANSITIONS,hwndParent,g_DlgProc);
- }
|