r_invert.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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 <stdlib.h>
  26. #include <vfw.h>
  27. #include <commctrl.h>
  28. #include "resource.h"
  29. #include "r_defs.h"
  30. #include "../Agave/Language/api_language.h"
  31. #ifndef LASER
  32. #define MOD_NAME "Trans / Invert"
  33. #define C_THISCLASS C_InvertClass
  34. class C_THISCLASS : public C_RBASE {
  35. protected:
  36. public:
  37. C_THISCLASS();
  38. virtual ~C_THISCLASS();
  39. virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
  40. virtual char *get_desc() { static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_INVERT,desc,128):desc); }
  41. virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
  42. virtual void load_config(unsigned char *data, int len);
  43. virtual int save_config(unsigned char *data);
  44. int enabled;
  45. };
  46. static C_THISCLASS *g_ConfigThis; // global configuration dialog pointer
  47. static HINSTANCE g_hDllInstance; // global DLL instance pointer (not needed in this example, but could be useful)
  48. C_THISCLASS::~C_THISCLASS()
  49. {
  50. }
  51. // configuration read/write
  52. C_THISCLASS::C_THISCLASS() // set up default configuration
  53. {
  54. enabled=1;
  55. }
  56. #define GET_INT() (data[pos]|(data[pos+1]<<8)|(data[pos+2]<<16)|(data[pos+3]<<24))
  57. void C_THISCLASS::load_config(unsigned char *data, int len) // read configuration of max length "len" from data.
  58. {
  59. int pos=0;
  60. if (len-pos >= 4) { enabled=GET_INT(); pos+=4; }
  61. }
  62. #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
  63. int C_THISCLASS::save_config(unsigned char *data) // write configuration to data, return length. config data should not exceed 64k.
  64. {
  65. int pos=0;
  66. PUT_INT(enabled); pos+=4;
  67. return pos;
  68. }
  69. // render function
  70. // render should return 0 if it only used framebuffer, or 1 if the new output data is in fbout. this is
  71. // used when you want to do something that you'd otherwise need to make a copy of the framebuffer.
  72. // w and h are the width and height of the screen, in pixels.
  73. // isBeat is 1 if a beat has been detected.
  74. // visdata is in the format of [spectrum:0,wave:1][channel][band].
  75. int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
  76. {
  77. int i=w*h;
  78. int *p=framebuffer;
  79. if (isBeat&0x80000000) return 0;
  80. if (!enabled) return 0;
  81. #ifndef NO_MMX
  82. int a[2]={0xffffff,0xffffff};
  83. __asm
  84. {
  85. mov ecx, i
  86. shr ecx, 3
  87. movq mm0, [a]
  88. mov edi, p
  89. align 16
  90. _mmx_invert_loop:
  91. movq mm1, [edi]
  92. movq mm2, [edi+8]
  93. pxor mm1, mm0
  94. movq mm3, [edi+16]
  95. pxor mm2, mm0
  96. movq mm4, [edi+24]
  97. pxor mm3, mm0
  98. movq [edi], mm1
  99. pxor mm4, mm0
  100. movq [edi+8], mm2
  101. movq [edi+16], mm3
  102. movq [edi+24], mm4
  103. add edi, 32
  104. dec ecx
  105. jnz _mmx_invert_loop
  106. mov ecx, i
  107. shr ecx, 1
  108. and ecx, 3
  109. jz _mmx_invert_noendloop
  110. _mmx_invert_endloop:
  111. movq mm1, [edi]
  112. pxor mm1, mm0
  113. movq [edi], mm1
  114. add edi, 8
  115. dec ecx
  116. jnz _mmx_invert_endloop
  117. _mmx_invert_noendloop:
  118. emms
  119. }
  120. #else
  121. while (i--) *p++ = 0xFFFFFF^*p;
  122. #endif
  123. return 0;
  124. }
  125. // configuration dialog stuff
  126. static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam,LPARAM lParam)
  127. {
  128. switch (uMsg)
  129. {
  130. case WM_INITDIALOG:
  131. if (g_ConfigThis->enabled) CheckDlgButton(hwndDlg,IDC_CHECK1,BST_CHECKED);
  132. return 1;
  133. case WM_COMMAND:
  134. if (LOWORD(wParam) == IDC_CHECK1)
  135. g_ConfigThis->enabled=IsDlgButtonChecked(hwndDlg,IDC_CHECK1)?1:0;
  136. }
  137. return 0;
  138. }
  139. HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent) // return NULL if no config dialog possible
  140. {
  141. g_ConfigThis = this;
  142. return WASABI_API_CREATEDIALOG(IDD_CFG_INVERT,hwndParent,g_DlgProc);
  143. }
  144. // export stuff
  145. C_RBASE *R_Invert(char *desc) // creates a new effect object if desc is NULL, otherwise fills in desc with description
  146. {
  147. if (desc) { strcpy(desc,MOD_NAME); return NULL; }
  148. return (C_RBASE *) new C_THISCLASS();
  149. }
  150. #else
  151. C_RBASE *R_Invert(char *desc) // creates a new effect object if desc is NULL, otherwise fills in desc with description
  152. { return NULL; }
  153. #endif