1
0

r_fastbright.cpp 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. #include <windows.h>
  25. #include <commctrl.h>
  26. #include "r_defs.h"
  27. #include "resource.h"
  28. #include "timing.h"
  29. #include "../Agave/Language/api_language.h"
  30. #ifndef LASER
  31. #define C_THISCLASS C_FastBright
  32. #define MOD_NAME "Trans / Fast Brightness"
  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_TRANS_FAST_BRIGHTNESS,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. #ifdef NO_MMX
  44. int tab[3][256];
  45. #endif
  46. int dir;
  47. };
  48. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  49. void C_THISCLASS::load_config(unsigned char *data, int len) // read configuration of max length "len" from data.
  50. {
  51. int pos=0;
  52. dir=0;
  53. if (len-pos >= 4) { dir=GET_INT(); pos+=4; }
  54. }
  55. #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
  56. int C_THISCLASS::save_config(unsigned char *data) // write configuration to data, return length. config data should not exceed 64k.
  57. {
  58. int pos=0;
  59. PUT_INT(dir); pos+=4;
  60. return pos;
  61. }
  62. C_THISCLASS::C_THISCLASS()
  63. {
  64. #ifdef NO_MMX
  65. int x;
  66. for (x = 0; x < 128; x ++)
  67. {
  68. tab[0][x]=x+x;
  69. tab[1][x]=x<<9;
  70. tab[2][x]=x<<17;
  71. }
  72. for (; x < 256; x ++)
  73. {
  74. tab[0][x]=255;
  75. tab[1][x]=255<<8;
  76. tab[2][x]=255<<16;
  77. }
  78. #endif
  79. dir=0;
  80. }
  81. C_THISCLASS::~C_THISCLASS()
  82. {
  83. }
  84. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  85. {
  86. if (isBeat&0x80000000) return 0;
  87. #ifdef NO_MMX // the non mmx x2 version really isn't any , in terms faster than normal brightness with no exclusions turned on
  88. {
  89. unsigned int *t=(unsigned int *)framebuffer;
  90. int x;
  91. unsigned int mask = 0x7F7F7F7F;
  92. x=w*h/2;
  93. if (dir == 0)
  94. while (x--)
  95. {
  96. unsigned int v1=t[0];
  97. unsigned int v2=t[1];
  98. v1=tab[0][v1&0xff]|tab[1][(v1>>8)&0xff]|tab[2][(v1>>16)&0xff]|(v1&0xff000000);
  99. v2=tab[0][v2&0xff]|tab[1][(v2>>8)&0xff]|tab[2][(v2>>16)&0xff]|(v2&0xff000000);
  100. t[0]=v1;
  101. t[1]=v2;
  102. t+=2;
  103. }
  104. else if (dir == 1)
  105. while (x--)
  106. {
  107. unsigned int v1=t[0]>>1;
  108. unsigned int v2=t[1]>>1;
  109. t[0]=v1&mask;
  110. t[1]=v2&mask;
  111. t+=2;
  112. }
  113. }
  114. #else
  115. int mask[2] =
  116. {
  117. 0x7F7F7F7F,
  118. 0x7F7F7F7F,
  119. };
  120. int l=(w*h);
  121. if (dir == 0) __asm
  122. {
  123. mov edx, l
  124. mov edi, framebuffer
  125. shr edx, 3 // 8 pixels at a time
  126. align 16
  127. _l1:
  128. movq mm0, [edi]
  129. movq mm1, [edi+8]
  130. movq mm2, [edi+16]
  131. paddusb mm0, mm0
  132. movq mm3, [edi+24]
  133. paddusb mm1, mm1
  134. paddusb mm2, mm2
  135. movq [edi], mm0
  136. paddusb mm3, mm3
  137. movq [edi+8], mm1
  138. movq [edi+16], mm2
  139. movq [edi+24], mm3
  140. add edi, 32
  141. dec edx
  142. jnz _l1
  143. mov edx, l
  144. and edx, 7
  145. shr edx, 1 // up the last 7 pixels (two at a time)
  146. jz _l3
  147. _l2:
  148. movq mm3, [edi]
  149. paddusb mm3, mm3
  150. movq [edi], mm3
  151. add edi, 8
  152. dec edx
  153. jnz _l2
  154. _l3:
  155. emms
  156. }
  157. else if (dir == 1) __asm
  158. {
  159. mov edx, l
  160. movq mm7, [mask]
  161. mov edi, framebuffer
  162. shr edx, 3 // 8 pixels at a time
  163. align 16
  164. _lr1:
  165. movq mm0, [edi]
  166. movq mm1, [edi+8]
  167. movq mm2, [edi+16]
  168. psrl mm0, 1
  169. movq mm3, [edi+24]
  170. pand mm0, mm7
  171. psrl mm1, 1
  172. movq [edi], mm0
  173. psrl mm2, 1
  174. pand mm1, mm7
  175. movq [edi+8], mm1
  176. pand mm2, mm7
  177. psrl mm3, 1
  178. movq [edi+16], mm2
  179. pand mm3, mm7
  180. movq [edi+24], mm3
  181. add edi, 32
  182. dec edx
  183. jnz _lr1
  184. mov edx, l
  185. and edx, 7
  186. shr edx, 1 // up the last 7 pixels (two at a time)
  187. jz _lr3
  188. _lr2:
  189. movq mm3, [edi]
  190. psrl mm3, 1
  191. pand mm3, mm7
  192. movq [edi], mm3
  193. add edi, 8
  194. dec edx
  195. jnz _lr2
  196. _lr3:
  197. emms
  198. }
  199. #endif
  200. return 0;
  201. }
  202. C_RBASE *R_FastBright(char *desc)
  203. {
  204. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  205. return (C_RBASE *) new C_THISCLASS();
  206. }
  207. static C_THISCLASS *g_this;
  208. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  209. {
  210. switch (uMsg)
  211. {
  212. case WM_INITDIALOG:
  213. if (g_this->dir==0) CheckDlgButton(hwndDlg,IDC_RADIO1,BST_CHECKED);
  214. else if (g_this->dir == 1) CheckDlgButton(hwndDlg,IDC_RADIO2,BST_CHECKED);
  215. else CheckDlgButton(hwndDlg,IDC_RADIO3,BST_CHECKED);
  216. return 1;
  217. case WM_COMMAND:
  218. if (LOWORD(wParam) == IDC_RADIO1)
  219. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO1))
  220. g_this->dir=0;
  221. if (LOWORD(wParam) == IDC_RADIO2)
  222. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO2))
  223. g_this->dir=1;
  224. if (LOWORD(wParam) == IDC_RADIO3)
  225. if (IsDlgButtonChecked(hwndDlg,IDC_RADIO3))
  226. g_this->dir=2;
  227. return 0;
  228. }
  229. return 0;
  230. }
  231. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  232. {
  233. g_this = this;
  234. return WASABI_API_CREATEDIALOG(IDD_CFG_FASTBRIGHT,hwndParent,g_DlgProc);
  235. }
  236. #else
  237. C_RBASE *R_FastBright(char *desc) { return NULL; }
  238. #endif