1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/*
LICENSE
-------
Copyright 2005 Nullsoft, Inc.
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Nullsoft nor the names of its contributors may be used to
endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <windows.h>
#include <commctrl.h>
#include <time.h>
#include "resource.h"
#include "r_defs.h"
#include "../Agave/Language/api_language.h"
#ifndef LASER
// this will be the directory and APE name displayed in the AVS Editor
#define MOD_NAME "Trans / Channel Shift"
#define C_THISCLASS C_ChannelShiftClass
typedef struct {
int mode;
int onbeat;
} apeconfig;
class C_THISCLASS : public C_RBASE
{
protected:
public:
C_THISCLASS();
virtual ~C_THISCLASS();
virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h);
virtual HWND conf(HINSTANCE hInstance, HWND hwndParent);
virtual char *get_desc();
virtual void load_config(unsigned char *data, int len);
virtual int save_config(unsigned char *data);
apeconfig config;
HWND hwndDlg;
};
// global configuration dialog pointer
static C_THISCLASS *g_ConfigThis;
static HINSTANCE g_hDllInstance;
// this is where we deal with the configuration screen
static BOOL CALLBACK g_DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
int ids[] = { IDC_RBG, IDC_BRG, IDC_BGR, IDC_GBR, IDC_GRB, IDC_RGB };
switch (uMsg)
{
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED) {
for (int i=0;i<sizeof(ids)/sizeof(ids[0]);i++)
if (IsDlgButtonChecked(hwndDlg, ids[i]))
g_ConfigThis->config.mode = ids[i];
g_ConfigThis->config.onbeat = IsDlgButtonChecked(hwndDlg, IDC_ONBEAT) ? 1 : 0;
}
return 1;
case WM_INITDIALOG:
g_ConfigThis->hwndDlg = hwndDlg;
CheckDlgButton(hwndDlg, g_ConfigThis->config.mode, 1);
if (g_ConfigThis->config.onbeat)
CheckDlgButton(hwndDlg, IDC_ONBEAT, 1);
return 1;
case WM_DESTROY:
KillTimer(hwndDlg, 1);
return 1;
}
return 0;
}
// set up default configuration
C_THISCLASS::C_THISCLASS()
{
memset(&config, 0, sizeof(apeconfig));
config.mode = IDC_RBG;
config.onbeat = 1;
}
// virtual destructor
C_THISCLASS::~C_THISCLASS()
{
}
int C_THISCLASS::render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)
{
if (isBeat&0x80000000) return 0;
int c;
int modes[] = { IDC_RGB, IDC_RBG, IDC_GBR, IDC_GRB, IDC_BRG, IDC_BGR };
if (isBeat && config.onbeat) {
config.mode = modes[rand() % 6];
}
c = w*h;
switch (config.mode) {
default:
case IDC_RGB:
return 0;
case IDC_RBG:
__asm {
mov ebx, framebuffer;
mov ecx, c;
lp1:
sub ecx, 4;
mov eax, dword ptr [ebx+ecx*4];
xchg ah, al;
mov [ebx+ecx*4], eax;
mov eax, dword ptr [ebx+ecx*4+4];
xchg ah, al;
mov [ebx+ecx*4+4], eax;
mov eax, dword ptr [ebx+ecx*4+8];
xchg ah, al;
mov [ebx+ecx*4+8], eax;
mov eax, dword ptr [ebx+ecx*4+12];
xchg ah, al;
mov [ebx+ecx*4+12], eax;
test ecx, ecx;
jnz lp1;
}
break;
case IDC_BRG:
__asm {
mov ebx, framebuffer;
mov ecx, c;
lp2:
sub ecx, 4;
mov eax, dword ptr [ebx+ecx*4];
mov dl, al;
shr eax, 8;
bswap eax;
mov ah, dl;
bswap eax;
mov [ebx+ecx*4], eax;
mov eax, dword ptr [ebx+ecx*4+4];
mov dl, al;
shr eax, 8;
bswap eax;
mov ah, dl;
bswap eax;
mov [ebx+ecx*4+4], eax;
mov eax, dword ptr [ebx+ecx*4+8];
mov dl, al;
shr eax, 8;
bswap eax;
mov ah, dl;
bswap eax;
mov [ebx+ecx*4+8], eax;
mov eax, dword ptr [ebx+ecx*4+12];
mov dl, al;
shr eax, 8;
bswap eax;
mov ah, dl;
bswap eax;
mov [ebx+ecx*4+12], eax;
test ecx, ecx;
jnz lp2;
}
break;
case IDC_BGR:
__asm {
mov ebx, framebuffer;
mov ecx, c;
lp3:
sub ecx, 4;
mov eax, dword ptr [ebx+ecx*4];
bswap eax;
shr eax, 8;
mov [ebx+ecx*4], eax;
mov eax, dword ptr [ebx+ecx*4+4];
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+4], eax;
mov eax, dword ptr [ebx+ecx*4+8];
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+8], eax;
mov eax, dword ptr [ebx+ecx*4+12];
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+12], eax;
test ecx, ecx;
jnz lp3;
}
break;
case IDC_GBR:
__asm {
mov ebx, framebuffer;
mov ecx, c;
lp4:
sub ecx, 4;
mov eax, dword ptr [ebx+ecx*4];
mov edx, eax;
bswap edx;
shl eax, 8;
mov al, dh;
mov [ebx+ecx*4], eax;
mov eax, dword ptr [ebx+ecx*4+4];
mov edx, eax;
bswap edx;
shl eax, 8;
mov al, dh;
mov [ebx+ecx*4+4], eax;
mov eax, dword ptr [ebx+ecx*4+8];
mov edx, eax;
bswap edx;
shl eax, 8;
mov al, dh;
mov [ebx+ecx*4+8], eax;
mov eax, dword ptr [ebx+ecx*4+12];
mov edx, eax;
bswap edx;
shl eax, 8;
mov al, dh;
mov [ebx+ecx*4+12], eax;
test ecx, ecx;
jnz lp4;
}
break;
case IDC_GRB:
__asm {
mov ebx, framebuffer;
mov ecx, c;
lp5:
sub ecx, 4;
mov eax, dword ptr [ebx+ecx*4];
shl eax, 8;
bswap eax;
xchg ah, al;
bswap eax;
shr eax, 8;
mov [ebx+ecx*4], eax;
mov eax, dword ptr [ebx+ecx*4+4];
shl eax, 8;
bswap eax;
xchg ah, al;
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+4], eax;
mov eax, dword ptr [ebx+ecx*4+8];
shl eax, 8;
bswap eax;
xchg ah, al;
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+8], eax;
mov eax, dword ptr [ebx+ecx*4+12];
shl eax, 8;
bswap eax;
xchg ah, al;
bswap eax;
shr eax, 8;
mov [ebx+ecx*4+12], eax;
test ecx, ecx;
jnz lp5;
}
break;
}
return 0;
}
HWND C_THISCLASS::conf(HINSTANCE hInstance, HWND hwndParent)
{
g_ConfigThis = this;
return WASABI_API_CREATEDIALOG(IDD_CFG_CHANSHIFT, hwndParent, (DLGPROC)g_DlgProc);
}
char *C_THISCLASS::get_desc(void)
{
static char desc[128]; return (!desc[0]?WASABI_API_LNGSTRING_BUF(IDS_TRANS_CHANNEL_SHIFT,desc,128):desc);
}
void C_THISCLASS::load_config(unsigned char *data, int len)
{
srand((unsigned int)time(0));
if (len <= sizeof(apeconfig))
memcpy(&this->config, data, len);
}
int C_THISCLASS::save_config(unsigned char *data)
{
memcpy(data, &this->config, sizeof(apeconfig));
return sizeof(apeconfig);
}
C_RBASE *R_ChannelShift(char *desc)
{
if (desc) {
strcpy(desc,MOD_NAME);
return NULL;
}
return (C_RBASE *) new C_THISCLASS();
}
#endif
|