1
0

r_nfclr.cpp 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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 "../Agave/Language/api_language.h"
  30. #ifndef LASER
  31. #define C_THISCLASS C_NFClearClass
  32. #define MOD_NAME "Render / OnBeat Clear"
  33. class C_THISCLASS : public C_RBASE {
  34. protected:
  35. public:
  36. C_THISCLASS();
  37. virtual ~C_THISCLASS();
  38. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  39. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_ONBEAT_CLEAR,desc,128):desc); }
  40. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  41. virtual void load_config(unsigned char *data, int len);
  42. virtual int save_config(unsigned char *data);
  43. int nf,cf,df;
  44. int color, blend;
  45. };
  46. #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
  47. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  48. void C_THISCLASS::load_config(unsigned char *data, int len)
  49. {
  50. int pos=0;
  51. if (len-pos >= 4) { color=GET_INT(); pos+=4; }
  52. if (len-pos >= 4) { blend=GET_INT(); pos+=4; }
  53. if (len-pos >= 4) { nf=GET_INT(); pos+=4; }
  54. }
  55. int C_THISCLASS::save_config(unsigned char *data)
  56. {
  57. int pos=0;
  58. PUT_INT(color); pos+=4;
  59. PUT_INT(blend); pos+=4;
  60. PUT_INT(nf); pos+=4;
  61. return pos;
  62. }
  63. C_THISCLASS::C_THISCLASS()
  64. {
  65. cf=0;
  66. nf=1;
  67. df=0;
  68. color=RGB(255,255,255);
  69. blend=0;
  70. }
  71. C_THISCLASS::~C_THISCLASS()
  72. {
  73. }
  74. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  75. {
  76. int p=0;
  77. char *t=(char *)&visdata[1][0][0];
  78. int np=0;
  79. if (isBeat&0x80000000) return 0;
  80. if (isBeat)
  81. {
  82. if (nf && ++cf >= nf)
  83. {
  84. cf=df=0;
  85. int i=w*h;
  86. int c=color;
  87. if (!blend) __asm
  88. {
  89. mov ecx, i
  90. mov edi, framebuffer
  91. mov eax, c
  92. rep stosd
  93. }
  94. else
  95. {
  96. #ifdef NO_MMX
  97. while (i--)
  98. {
  99. *framebuffer=BLEND_AVG(*framebuffer,color);
  100. framebuffer++;
  101. }
  102. #else
  103. {
  104. int icolor[2]={this->color,this->color};
  105. int vc[2] = { ~((1<<7)|(1<<15)|(1<<23)),~((1<<7)|(1<<15)|(1<<23))};
  106. i/=4;
  107. __asm
  108. {
  109. movq mm6, vc
  110. movq mm7, icolor
  111. psrlq mm7, 1
  112. pand mm7, mm6
  113. mov edx, i
  114. mov edi, framebuffer
  115. _l1:
  116. movq mm0, [edi]
  117. movq mm1, [edi+8]
  118. psrlq mm0, 1
  119. pand mm0, mm6
  120. psrlq mm1, 1
  121. paddb mm0, mm7
  122. pand mm1, mm6
  123. movq [edi], mm0
  124. paddb mm1, mm7
  125. movq [edi+8], mm1
  126. add edi, 16
  127. dec edx
  128. jnz _l1
  129. emms
  130. }
  131. }
  132. #endif
  133. }
  134. }
  135. }
  136. else if (++df >= nf)
  137. {
  138. df=0;
  139. // memset(framebuffer,0,w*h*4);
  140. }
  141. return 0;
  142. }
  143. C_RBASE *R_NFClear(char *desc)
  144. {
  145. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  146. return (C_RBASE *) new C_THISCLASS();
  147. }
  148. static C_THISCLASS *g_this;
  149. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  150. {
  151. int *a=NULL;
  152. switch (uMsg)
  153. {
  154. case WM_DRAWITEM:
  155. {
  156. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  157. switch (di->CtlID)
  158. {
  159. case IDC_BUTTON1:
  160. GR_DrawColoredButton(di,g_this->color);
  161. break;
  162. }
  163. }
  164. return 0;
  165. case WM_INITDIALOG:
  166. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  167. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,100);
  168. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->nf);
  169. if (g_this->blend) CheckDlgButton(hwndDlg,IDC_BLEND,BST_CHECKED);
  170. return 1;
  171. case WM_HSCROLL:
  172. {
  173. HWND swnd = (HWND) lParam;
  174. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  175. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  176. {
  177. g_this->nf=t;
  178. }
  179. }
  180. return 0;
  181. case WM_COMMAND:
  182. if (LOWORD(wParam) == IDC_BUTTON1)
  183. {
  184. GR_SelectColor(hwndDlg,&g_this->color);
  185. InvalidateRect(GetDlgItem(hwndDlg,LOWORD(wParam)),NULL,FALSE);
  186. }
  187. if (LOWORD(wParam) == IDC_BLEND)
  188. {
  189. if (IsDlgButtonChecked(hwndDlg,IDC_BLEND))
  190. g_this->blend=1;
  191. else g_this->blend=0;
  192. }
  193. }
  194. return 0;
  195. }
  196. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  197. {
  198. g_this = this;
  199. return WASABI_API_CREATEDIALOG(IDD_CFG_NFC,hwndParent,g_DlgProc);
  200. }
  201. #else
  202. C_RBASE *R_NFClear(char *desc) { return NULL; }
  203. #endif