1
0

r_fadeout.cpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. LICENSE
  3. -------
  4. Copyright 2005 Nullsoft, Inc.
  5. All rights reserved.
  6. Redistribution and use in source and binary forms, with or without modification,
  7. are permitted provided that the following conditions are met:
  8. * Redistributions of source code must retain the above copyright notice,
  9. this list of conditions and the following disclaimer.
  10. * Redistributions in binary form must reproduce the above copyright notice,
  11. this list of conditions and the following disclaimer in the documentation
  12. and/or other materials provided with the distribution.
  13. * Neither the name of Nullsoft nor the names of its contributors may be used to
  14. endorse or promote products derived from this software without specific prior written permission.
  15. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
  16. IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
  17. FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  18. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  20. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
  21. IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  22. OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  23. */
  24. // alphachannel safe 11/21/99
  25. #include <windows.h>
  26. #include <commctrl.h>
  27. #include "r_defs.h"
  28. #include "resource.h"
  29. #include "timing.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #define C_THISCLASS C_FadeOutClass
  33. #define MOD_NAME "Trans / Fadeout"
  34. class C_THISCLASS : public C_RBASE {
  35. protected:
  36. public:
  37. C_THISCLASS();
  38. virtual ~C_THISCLASS();
  39. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  40. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_FADEOUT,desc,128):desc); }
  41. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  42. virtual void load_config(unsigned char *data, int len);
  43. virtual int save_config(unsigned char *data);
  44. void maketab(void);
  45. unsigned char fadtab[3][256];
  46. int fadelen, color;
  47. };
  48. void C_THISCLASS::maketab(void)
  49. {
  50. int rseek=color&0xff;
  51. int gseek=(color>>8)&0xff;
  52. int bseek=(color>>16)&0xff;
  53. int x;
  54. for (x = 0; x < 256; x ++)
  55. {
  56. int r=x;
  57. int g=x;
  58. int b=x;
  59. if (r <= rseek-fadelen) r+=fadelen;
  60. else if (r >= rseek+fadelen) r-=fadelen;
  61. else r=rseek;
  62. if (g <= gseek-fadelen) g+=fadelen;
  63. else if (g >= gseek+fadelen) g-=fadelen;
  64. else g=gseek;
  65. if (b <= bseek-fadelen) b+=fadelen;
  66. else if (b >= bseek+fadelen) b-=fadelen;
  67. else b=bseek;
  68. fadtab[0][x]=r;
  69. fadtab[1][x]=g;
  70. fadtab[2][x]=b;
  71. }
  72. }
  73. #define PUT_INT(y) data[pos]=(y)&255; data[pos+1]=(y>>8)&255; data[pos+2]=(y>>16)&255; data[pos+3]=(y>>24)&255
  74. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  75. void C_THISCLASS::load_config(unsigned char *data, int len)
  76. {
  77. int pos=0;
  78. if (len-pos >= 4) { fadelen=GET_INT(); pos+=4; }
  79. if (len-pos >= 4) { color=GET_INT(); pos+=4; }
  80. maketab();
  81. }
  82. int C_THISCLASS::save_config(unsigned char *data)
  83. {
  84. int pos=0;
  85. PUT_INT(fadelen); pos+=4;
  86. PUT_INT(color); pos+=4;
  87. return pos;
  88. }
  89. C_THISCLASS::C_THISCLASS()
  90. {
  91. color=0;
  92. fadelen=16;
  93. maketab();
  94. }
  95. C_THISCLASS::~C_THISCLASS()
  96. {
  97. }
  98. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  99. {
  100. if (isBeat&0x80000000) return 0;
  101. if (!fadelen) return 0;
  102. timingEnter(1);
  103. if (
  104. #ifdef NO_MMX
  105. 1
  106. #else
  107. color
  108. #endif
  109. )
  110. {
  111. unsigned char *t=(unsigned char *)framebuffer;
  112. int x=w*h;
  113. while (x--)
  114. {
  115. t[0]=fadtab[0][t[0]];
  116. t[1]=fadtab[1][t[1]];
  117. t[2]=fadtab[2][t[2]];
  118. t+=4;
  119. }
  120. }
  121. #ifndef NO_MMX
  122. else
  123. {
  124. int l=(w*h);
  125. char fadj[8];
  126. int x;
  127. unsigned char *t=fadtab[0];
  128. for (x = 0; x < 8; x ++) fadj[x]=this->fadelen;
  129. __asm
  130. {
  131. mov edx, l
  132. mov edi, framebuffer
  133. movq mm7, [fadj]
  134. shr edx, 3
  135. align 16
  136. _l1:
  137. movq mm0, [edi]
  138. movq mm1, [edi+8]
  139. movq mm2, [edi+16]
  140. psubusb mm0, mm7
  141. movq mm3, [edi+24]
  142. psubusb mm1, mm7
  143. movq [edi], mm0
  144. psubusb mm2, mm7
  145. movq [edi+8], mm1
  146. psubusb mm3, mm7
  147. movq [edi+16], mm2
  148. movq [edi+24], mm3
  149. add edi, 8*4
  150. dec edx
  151. jnz _l1
  152. mov edx, l
  153. sub eax, eax
  154. and edx, 7
  155. jz _l3
  156. sub ebx, ebx
  157. sub ecx, ecx
  158. mov esi, t
  159. _l2:
  160. mov al, [edi]
  161. mov bl, [edi+1]
  162. mov cl, [edi+2]
  163. sub al, [esi+eax]
  164. sub bl, [esi+ebx]
  165. sub cl, [esi+ecx]
  166. mov [edi], al
  167. mov [edi+1], bl
  168. mov [edi+2], cl
  169. add edi, 4
  170. dec edx
  171. jnz _l2
  172. _l3:
  173. emms
  174. }
  175. }
  176. #endif
  177. timingLeave(1);
  178. return 0;
  179. }
  180. C_RBASE *R_FadeOut(char *desc)
  181. {
  182. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  183. return (C_RBASE *) new C_THISCLASS();
  184. }
  185. static C_THISCLASS *g_this;
  186. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  187. {
  188. int *a=NULL;
  189. switch (uMsg)
  190. {
  191. case WM_DRAWITEM:
  192. {
  193. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  194. switch (di->CtlID)
  195. {
  196. case IDC_LC:
  197. GR_DrawColoredButton(di,g_this->color);
  198. break;
  199. }
  200. }
  201. return 0;
  202. case WM_INITDIALOG:
  203. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  204. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,92);
  205. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->fadelen);
  206. return 1;
  207. case WM_HSCROLL:
  208. {
  209. HWND swnd = (HWND) lParam;
  210. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  211. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  212. {
  213. g_this->fadelen=t;
  214. g_this->maketab();
  215. }
  216. }
  217. case WM_COMMAND:
  218. switch (LOWORD(wParam))
  219. {
  220. case IDC_LC:
  221. GR_SelectColor(hwndDlg,&g_this->color);
  222. InvalidateRect(GetDlgItem(hwndDlg,LOWORD(wParam)),NULL,FALSE);
  223. g_this->maketab();
  224. return 0;
  225. }
  226. return 0;
  227. }
  228. return 0;
  229. }
  230. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  231. {
  232. g_this = this;
  233. return WASABI_API_CREATEDIALOG(IDD_CFG_FADE,hwndParent,g_DlgProc);
  234. }
  235. #else
  236. C_RBASE *R_FadeOut(char *desc) { return NULL; }
  237. #endif