r_chanshift.cpp 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 <time.h>
  27. #include "resource.h"
  28. #include "r_defs.h"
  29. #include "../Agave/Language/api_language.h"
  30. #ifndef LASER
  31. // this will be the directory and APE name displayed in the AVS Editor
  32. #define MOD_NAME "Trans / Channel Shift"
  33. #define C_THISCLASS C_ChannelShiftClass
  34. typedef struct {
  35. int mode;
  36. int onbeat;
  37. } apeconfig;
  38. class C_THISCLASS : public C_RBASE
  39. {
  40. protected:
  41. public:
  42. C_THISCLASS();
  43. virtual ~C_THISCLASS();
  44. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  45. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  46. virtual char *get_desc();
  47. virtual void load_config(unsigned char *data, int len);
  48. virtual int save_config(unsigned char *data);
  49. apeconfig config;
  50. HWND hwndDlg;
  51. };
  52. // global configuration dialog pointer
  53. static C_THISCLASS *g_ConfigThis;
  54. static HINSTANCE g_hDllInstance;
  55. // this is where we deal with the configuration screen
  56. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  57. {
  58. int ids[] = { IDC_RBG, IDC_BRG, IDC_BGR, IDC_GBR, IDC_GRB, IDC_RGB };
  59. switch (uMsg)
  60. {
  61. case WM_COMMAND:
  62. if (HIWORD(wParam) == BN_CLICKED) {
  63. for (int i=0;i<sizeof(ids)/sizeof(ids[0]);i++)
  64. if (IsDlgButtonChecked(hwndDlg, ids[i]))
  65. g_ConfigThis->config.mode = ids[i];
  66. g_ConfigThis->config.onbeat = IsDlgButtonChecked(hwndDlg, IDC_ONBEAT) ? 1 : 0;
  67. }
  68. return 1;
  69. case WM_INITDIALOG:
  70. g_ConfigThis->hwndDlg = hwndDlg;
  71. CheckDlgButton(hwndDlg, g_ConfigThis->config.mode, 1);
  72. if (g_ConfigThis->config.onbeat)
  73. CheckDlgButton(hwndDlg, IDC_ONBEAT, 1);
  74. return 1;
  75. case WM_DESTROY:
  76. KillTimer(hwndDlg, 1);
  77. return 1;
  78. }
  79. return 0;
  80. }
  81. // set up default configuration
  82. C_THISCLASS::C_THISCLASS()
  83. {
  84. memset(&config, 0, sizeof(apeconfig));
  85. config.mode = IDC_RBG;
  86. config.onbeat = 1;
  87. }
  88. // virtual destructor
  89. C_THISCLASS::~C_THISCLASS()
  90. {
  91. }
  92. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  93. {
  94. if (isBeat&0x80000000) return 0;
  95. int c;
  96. int modes[] = { IDC_RGB, IDC_RBG, IDC_GBR, IDC_GRB, IDC_BRG, IDC_BGR };
  97. if (isBeat && config.onbeat) {
  98. config.mode = modes[rand() % 6];
  99. }
  100. c = w*h;
  101. switch (config.mode) {
  102. default:
  103. case IDC_RGB:
  104. return 0;
  105. case IDC_RBG:
  106. __asm {
  107. mov ebx, framebuffer;
  108. mov ecx, c;
  109. lp1:
  110. sub ecx, 4;
  111. mov eax, dword ptr [ebx+ecx*4];
  112. xchg ah, al;
  113. mov [ebx+ecx*4], eax;
  114. mov eax, dword ptr [ebx+ecx*4+4];
  115. xchg ah, al;
  116. mov [ebx+ecx*4+4], eax;
  117. mov eax, dword ptr [ebx+ecx*4+8];
  118. xchg ah, al;
  119. mov [ebx+ecx*4+8], eax;
  120. mov eax, dword ptr [ebx+ecx*4+12];
  121. xchg ah, al;
  122. mov [ebx+ecx*4+12], eax;
  123. test ecx, ecx;
  124. jnz lp1;
  125. }
  126. break;
  127. case IDC_BRG:
  128. __asm {
  129. mov ebx, framebuffer;
  130. mov ecx, c;
  131. lp2:
  132. sub ecx, 4;
  133. mov eax, dword ptr [ebx+ecx*4];
  134. mov dl, al;
  135. shr eax, 8;
  136. bswap eax;
  137. mov ah, dl;
  138. bswap eax;
  139. mov [ebx+ecx*4], eax;
  140. mov eax, dword ptr [ebx+ecx*4+4];
  141. mov dl, al;
  142. shr eax, 8;
  143. bswap eax;
  144. mov ah, dl;
  145. bswap eax;
  146. mov [ebx+ecx*4+4], eax;
  147. mov eax, dword ptr [ebx+ecx*4+8];
  148. mov dl, al;
  149. shr eax, 8;
  150. bswap eax;
  151. mov ah, dl;
  152. bswap eax;
  153. mov [ebx+ecx*4+8], eax;
  154. mov eax, dword ptr [ebx+ecx*4+12];
  155. mov dl, al;
  156. shr eax, 8;
  157. bswap eax;
  158. mov ah, dl;
  159. bswap eax;
  160. mov [ebx+ecx*4+12], eax;
  161. test ecx, ecx;
  162. jnz lp2;
  163. }
  164. break;
  165. case IDC_BGR:
  166. __asm {
  167. mov ebx, framebuffer;
  168. mov ecx, c;
  169. lp3:
  170. sub ecx, 4;
  171. mov eax, dword ptr [ebx+ecx*4];
  172. bswap eax;
  173. shr eax, 8;
  174. mov [ebx+ecx*4], eax;
  175. mov eax, dword ptr [ebx+ecx*4+4];
  176. bswap eax;
  177. shr eax, 8;
  178. mov [ebx+ecx*4+4], eax;
  179. mov eax, dword ptr [ebx+ecx*4+8];
  180. bswap eax;
  181. shr eax, 8;
  182. mov [ebx+ecx*4+8], eax;
  183. mov eax, dword ptr [ebx+ecx*4+12];
  184. bswap eax;
  185. shr eax, 8;
  186. mov [ebx+ecx*4+12], eax;
  187. test ecx, ecx;
  188. jnz lp3;
  189. }
  190. break;
  191. case IDC_GBR:
  192. __asm {
  193. mov ebx, framebuffer;
  194. mov ecx, c;
  195. lp4:
  196. sub ecx, 4;
  197. mov eax, dword ptr [ebx+ecx*4];
  198. mov edx, eax;
  199. bswap edx;
  200. shl eax, 8;
  201. mov al, dh;
  202. mov [ebx+ecx*4], eax;
  203. mov eax, dword ptr [ebx+ecx*4+4];
  204. mov edx, eax;
  205. bswap edx;
  206. shl eax, 8;
  207. mov al, dh;
  208. mov [ebx+ecx*4+4], eax;
  209. mov eax, dword ptr [ebx+ecx*4+8];
  210. mov edx, eax;
  211. bswap edx;
  212. shl eax, 8;
  213. mov al, dh;
  214. mov [ebx+ecx*4+8], eax;
  215. mov eax, dword ptr [ebx+ecx*4+12];
  216. mov edx, eax;
  217. bswap edx;
  218. shl eax, 8;
  219. mov al, dh;
  220. mov [ebx+ecx*4+12], eax;
  221. test ecx, ecx;
  222. jnz lp4;
  223. }
  224. break;
  225. case IDC_GRB:
  226. __asm {
  227. mov ebx, framebuffer;
  228. mov ecx, c;
  229. lp5:
  230. sub ecx, 4;
  231. mov eax, dword ptr [ebx+ecx*4];
  232. shl eax, 8;
  233. bswap eax;
  234. xchg ah, al;
  235. bswap eax;
  236. shr eax, 8;
  237. mov [ebx+ecx*4], eax;
  238. mov eax, dword ptr [ebx+ecx*4+4];
  239. shl eax, 8;
  240. bswap eax;
  241. xchg ah, al;
  242. bswap eax;
  243. shr eax, 8;
  244. mov [ebx+ecx*4+4], eax;
  245. mov eax, dword ptr [ebx+ecx*4+8];
  246. shl eax, 8;
  247. bswap eax;
  248. xchg ah, al;
  249. bswap eax;
  250. shr eax, 8;
  251. mov [ebx+ecx*4+8], eax;
  252. mov eax, dword ptr [ebx+ecx*4+12];
  253. shl eax, 8;
  254. bswap eax;
  255. xchg ah, al;
  256. bswap eax;
  257. shr eax, 8;
  258. mov [ebx+ecx*4+12], eax;
  259. test ecx, ecx;
  260. jnz lp5;
  261. }
  262. break;
  263. }
  264. return 0;
  265. }
  266. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  267. {
  268. g_ConfigThis = this;
  269. return WASABI_API_CREATEDIALOG(IDD_CFG_CHANSHIFT, hwndParent, (DLGPROC)g_DlgProc);
  270. }
  271. char *C_THISCLASS::get_desc(void)
  272. {
  273. static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_CHANNEL_SHIFT,desc,128):desc);
  274. }
  275. void C_THISCLASS::load_config(unsigned char *data, int len)
  276. {
  277. srand((unsigned int)time(0));
  278. if (len <= sizeof(apeconfig))
  279. memcpy(&this->config, data, len);
  280. }
  281. int C_THISCLASS::save_config(unsigned char *data)
  282. {
  283. memcpy(data, &this->config, sizeof(apeconfig));
  284. return sizeof(apeconfig);
  285. }
  286. C_RBASE *R_ChannelShift(char *desc)
  287. {
  288. if (desc) {
  289. strcpy(desc,MOD_NAME);
  290. return NULL;
  291. }
  292. return (C_RBASE *) new C_THISCLASS();
  293. }
  294. #endif