1
0

draw_sa.cpp 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517
  1. /** (c) Nullsoft, Inc. C O N F I D E N T I A L
  2. ** Filename:
  3. ** Project:
  4. ** Description:
  5. ** Author:
  6. ** Created:
  7. **/
  8. #include "Main.h"
  9. #include "draw.h"
  10. #include "WADrawDC.h"
  11. unsigned char *specData;
  12. int sa_safe=0;
  13. int sa_kill=1;
  14. void draw_sa(unsigned char *values, int draw)
  15. {
  16. static int bx[75];
  17. static int t_bx[75];
  18. static float t_vx[75];
  19. int x;
  20. int fo[5] = {3, 6, 12, 16, 32 };
  21. float pfo[5]={1.05f,1.1f,1.2f,1.4f,1.6f};
  22. int dbx;
  23. float spfo;
  24. int ws=(config_windowshade&&config_mw_open);
  25. int s = (config_dsize&&config_mw_open)?1:0;
  26. unsigned char *gmem;
  27. dbx = fo[max(min(config_safalloff,4),0)];
  28. spfo=pfo[max(min(config_sa_peak_falloff,4),0)];
  29. sa_safe++;
  30. if (sa_kill || !draw_initted || !specData)
  31. {
  32. sa_safe--;
  33. return ;
  34. }
  35. if (s && draw)
  36. {
  37. int y;
  38. gmem = specData;
  39. if (!ws)
  40. {
  41. for (y = 0; y < 8; y++)
  42. {
  43. int *smem = (int *) gmem;
  44. for (int x = 0; x < 76; x ++)
  45. *smem++ = 0x0101;
  46. gmem += 76*2*2;
  47. memset(gmem,0,76*2*2);
  48. gmem += 76*2*2;
  49. }
  50. }
  51. else
  52. {
  53. gmem += 76*2*(32-10);
  54. for (y = 0; y < 10; y++)
  55. {
  56. memset(gmem,0,76);
  57. gmem += 76*2;
  58. }
  59. }
  60. }
  61. else if (draw)
  62. {
  63. int y;
  64. gmem = specData+76*2*16;
  65. if (!ws)
  66. {
  67. for (y = 0; y < 8; y++)
  68. {
  69. int *smem = (int *) gmem;
  70. for (int x = 0; x < 76/4; x ++)
  71. *smem++ = 0x10001;
  72. gmem += 76*2;
  73. memset(gmem,0,76);
  74. gmem += 76*2;
  75. }
  76. }
  77. else
  78. {
  79. gmem += 76*2*(16-5);
  80. for (y = 0; y < 5; y++)
  81. {
  82. memset(gmem,0,76/2);
  83. gmem += 76*2;
  84. }
  85. }
  86. }
  87. if (!values)
  88. {
  89. memset(bx,0,75*sizeof(int));
  90. }
  91. else if (!s) // singlesize
  92. {
  93. if (!ws) // non windowshade singlesize
  94. {
  95. if (config_sa == 2) // non windowshade singlesize oscilliscope
  96. {
  97. gmem = specData + 76*2*14;
  98. if (draw)
  99. {
  100. int lv=-1;
  101. if (((config_safire>>2)&3)==0) for (x = 0; x < 75; x ++)
  102. {
  103. register int v; register char c;
  104. v = (((int) ((signed char *)values)[x])) + 8;
  105. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  106. gmem[v*76*2] = c;
  107. gmem++;
  108. }
  109. else if (((config_safire>>2)&3)==1) for (x = 0; x < 75; x ++)
  110. {
  111. register int v,t; register char c;
  112. v = (((int) ((signed char *)values)[x])) + 8;
  113. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  114. if (lv == -1) lv=v;
  115. t=lv;
  116. lv=v;
  117. if (v >= t) while (v >= t) gmem[v--*76*2] = c;
  118. else while (v < t) gmem[v++*76*2] = c;
  119. gmem++;
  120. }
  121. else if (((config_safire>>2)&3)==2) for (x = 0; x < 75; x ++) // solid
  122. {
  123. register int v; register char c;
  124. v = (((int) ((signed char *)values)[x])) + 8;
  125. if (v < 0) v = 0 ; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  126. if (v > 7) while (v > 7) gmem[v--*76*2] = c;
  127. else while (v <= 7) gmem[v++*76*2] = c;
  128. gmem++;
  129. }
  130. }
  131. }
  132. else // non windowshade singlesize spectrum analyzer
  133. {
  134. for (x = 0; x < 75; x ++)
  135. {
  136. register int y,v,t;
  137. t=x&~3;
  138. if (!(config_safire&32))
  139. {
  140. int a=values[t],b=values[t+1],c=values[t+2],d=values[t+3];
  141. v = a+b+c+d;//-min(a,min(b,min(c,d)));
  142. v/=4;
  143. }
  144. else v = (((int)values[x]));
  145. if (v > 15) v = 15;
  146. if ((v<<4) < bx[x]) v = (bx[x]-=dbx)>>4;
  147. else bx[x] = v<<4;
  148. if (bx[x] < 0) bx[x] = 0;
  149. if (v < 0) v = 0;
  150. gmem = specData + 76*2*14 + x;
  151. if ((config_safire&3)==1) t = v+2;
  152. else if ((config_safire&3)==2) t=17-(v);
  153. else t = 17;
  154. if (t_bx[x] <= v*256) {
  155. t_bx[x]=v*256;
  156. t_vx[x]=3.0f;
  157. }
  158. if (draw && (config_safire&32 || (x&3)!=3))
  159. {
  160. if ((config_safire&3)!=2) for (y = 0; y < v; y ++)
  161. {
  162. *gmem = t-y;
  163. gmem += 76*2;
  164. }
  165. else for (y = 0; y < v; y ++)
  166. {
  167. *gmem = t;
  168. gmem += 76*2;
  169. }
  170. if (config_sa_peaks && t_bx[x]/256 >= 0 && t_bx[x]/256 <= 15)
  171. {
  172. specData[76*2*14 + (t_bx[x]/256)*76*2 + x]=23;
  173. }
  174. }
  175. t_bx[x] -= (int)t_vx[x];
  176. t_vx[x] *= spfo;
  177. if (t_bx[x] < 0) t_bx[x]=0;
  178. }
  179. }
  180. }
  181. else // windowshade singlesize
  182. {
  183. if (config_sa==1) // windowshade singlesize spectrum analyzer
  184. {
  185. gmem = specData+76*2*(32-5);
  186. for (x = 0; x < 37; x ++)
  187. {
  188. register int y,v,t;
  189. t=((x)&~3)*2;
  190. if (!(config_safire&32))
  191. {
  192. int a=values[t],b=values[t+1],c=values[t+2],d=values[t+3];
  193. v = a+b+c+d;//-min(a,min(b,min(c,d)));
  194. v/=4;
  195. }
  196. else v = (((int)values[x*2])+((int)values[x*2+1]))/2;
  197. if (v > 15) v = 15;
  198. if ((v<<4) < bx[x*2]) v = (bx[x*2]-=dbx)>>4;
  199. else bx[x*2] = v<<4;
  200. if (bx[x*2] < 0) bx[x*2] = 0;
  201. if (v < 0) v = 0;
  202. gmem = specData + 76*2*(32-5) + x;
  203. if ((config_safire&3)==1) t = v+2;
  204. else if ((config_safire&3)==2) t=17-(v);
  205. else t = 17;
  206. if (t_bx[x*2] <= v*256) {
  207. t_bx[x*2]=v*256;
  208. t_vx[x*2]=3.0f;
  209. }
  210. v = (v * 5)/15;
  211. if (v > 5) v=5;
  212. if (draw && (config_safire&32 || (x&3)!=3))
  213. {
  214. int poo=(t_bx[x*2]*5)/15/256;
  215. if ((config_safire&3)!=2) for (y = 0; y < v; y ++)
  216. {
  217. *gmem = t-(y*15)/5;
  218. gmem += 76*2;
  219. }
  220. else for (y = 0; y < v; y ++)
  221. {
  222. *gmem = t;
  223. gmem += 76*2;
  224. }
  225. if (config_sa_peaks && poo >= 0 && poo <= 4)
  226. {
  227. specData[76*2*(32-5) + poo*76*2 + x]=23;
  228. }
  229. }
  230. t_bx[x*2] -= (int)t_vx[x*2];
  231. t_vx[x*2] *= spfo;
  232. if (t_bx[x*2] < 0) t_bx[x*2]=0;
  233. }
  234. }
  235. else if (config_sa == 2) // windowshade singlesize oscilliscope
  236. {
  237. int wm=((config_safire>>2)&3);
  238. int lastv=-5;
  239. gmem = specData+76*2*(32-5);
  240. for (x = 0; x < 38; x ++)
  241. {
  242. int v = (((int) ((signed char *)values)[x])) + 8;
  243. v *= 5;
  244. v /= 16;
  245. if (v < 0) v = 0 ; if (v > 4) v = 4;
  246. if (wm==0 || lastv==-5)
  247. {
  248. lastv=v;
  249. gmem[x+v*76*2] = 18;
  250. }
  251. else if (wm == 1)
  252. {
  253. int tmp=lastv;
  254. lastv=v;
  255. if (v >= tmp) while (v>=tmp) { gmem[x+v--*76*2] = 18; }
  256. else while (v<=tmp) { gmem[x+v++*76*2] = 18; }
  257. }
  258. else if (wm == 2)
  259. {
  260. if (v >= 2) while (v>=2) { gmem[x+v--*76*2] = 18; }
  261. else while (v<=2) { gmem[x+v++*76*2] = 18; }
  262. }
  263. }
  264. }
  265. }
  266. }
  267. else // doublesize
  268. {
  269. if (!ws)
  270. {
  271. if (config_sa == 2)
  272. {
  273. gmem = specData;// + 76*2*16;
  274. if (draw)
  275. {
  276. int lv=-1;
  277. if (((config_safire>>2)&3)==0) for (x = 0; x < 75*2; x += 2)
  278. {
  279. register int v; register char c;
  280. v = (((int) ((signed char *)values)[x/2])) + 8;
  281. if (v < 0) v = 0; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  282. gmem[v*76*2*2] = c; gmem++[v*76*2*2 + 76*2] = c;
  283. gmem[v*76*2*2] = c; gmem++[v*76*2*2 + 76*2] = c;
  284. }
  285. else if (((config_safire>>2)&3)==1) for (x = 0; x < 75*2; x += 2)
  286. {
  287. register int v,t; register char c;
  288. v = (((int) ((signed char *)values)[x/2])) + 8;
  289. if (v < 0) v = 0; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  290. if (lv == -1) lv=v;
  291. t=lv;
  292. lv=v;
  293. if (v >= t) while (v >= t)
  294. {
  295. gmem[v*76*2*2] = c;
  296. gmem[v*76*2*2 + 76*2] = c;
  297. gmem[v*76*2*2 + 1] = c;
  298. gmem[v*76*2*2 + 76*2 + 1] = c;
  299. v--;
  300. }
  301. else while (v < t)
  302. {
  303. gmem[v*76*2*2] = c;
  304. gmem[v*76*2*2 + 76*2] = c;
  305. gmem[v*76*2*2 + 1] = c;
  306. gmem[v*76*2*2 + 76*2 + 1] = c;
  307. v++;
  308. }
  309. gmem+=2;
  310. }
  311. else if (((config_safire>>2)&3)==2) for (x = 0; x < 75*2; x += 2)
  312. {
  313. register int v; register char c;
  314. v = (((int) ((signed char *)values)[x/2])) + 8;
  315. if (v < 0) v = 0; if (v > 15) v = 15; c = v/2-4; if (c < 0) c = -c; c += 18;
  316. if (v > 7) while (v > 7)
  317. {
  318. gmem[v*76*2*2] = c;
  319. gmem[v*76*2*2 + 76*2] = c;
  320. gmem[v*76*2*2 + 1] = c;
  321. gmem[v*76*2*2 + 76*2 + 1] = c;
  322. v--;
  323. }
  324. else while (v <= 7)
  325. {
  326. gmem[v*76*2*2] = c;
  327. gmem[v*76*2*2 + 76*2] = c;
  328. gmem[v*76*2*2 + 1] = c;
  329. gmem[v*76*2*2 + 76*2 + 1] = c;
  330. v++;
  331. }
  332. gmem+=2;
  333. }
  334. }
  335. }
  336. else
  337. {
  338. for (x = 0; x < 75*2;)
  339. {
  340. register int y,v, t;
  341. t=(x/2)&~3;
  342. if (!(config_safire&32))
  343. {
  344. int a=values[t],b=values[t+1],c=values[t+2],d=values[t+3];
  345. v = a+b+c+d;//-min(a,min(b,min(c,d)));
  346. v/=4;
  347. }
  348. else v = (((int)values[x/2]));
  349. if (v > 15) v = 15;
  350. if ((v<<4) < bx[x/2]) v = (bx[x/2]-=dbx)>>4;
  351. else bx[x/2] = v<<4;
  352. if (bx[x/2] < 0) bx[x/2] = 0;
  353. if (v < 0) v = 0;
  354. gmem = specData+x;
  355. if ((config_safire&3)==1) t = v+2;
  356. else if ((config_safire&3)==2) t = 17 - v;
  357. else t = 17;
  358. if (t_bx[x/2] <= v*256) {
  359. t_bx[x/2]=v*256;
  360. t_vx[x/2]=3.0f;
  361. }
  362. v*=2;
  363. if (draw && (config_safire&32 || ((x/2)&3)!=3))
  364. {
  365. if ((config_safire&3)!=2) for (y = 0; y < v; y ++)
  366. {
  367. gmem[0] = gmem[1] = t-y/2;
  368. gmem += 76*2;
  369. }
  370. else for (y = 0; y < v; y ++)
  371. {
  372. gmem[0] = gmem[1] = t;
  373. gmem += 76*2;
  374. }
  375. if (config_sa_peaks && t_bx[x/2]/256 > 0 && t_bx[x/2]/256 <= 15)
  376. {
  377. specData[(t_bx[x/2]/256)*76*4 + x]=specData[(t_bx[x/2]/256)*76*4 + x+1]=23;
  378. specData[(t_bx[x/2]/256)*76*4 + x + 76*2]=specData[(t_bx[x/2]/256)*76*4 + x+1+ 76*2]=23;
  379. }
  380. }
  381. t_bx[x/2] -= (int)t_vx[x/2];
  382. t_vx[x/2] *=spfo;
  383. if (t_bx[x/2] < 0) t_bx[x/2]=0;
  384. x+=2;
  385. }
  386. }
  387. }
  388. else
  389. {
  390. if (config_sa == 2) // doublesize window shade scope
  391. {
  392. int wm=((config_safire>>2)&3);
  393. int lastv=-5;
  394. gmem = specData+76*2*(32-10);
  395. for (x = 0; x < 75; x ++)
  396. {
  397. int v = (((int) ((signed char *)values)[x])) + 8;
  398. v *= 10;
  399. v /= 16;
  400. if (v < 0) v = 0 ; if (v > 9) v = 9;
  401. if (wm==0 || lastv==-5)
  402. {
  403. lastv=v;
  404. gmem[x+v*76*2] = 18;
  405. }
  406. else if (wm == 1)
  407. {
  408. int tmp=lastv;
  409. lastv=v;
  410. if (v >= tmp) while (v>=tmp) { gmem[x+v--*76*2] = 18; }
  411. else while (v<=tmp) { gmem[x+v++*76*2] = 18; }
  412. }
  413. else if (wm == 2)
  414. {
  415. if (v >= 4) while (v>=4) { gmem[x+v--*76*2] = 18; }
  416. else while (v<=4) { gmem[x+v++*76*2] = 18; }
  417. }
  418. }
  419. }
  420. if (config_sa == 1) { // doublesize window shade spectrum
  421. for (x = 0; x < 75; x ++)
  422. {
  423. register int y,v,t;
  424. t=(x)&~3;
  425. if (!(config_safire&32))
  426. {
  427. int a=values[t],b=values[t+1],c=values[t+2],d=values[t+3];
  428. v = a+b+c+d;//-min(a,min(b,min(c,d)));
  429. v/=4;
  430. }
  431. else v = (int)values[x];
  432. if (v > 15) v = 15;
  433. if ((v<<4) < bx[x]) v = (bx[x]-=dbx)>>4;
  434. else bx[x] = v<<4;
  435. if (bx[x] < 0) bx[x] = 0;
  436. if (v < 0) v = 0;
  437. gmem = specData + 76*2*(32-10) + x;
  438. if ((config_safire&3)==1) t = v+2;
  439. else if ((config_safire&3)==2) t=17-(v);
  440. else t = 17;
  441. if (t_bx[x] <= v*256) {
  442. t_bx[x]=v*256;
  443. t_vx[x]=3.0f;
  444. }
  445. v = (v * 10)/15;
  446. if (draw && (config_safire&32 || (x&3)!=3))
  447. {
  448. int poo=(t_bx[x]*10)/15/256;
  449. if ((config_safire&3)!=2) for (y = 0; y < v; y ++)
  450. {
  451. *gmem = t-(y*15)/10;
  452. gmem += 76*2;
  453. }
  454. else for (y = 0; y < v; y ++)
  455. {
  456. *gmem = t;
  457. gmem += 76*2;
  458. }
  459. if (config_sa_peaks && poo >= 0 && poo <= 9)
  460. {
  461. specData[76*2*(32-10) + poo*76*2 + x]=23;
  462. }
  463. }
  464. t_bx[x] -= (int)t_vx[x];
  465. t_vx[x] *= spfo;
  466. if (t_bx[x] < 0) t_bx[x]=0;
  467. }
  468. }
  469. }
  470. }
  471. if (draw)
  472. {
  473. if (config_mw_open && hVisWindow)
  474. {
  475. WADrawDC myDC(hVisWindow);
  476. if (myDC)
  477. {
  478. do_palmode(myDC);
  479. if(values)
  480. {
  481. if (!ws) BitBlt(myDC,0,0,76<<s,16<<s,specDC,0,0,SRCCOPY);
  482. else BitBlt(myDC,0,0,38<<s,5<<s,specDC,0,0,SRCCOPY);
  483. }
  484. else
  485. {
  486. InvalidateRect(hMainWindow,NULL,FALSE);
  487. }
  488. }
  489. }
  490. else if (config_pe_open && config_pe_width >= 350 && config_pe_height != 14 && hPLVisWindow)
  491. {
  492. if (hPLWindow)
  493. {
  494. WADrawDC myDC(hPLVisWindow);
  495. if (myDC)
  496. {
  497. do_palmode(myDC);
  498. if(values)
  499. BitBlt(myDC,0,0,72,16,specDC,0,0,SRCCOPY);
  500. else
  501. InvalidateRect(hPLWindow,NULL,FALSE);
  502. }
  503. }
  504. }
  505. }
  506. sa_safe--;
  507. }