1
0

r_rotblit.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  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 "timing.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #include <math.h>
  33. #define M_PI 3.1415926536
  34. #define C_THISCLASS C_RotBlitClass
  35. #define MOD_NAME "Trans / Roto Blitter"
  36. class C_THISCLASS : public C_RBASE {
  37. protected:
  38. public:
  39. C_THISCLASS();
  40. virtual ~C_THISCLASS();
  41. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  42. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_ROTO_BLITTER,desc,128):desc); }
  43. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  44. virtual void load_config(unsigned char *data, int len);
  45. virtual int save_config(unsigned char *data);
  46. int zoom_scale, rot_dir, blend, beatch, beatch_speed, zoom_scale2, beatch_scale,scale_fpos;
  47. int rot_rev;
  48. int subpixel;
  49. double rot_rev_pos;
  50. int l_w, l_h;
  51. int *w_mul;
  52. };
  53. #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
  54. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  55. void C_THISCLASS::load_config(unsigned char *data, int len)
  56. {
  57. int pos=0;
  58. if (len-pos >= 4) { zoom_scale=GET_INT(); pos+=4; }
  59. if (len-pos >= 4) { rot_dir=GET_INT(); pos+=4; }
  60. if (len-pos >= 4) { blend=GET_INT(); pos+=4; }
  61. if (len-pos >= 4) { beatch=GET_INT(); pos+=4; }
  62. if (len-pos >= 4) { beatch_speed=GET_INT(); pos+=4; }
  63. if (len-pos >= 4) { zoom_scale2=GET_INT(); pos+=4; }
  64. if (len-pos >= 4) { beatch_scale=GET_INT(); pos+=4; }
  65. if (len-pos >= 4) { subpixel=GET_INT(); pos+=4; }
  66. else subpixel=0;
  67. scale_fpos=zoom_scale;
  68. }
  69. int C_THISCLASS::save_config(unsigned char *data)
  70. {
  71. int pos=0;
  72. PUT_INT(zoom_scale); pos+=4;
  73. PUT_INT(rot_dir); pos+=4;
  74. PUT_INT(blend); pos+=4;
  75. PUT_INT(beatch); pos+=4;
  76. PUT_INT(beatch_speed); pos+=4;
  77. PUT_INT(zoom_scale2); pos+=4;
  78. PUT_INT(beatch_scale); pos+=4;
  79. PUT_INT(subpixel); pos+=4;
  80. return pos;
  81. }
  82. C_THISCLASS::C_THISCLASS()
  83. {
  84. zoom_scale=31;
  85. rot_dir=31;
  86. blend=0;
  87. rot_rev=1;
  88. rot_rev_pos=1.0;
  89. beatch=0;
  90. l_w=l_h=0;
  91. w_mul=NULL;
  92. beatch_speed=0;
  93. beatch_scale=0;
  94. zoom_scale2=31;
  95. scale_fpos=zoom_scale;
  96. subpixel=1;
  97. }
  98. C_THISCLASS::~C_THISCLASS()
  99. {
  100. if (w_mul) GlobalFree(w_mul);
  101. w_mul=NULL;
  102. l_w=l_h=0;
  103. }
  104. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  105. {
  106. int y;
  107. if (l_w != w || l_h != h || !w_mul) // generate width table
  108. {
  109. int x;
  110. if (w_mul) GlobalFree(w_mul);
  111. l_w=w;
  112. l_h=h;
  113. w_mul=(int *)GlobalAlloc(GMEM_FIXED,sizeof(int)*h);
  114. for (x = 0; x < h; x ++)
  115. w_mul[x]=x*w;
  116. }
  117. if (isBeat&0x80000000) return 0;
  118. unsigned int *dest=(unsigned int *) fbout;
  119. unsigned int *src=(unsigned int *) framebuffer;
  120. unsigned int *bdest=(unsigned int *) framebuffer;
  121. if (isBeat && beatch)
  122. {
  123. rot_rev=-rot_rev;
  124. }
  125. if (!beatch) rot_rev=1;
  126. rot_rev_pos+=(1.0/(1+beatch_speed*4))*(rot_rev-rot_rev_pos);
  127. if (rot_rev_pos > rot_rev && rot_rev>0) rot_rev_pos=rot_rev;
  128. if (rot_rev_pos < rot_rev && rot_rev<0) rot_rev_pos=rot_rev;
  129. if (isBeat && beatch_scale)
  130. {
  131. scale_fpos=zoom_scale2;
  132. }
  133. int f_val;
  134. if (zoom_scale < zoom_scale2)
  135. {
  136. f_val=max(scale_fpos,zoom_scale);
  137. if (scale_fpos > zoom_scale) scale_fpos -= 3;
  138. }
  139. else
  140. {
  141. f_val=min(scale_fpos,zoom_scale);
  142. if (scale_fpos < zoom_scale) scale_fpos+=3;
  143. }
  144. double zoom = 1.0 + (f_val-31)/31.0;
  145. double theta=((rot_dir-32))*rot_rev_pos;
  146. double temp;
  147. int ds_dx, dt_dx, ds_dy, dt_dy, s, t, sstart, tstart;
  148. int x, offset=0;
  149. temp = cos((theta)*M_PI/180.0)*zoom;
  150. ds_dx = (int) (temp*65536.0);
  151. dt_dy = (int) (temp*65536.0);
  152. temp = sin((theta)*M_PI/180.0)*zoom;
  153. ds_dy = - (int) (temp*65536.0);
  154. dt_dx = (int) (temp*65536.0);
  155. s = sstart = -(((w-1)/2)*ds_dx + ((h-1)/2)*ds_dy) + (w-1)*(32768 + (1<<20));
  156. t = tstart = -(((w-1)/2)*dt_dx + ((h-1)/2)*dt_dy) + (h-1)*(32768 + (1<<20));
  157. int ds, dt;
  158. ds = (w-1)<<16;
  159. dt = (h-1)<<16;
  160. y = h;
  161. if (ds_dx <= -ds || ds_dx >= ds || dt_dx <= -dt || dt_dx >= dt);
  162. else while (y--)
  163. {
  164. if (ds) s %= ds;
  165. if (dt) t %= dt;
  166. if (s < 0) s+=ds; if (t < 0) t+=dt;
  167. x = w;
  168. offset = y*w;
  169. #define DO_LOOP(Z) while (x--) { Z; s += ds_dx; t += dt_dx; }
  170. #define DO_LOOPS(Z) \
  171. if (ds_dx <= 0 && dt_dx <= 0) DO_LOOP(if (t < 0) t += dt; if (s < 0) s += ds; Z) \
  172. else if (ds_dx <= 0) DO_LOOP(if (t >= dt) t -= dt; if (s < 0) s += ds; Z) \
  173. else if (dt_dx <= 0) DO_LOOP(if (t < 0) t += dt; if (s >= ds) s -= ds; Z) \
  174. else DO_LOOP(if (t >= dt) t -= dt; if (s >= ds) s -= ds; Z)
  175. if (subpixel && blend) DO_LOOPS(*dest++ = BLEND_AVG(*bdest++,BLEND4_16(src+(s>>16)+w_mul[t>>16],w,s,t)))
  176. else if (subpixel) DO_LOOPS(*dest++ = BLEND4_16(src+(s>>16)+w_mul[t>>16],w,s,t))
  177. else if (!blend) DO_LOOPS(*dest++ = src[(s>>16)+w_mul[t>>16]])
  178. else DO_LOOPS(*dest++ = BLEND_AVG(*bdest++,src[(s>>16)+w_mul[t>>16]]))
  179. s = (sstart += ds_dy);
  180. t = (tstart += dt_dy);
  181. }
  182. #ifndef NO_MMX
  183. __asm emms;
  184. #endif
  185. return 1;
  186. }
  187. C_RBASE *R_RotBlit(char *desc)
  188. {
  189. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  190. return (C_RBASE *) new C_THISCLASS();
  191. }
  192. static C_THISCLASS *g_this;
  193. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  194. {
  195. int *a=NULL;
  196. switch (uMsg)
  197. {
  198. case WM_INITDIALOG:
  199. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMIN,0,0);
  200. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETRANGEMAX,0,256);
  201. SendDlgItemMessage(hwndDlg,IDC_SLIDER1,TBM_SETPOS,1,g_this->zoom_scale);
  202. SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETRANGEMIN,0,0);
  203. SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETRANGEMAX,0,256);
  204. SendDlgItemMessage(hwndDlg,IDC_SLIDER6,TBM_SETPOS,1,g_this->zoom_scale2);
  205. SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETRANGEMIN,0,0);
  206. SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETRANGEMAX,0,8);
  207. SendDlgItemMessage(hwndDlg,IDC_SLIDER5,TBM_SETPOS,1,g_this->beatch_speed);
  208. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMIN,0,0);
  209. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETRANGEMAX,0,64);
  210. SendDlgItemMessage(hwndDlg,IDC_SLIDER2,TBM_SETPOS,1,g_this->rot_dir);
  211. if (g_this->subpixel) CheckDlgButton(hwndDlg,IDC_CHECK2,BST_CHECKED);
  212. else if (g_this->blend==1) CheckDlgButton(hwndDlg,IDC_BLEND,BST_CHECKED);
  213. if (g_this->beatch==1) CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
  214. if (g_this->beatch_scale==1) CheckDlgButton(hwndDlg,IDC_CHECK6,BST_CHECKED);
  215. return 1;
  216. case WM_COMMAND:
  217. switch (LOWORD(wParam))
  218. {
  219. case IDC_BLEND:
  220. if (IsDlgButtonChecked(hwndDlg,IDC_BLEND))
  221. {
  222. g_this->blend=1;
  223. }
  224. else g_this->blend=0;
  225. break;
  226. case IDC_CHECK1:
  227. if (IsDlgButtonChecked(hwndDlg,IDC_CHECK1))
  228. g_this->beatch=1;
  229. else g_this->beatch=0;
  230. break;
  231. case IDC_CHECK2:
  232. if (IsDlgButtonChecked(hwndDlg,IDC_CHECK2))
  233. {
  234. g_this->subpixel=1;
  235. }
  236. else g_this->subpixel=0;
  237. break;
  238. case IDC_CHECK6:
  239. if (IsDlgButtonChecked(hwndDlg,IDC_CHECK6))
  240. g_this->beatch_scale=1;
  241. else g_this->beatch_scale=0;
  242. break;
  243. }
  244. return 0;
  245. case WM_HSCROLL:
  246. {
  247. HWND swnd = (HWND) lParam;
  248. int t = (int) SendMessage(swnd,TBM_GETPOS,0,0);
  249. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER1))
  250. {
  251. g_this->zoom_scale=t;
  252. }
  253. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER6))
  254. {
  255. g_this->zoom_scale2=t;
  256. g_this->scale_fpos=t;
  257. }
  258. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER2))
  259. {
  260. g_this->rot_dir=t;
  261. }
  262. if (swnd == GetDlgItem(hwndDlg,IDC_SLIDER5))
  263. {
  264. g_this->beatch_speed=t;
  265. }
  266. }
  267. }
  268. return 0;
  269. }
  270. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
  271. {
  272. g_this = this;
  273. return WASABI_API_CREATEDIALOG(IDD_CFG_ROTBLT,hwndParent,g_DlgProc);
  274. }
  275. #else
  276. C_RBASE *R_RotBlit(char *desc)
  277. { return NULL; }
  278. #endif