1
0

r_simple.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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 "r_defs.h"
  27. #include "resource.h"
  28. #include "../Agave/Language/api_language.h"
  29. #ifndef LASER
  30. #define C_THISCLASS C_SimpleClass
  31. #define MOD_NAME "Render / Simple"
  32. class C_THISCLASS : public C_RBASE {
  33. protected:
  34. public:
  35. C_THISCLASS();
  36. virtual ~C_THISCLASS();
  37. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  38. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_RENDER_SIMPLE,desc,128):desc); }
  39. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  40. virtual void load_config(unsigned char *data, int len);
  41. virtual int save_config(unsigned char *data);
  42. int effect;
  43. int num_colors;
  44. int colors[16];
  45. int color_pos;
  46. };
  47. #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
  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)
  50. {
  51. int pos=0;
  52. int x=0;
  53. if (len-pos >= 4) { effect=GET_INT(); pos+=4; }
  54. if (len-pos >= 4) { num_colors=GET_INT(); pos+=4; }
  55. if (num_colors <= 16) while (len-pos >= 4 && x < num_colors) { colors[x++]=GET_INT(); pos+=4; }
  56. else num_colors=0;
  57. }
  58. int C_THISCLASS::save_config(unsigned char *data)
  59. {
  60. int pos=0,x=0;
  61. PUT_INT(effect); pos+=4;
  62. PUT_INT(num_colors); pos+=4;
  63. while (x < num_colors) { PUT_INT(colors[x]); x++; pos+=4; }
  64. return pos;
  65. }
  66. C_THISCLASS::C_THISCLASS()
  67. {
  68. effect=0|(2<<2)|(2<<4);
  69. num_colors=1;
  70. memset(colors,0,sizeof(colors));
  71. colors[0]=RGB(255,255,255);
  72. color_pos=0;
  73. }
  74. C_THISCLASS::~C_THISCLASS()
  75. {
  76. }
  77. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  78. {
  79. if (!num_colors) return 0;
  80. if (isBeat&0x80000000) return 0;
  81. int x;
  82. float yscale = (float) h / 2.0f / 256.0f;
  83. float xscale = 288.0f/w;
  84. int current_color;
  85. unsigned char *fa_data;
  86. char center_channel[576];
  87. int which_ch=(effect>>2)&3;
  88. int y_pos=(effect>>4)&3;
  89. color_pos++;
  90. if (color_pos >= num_colors * 64) color_pos=0;
  91. {
  92. int p=color_pos/64;
  93. int r=color_pos&63;
  94. int c1,c2;
  95. int r1,r2,r3;
  96. c1=colors[p];
  97. if (p+1 < num_colors)
  98. c2=colors[p+1];
  99. else c2=colors[0];
  100. r1=(((c1&255)*(63-r))+((c2&255)*r))/64;
  101. r2=((((c1>>8)&255)*(63-r))+(((c2>>8)&255)*r))/64;
  102. r3=((((c1>>16)&255)*(63-r))+(((c2>>16)&255)*r))/64;
  103. current_color=r1|(r2<<8)|(r3<<16);
  104. }
  105. if (which_ch>=2)
  106. {
  107. int w=0;
  108. if ((effect&3)>1)
  109. w=1;
  110. for (x = 0; x < 576; x ++) center_channel[x]=visdata[w][0][x]/2+visdata[w][1][x]/2;
  111. }
  112. if (which_ch < 2) fa_data=(unsigned char *)&visdata[(effect&3)>1?1:0][which_ch][0];
  113. else fa_data=(unsigned char *)center_channel;
  114. if (effect&(1<<6))
  115. {
  116. switch (effect&2)
  117. {
  118. case 2: // dot scope
  119. {
  120. int yh = y_pos*h / 2;
  121. if (y_pos==2) yh=h/4;
  122. int ys = yh+(int)(yscale*128.0f);
  123. for (x = 0; x < w; x ++)
  124. {
  125. float r=x*xscale;
  126. float s1=r-(int)r;
  127. float yr=(fa_data[(int)r]^128)*(1.0f-s1)+(fa_data[(int)r+1]^128)*(s1);
  128. int y=yh + (int) (yr*yscale);
  129. if (y >= 0 && y < h) framebuffer[x+y*w]=current_color;
  130. }
  131. }
  132. break;
  133. case 0: // dot analyzer
  134. {
  135. int h2=h/2;
  136. float ys=yscale;
  137. float xs=200.0f/w;
  138. int adj=1;
  139. if (y_pos!=1) { ys=-ys; adj=0; }
  140. if (y_pos==2)
  141. {
  142. h2 -= (int) (ys*256/2);
  143. }
  144. for (x = 0; x < w; x ++)
  145. {
  146. float r=x*xs;
  147. float s1=r-(int)r;
  148. float yr=fa_data[(int)r]*(1.0f-s1)+fa_data[(int)r+1]*(s1);
  149. int y=h2+adj+(int)(yr*ys-1.0f);
  150. if (y >= 0 && y < h) framebuffer[x+w*y]=current_color;
  151. }
  152. }
  153. break;
  154. }
  155. }
  156. else
  157. switch (effect&3)
  158. {
  159. case 0: //solid analyzer
  160. {
  161. int h2=h/2;
  162. float ys=yscale;
  163. float xs=200.0f/w;
  164. int adj=1;
  165. if (y_pos!=1) { ys=-ys; adj=0; }
  166. if (y_pos==2)
  167. {
  168. h2 -= (int) (ys*256/2);
  169. }
  170. for (x = 0; x < w; x ++)
  171. {
  172. float r=x*xs;
  173. float s1=r-(int)r;
  174. float yr=fa_data[(int)r]*(1.0f-s1)+fa_data[(int)r+1]*(s1);
  175. line(framebuffer,x,h2-adj,x,h2 + adj + (int) (yr*ys - 1.0f),w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  176. }
  177. }
  178. break;
  179. case 1: // line analyzer
  180. {
  181. int yh = 0;
  182. int h2=h/2;
  183. int lx,ly,ox,oy;
  184. float xs= 1.0f/xscale*(288.0f/200.f);
  185. float ys=yscale;
  186. if (y_pos!=1) { ys=-ys; }
  187. if (y_pos == 2)
  188. h2 -= (int) (ys*256/2);
  189. ly=h2 + (int) ((fa_data[0])*ys);
  190. lx=0;
  191. for (x = 1; x < 200; x ++)
  192. {
  193. oy=h2 + (int) ((fa_data[x])*ys);
  194. ox=(int) (x*xs);
  195. line(framebuffer,lx,ly,ox,oy,w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  196. ly=oy;
  197. lx=ox;
  198. }
  199. }
  200. break;
  201. case 2: // line scope
  202. {
  203. float xs = 1.0f/xscale;
  204. int lx, ly,ox,oy;
  205. int yh;
  206. if (y_pos == 2)
  207. yh = h/4;
  208. else yh = y_pos*h/ 2;
  209. lx=0;
  210. ly=yh + (int) ((int)(fa_data[0]^128)*yscale);;
  211. for (x = 1; x < 288; x ++)
  212. {
  213. ox=(int)(x*xs);
  214. oy = yh + (int) ((int)(fa_data[x]^128)*yscale);
  215. line(framebuffer, lx,ly,ox,oy,w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  216. lx=ox;
  217. ly=oy;
  218. }
  219. }
  220. break;
  221. case 3: // solid scope
  222. {
  223. int yh = y_pos*h / 2;
  224. if (y_pos==2) yh=h/4;
  225. int ys = yh+(int)(yscale*128.0f);
  226. for (x = 0; x < w; x ++)
  227. {
  228. float r=x*xscale;
  229. float s1=r-(int)r;
  230. float yr=(fa_data[(int)r]^128)*(1.0f-s1)+(fa_data[(int)r+1]^128)*(s1);
  231. line(framebuffer,x,ys-1,x,yh + (int) (yr*yscale),w,h,current_color,(g_line_blend_mode&0xff0000)>>16);
  232. }
  233. }
  234. break;
  235. }
  236. return 0;
  237. }
  238. C_RBASE *R_SimpleSpectrum(char *desc)
  239. {
  240. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  241. return (C_RBASE *) new C_THISCLASS();
  242. }
  243. static C_THISCLASS *g_this;
  244. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  245. {
  246. const static int chex[8]=
  247. {
  248. IDC_SA,IDC_SOLID,
  249. IDC_SA,IDC_LINES,
  250. IDC_OSC,IDC_LINES,
  251. IDC_OSC,IDC_SOLID,
  252. };
  253. int *a=NULL;
  254. switch (uMsg)
  255. {
  256. case WM_DRAWITEM:
  257. {
  258. DRAWITEMSTRUCT *di=(DRAWITEMSTRUCT *)lParam;
  259. if (di->CtlID == IDC_DEFCOL && g_this->num_colors>0)
  260. {
  261. int x;
  262. int w=di->rcItem.right-di->rcItem.left;
  263. int l=0,nl;
  264. for (x = 0; x < g_this->num_colors; x ++)
  265. {
  266. int color=g_this->colors[x];
  267. nl = (w*(x+1))/g_this->num_colors;
  268. color = ((color>>16)&0xff)|(color&0xff00)|((color<<16)&0xff0000);
  269. HPEN hPen,hOldPen;
  270. HBRUSH hBrush,hOldBrush;
  271. LOGBRUSH lb={(COLORREF)BS_SOLID,(COLORREF)color,(COLORREF)0};
  272. hPen = (HPEN)CreatePen(PS_SOLID,0,color);
  273. hBrush = CreateBrushIndirect(&lb);
  274. hOldPen=(HPEN)SelectObject(di->hDC,hPen);
  275. hOldBrush=(HBRUSH)SelectObject(di->hDC,hBrush);
  276. Rectangle(di->hDC,di->rcItem.left+l,di->rcItem.top,di->rcItem.left+nl,di->rcItem.bottom);
  277. SelectObject(di->hDC,hOldPen);
  278. SelectObject(di->hDC,hOldBrush);
  279. DeleteObject(hBrush);
  280. DeleteObject(hPen);
  281. l=nl;
  282. }
  283. }
  284. }
  285. return 0;
  286. case WM_INITDIALOG:
  287. if ((g_this->effect>>6)&1)
  288. {
  289. CheckDlgButton(hwndDlg,IDC_DOT,BST_CHECKED);
  290. if (g_this->effect&2)
  291. CheckDlgButton(hwndDlg,IDC_OSC,BST_CHECKED);
  292. else
  293. CheckDlgButton(hwndDlg,IDC_SA,BST_CHECKED);
  294. }
  295. else
  296. {
  297. CheckDlgButton(hwndDlg,chex[(g_this->effect&3)*2],BST_CHECKED);
  298. CheckDlgButton(hwndDlg,chex[(g_this->effect&3)*2+1],BST_CHECKED);
  299. }
  300. switch ((g_this->effect>>2)&3)
  301. {
  302. case 0: CheckDlgButton(hwndDlg,IDC_LEFTCH,BST_CHECKED); break;
  303. case 1: CheckDlgButton(hwndDlg,IDC_RIGHTCH,BST_CHECKED); break;
  304. case 2: CheckDlgButton(hwndDlg,IDC_MIDCH,BST_CHECKED); break;
  305. }
  306. switch ((g_this->effect>>4)&3)
  307. {
  308. case 0: CheckDlgButton(hwndDlg,IDC_TOP,BST_CHECKED); break;
  309. case 1: CheckDlgButton(hwndDlg,IDC_BOTTOM,BST_CHECKED); break;
  310. case 2: CheckDlgButton(hwndDlg,IDC_CENTER,BST_CHECKED); break;
  311. }
  312. SetDlgItemInt(hwndDlg,IDC_NUMCOL,g_this->num_colors,FALSE);
  313. return 1;
  314. case WM_COMMAND:
  315. switch (LOWORD(wParam))
  316. {
  317. case IDC_DOT: case IDC_SA: case IDC_SOLID: case IDC_OSC: case IDC_LINES:
  318. if (!IsDlgButtonChecked(hwndDlg,IDC_DOT))
  319. {
  320. int c;
  321. g_this->effect &= ~(1<<6);
  322. for (c = 0; c < 4; c ++)
  323. {
  324. if (IsDlgButtonChecked(hwndDlg,chex[c*2]) && IsDlgButtonChecked(hwndDlg,chex[c*2+1])) break;
  325. }
  326. if (c!=4) { g_this->effect&=~3; g_this->effect|=c;}
  327. }
  328. else
  329. {
  330. g_this->effect&=~3;
  331. if (!IsDlgButtonChecked(hwndDlg,IDC_SA)) g_this->effect|=2;
  332. g_this->effect |= 1<<6;
  333. }
  334. break;
  335. case IDC_LEFTCH: g_this->effect&=~12; break;
  336. case IDC_RIGHTCH: g_this->effect&=~12; g_this->effect|=4; break;
  337. case IDC_MIDCH: g_this->effect&=~12; g_this->effect|=8; break;
  338. case IDC_TOP: g_this->effect&=~48; break;
  339. case IDC_BOTTOM: g_this->effect&=~48; g_this->effect|=16; break;
  340. case IDC_CENTER: g_this->effect&=~48; g_this->effect|=32; break;
  341. case IDC_NUMCOL:
  342. {
  343. int p;
  344. BOOL tr=FALSE;
  345. p=GetDlgItemInt(hwndDlg,IDC_NUMCOL,&tr,FALSE);
  346. if (tr)
  347. {
  348. if (p > 16) p = 16;
  349. g_this->num_colors=p;
  350. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  351. }
  352. }
  353. break;
  354. case IDC_DEFCOL:
  355. {
  356. int wc=-1,w,h;
  357. POINT p;
  358. RECT r;
  359. GetCursorPos(&p);
  360. GetWindowRect(GetDlgItem(hwndDlg,IDC_DEFCOL),&r);
  361. p.x -= r.left;
  362. p.y -= r.top;
  363. w=r.right-r.left;
  364. h=r.bottom-r.top;
  365. if (p.x >= 0 && p.x < w && p.y >= 0 && p.y < h)
  366. {
  367. wc = (p.x*g_this->num_colors)/w;
  368. }
  369. if (wc>=0)
  370. {
  371. GR_SelectColor(hwndDlg,g_this->colors+wc);
  372. InvalidateRect(GetDlgItem(hwndDlg,IDC_DEFCOL),NULL,TRUE);
  373. }
  374. }
  375. }
  376. }
  377. return 0;
  378. }
  379. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  380. {
  381. g_this = this;
  382. return WASABI_API_CREATEDIALOG(IDD_CFG_SIMPLE,hwndParent,g_DlgProc);
  383. }
  384. #else
  385. C_RBASE *R_SimpleSpectrum(char *desc)
  386. { return NULL; }
  387. #endif