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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
|
/*
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.
*/
#ifndef _R_DEFS_H_
#define _R_DEFS_H_
// base class declaration, compatibility class
class RString;
class C_RBASE {
public:
C_RBASE() { }
virtual ~C_RBASE() { };
virtual int render(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h)=0; // returns 1 if fbout has dest
virtual HWND conf(HINSTANCE hInstance, HWND hwndParent){return 0;};
virtual char *get_desc()=0;
virtual void load_config(unsigned char *data, int len) { }
virtual int save_config(unsigned char *data) { return 0; }
void load_string(RString &s,unsigned char *data, int &pos, int len);
void save_string(unsigned char *data, int &pos, RString &text);
};
class C_RBASE2 : public C_RBASE {
public:
C_RBASE2() { }
virtual ~C_RBASE2() { };
int getRenderVer2() { return 2; }
virtual int smp_getflags() { return 0; } // return 1 to enable smp support
// returns # of threads you desire, <= max_threads, or 0 to not do anything
// default should return max_threads if you are flexible
virtual int smp_begin(int max_threads, char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) { return 0; }
virtual void smp_render(int this_thread, int max_threads, char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) { };
virtual int smp_finish(char visdata[2][2][576], int isBeat, int *framebuffer, int *fbout, int w, int h) { return 0; }; // return value is that of render() for fbstuff etc
};
// defined in main.cpp, render.cpp
extern char g_path[];
extern unsigned char g_blendtable[256][256];
extern int g_reset_vars_on_recompile;
// use this function to get a global buffer, and the last flag says whether or not to
// allocate it if it's not valid...
#define NBUF 8
void *getGlobalBuffer(int w, int h, int n, int do_alloc);
// implemented in util.cpp
char* GetTextResource(UINT id);
void GR_SelectColor(HWND hwnd, int *a);
void GR_DrawColoredButton(DRAWITEMSTRUCT *di, COLORREF color);
void loadComboBox(HWND dlg, char *ext, char *selectedName);
void compilerfunctionlist(HWND hwndDlg, char *localinfo=NULL);
// matrix.cpp
void matrixRotate(float matrix[], char m, float Deg);
void matrixTranslate(float m[], float x, float y, float z);
void matrixMultiply(float *dest, float src[]);
void matrixApply(float *m, float x, float y, float z, float *outx, float *outy, float *outz);
// linedraw.cpp
extern int g_line_blend_mode;
void line(int *fb, int x1,int y1,int x2,int y2, int width, int height, int color, int lw);
// inlines
static unsigned int __inline BLEND(unsigned int a, unsigned int b)
{
register unsigned int r,t;
r=(a&0xff)+(b&0xff);
t=min(r,0xff);
r=(a&0xff00)+(b&0xff00);
t|=min(r,0xff00);
r=(a&0xff0000)+(b&0xff0000);
t|=min(r,0xff0000);
r=(a&0xff000000)+(b&0xff000000);
return t|min(r,0xff000000);
}
#if 1
#define FASTMAX(x,y) max(x,y)
// (x-(((x-y)>>(32-1))&(x-y))) // hmm not faster :(
#define FASTMIN(x,y) min(x,y)
//(x+(((y-x)>>(32-1))&(y-x)))
#else
#pragma warning( push, 1 )
static __inline int FASTMAX(int x, int y)
{
__asm
{
mov ecx, [x]
mov eax, [y]
sub ecx, eax
cmc
and ecx, edx
add eax, ecx
}
}
static __inline int FASTMIN(int x, int y)
{
__asm
{
mov ecx, [x]
mov eax, [y]
sub ecx, eax
sbb edx, edx
and ecx, edx
add eax, ecx
}
}
#pragma warning( pop )
#endif
static unsigned int __inline BLEND_MAX(unsigned int a, unsigned int b)
{
register unsigned int t;
int _a=a&0xff;
int _b=b&0xff;
t=FASTMAX(_a,_b);
_a=a&0xff00; _b=b&0xff00;
t|=FASTMAX(_a,_b);
_a=a&0xff0000; _b=b&0xff0000;
t|=FASTMAX(_a,_b);
return t;
}
static unsigned int __inline BLEND_MIN(unsigned int a, unsigned int b)
{
#if 1
register unsigned int t;
int _a=a&0xff;
int _b=b&0xff;
t=FASTMIN(_a,_b);
_a=a&0xff00; _b=b&0xff00;
t|=FASTMIN(_a,_b);
_a=a&0xff0000; _b=b&0xff0000;
t|=FASTMIN(_a,_b);
return t;
#else
__asm
{
mov ecx, [a]
mov eax, [b]
and ecx, 0xff
and eax, 0xff
mov esi, [a]
mov ebx, [b]
sub ecx, eax
sbb edx, edx
and esi, 0xff00
and ebx, 0xff00
and ecx, edx
sub esi, ebx
sbb edx, edx
add eax, ecx
and esi, edx
mov ecx, [a]
add ebx, esi
and ecx, 0xff0000
mov esi, [b]
or eax, ebx
and esi, 0xff0000
sub ecx, esi
sbb edx, edx
and ecx, edx
add esi, ecx
or eax, esi
}
#endif
}
#ifdef FASTMAX
#undef FASTMAX
#undef FASTMIN
#endif
static unsigned int __inline BLEND_AVG(unsigned int a, unsigned int b)
{
return ((a>>1)&~((1<<7)|(1<<15)|(1<<23)))+((b>>1)&~((1<<7)|(1<<15)|(1<<23)));
}
static unsigned int __inline BLEND_SUB(unsigned int a, unsigned int b)
{
register int r,t;
r=(a&0xff)-(b&0xff);
t=max(r,0);
r=(a&0xff00)-(b&0xff00);
t|=max(r,0);
r=(a&0xff0000)-(b&0xff0000);
t|=max(r,0);
r=(a&0xff000000)-(b&0xff000000);
return t|max(r,0);
}
#ifdef NO_MMX
#define BLEND_ADJ BLEND_ADJ_NOMMX
#endif
static unsigned int __inline BLEND_ADJ_NOMMX(unsigned int a, unsigned int b, int v)
{
register int t;
t=g_blendtable[a&0xFF][v]+g_blendtable[b&0xFF][0xFF-v];
t|=(g_blendtable[(a&0xFF00)>>8][v]+g_blendtable[(b&0xFF00)>>8][0xFF-v])<<8;
t|=(g_blendtable[(a&0xFF0000)>>16][v]+g_blendtable[(b&0xFF0000)>>16][0xFF-v])<<16;
return t;
}
static unsigned int __inline BLEND_MUL(unsigned int a, unsigned int b)
{
register int t;
t=g_blendtable[a&0xFF][b&0xFF];
t|=g_blendtable[(a&0xFF00)>>8][(b&0xFF00)>>8]<<8;
t|=g_blendtable[(a&0xFF0000)>>16][(b&0xFF0000)>>16]<<16;
return t;
}
static __inline void BLEND_LINE(int *fb, int color)
{
register int bm=g_line_blend_mode&0xff;
switch (g_line_blend_mode&0xff)
{
case 1: *fb=BLEND(*fb,color); break;
case 2: *fb=BLEND_MAX(*fb,color); break;
case 3: *fb=BLEND_AVG(*fb,color); break;
case 4: *fb=BLEND_SUB(*fb,color); break;
case 5: *fb=BLEND_SUB(color,*fb); break;
case 6: *fb=BLEND_MUL(*fb,color); break;
case 7: *fb=BLEND_ADJ_NOMMX(*fb,color,(g_line_blend_mode>>8)&0xff); break;
case 8: *fb=*fb^color; break;
case 9: *fb=BLEND_MIN(*fb,color); break;
default: *fb=color; break;
}
}
extern unsigned int const mmx_blend4_revn[2];
extern int const mmx_blend4_zero;
extern int const mmx_blendadj_mask[2];
// NOTE. WHEN USING THIS FUNCTION, BE SURE TO DO 'if (g_mmx_available) __asm emms;' before calling
// any fpu code, or before returning.
#pragma warning( push, 1 )
#ifndef NO_MMX
static unsigned int __inline BLEND_ADJ(unsigned int a, unsigned int b, int v)
{
__asm
{
movd mm3, [v] // VVVVVVVV
movd mm0, [a]
packuswb mm3, mm3 // 0000HHVV
movd mm1, [b]
punpcklwd mm3, mm3 // HHVVHHVV
movq mm4, [mmx_blend4_revn]
punpckldq mm3, mm3 // HHVVHHVV HHVVHHVV
punpcklbw mm0, [mmx_blend4_zero]
pand mm3, [mmx_blendadj_mask]
punpcklbw mm1, [mmx_blend4_zero]
psubw mm4, mm3
pmullw mm0, mm3
pmullw mm1, mm4
paddw mm0, mm1
psrlw mm0, 8
packuswb mm0, mm0
movd eax, mm0
}
}
#endif
static __inline unsigned int BLEND4(unsigned int *p1, unsigned int w, int xp, int yp)
{
#ifdef NO_MMX
register int t;
unsigned char a1,a2,a3,a4;
a1=g_blendtable[255-xp][255-yp];
a2=g_blendtable[xp][255-yp];
a3=g_blendtable[255-xp][yp];
a4=g_blendtable[xp][yp];
t=g_blendtable[p1[0]&0xff][a1]+g_blendtable[p1[1]&0xff][a2]+g_blendtable[p1[w]&0xff][a3]+g_blendtable[p1[w+1]&0xff][a4];
t|=(g_blendtable[(p1[0]>>8)&0xff][a1]+g_blendtable[(p1[1]>>8)&0xff][a2]+g_blendtable[(p1[w]>>8)&0xff][a3]+g_blendtable[(p1[w+1]>>8)&0xff][a4])<<8;
t|=(g_blendtable[(p1[0]>>16)&0xff][a1]+g_blendtable[(p1[1]>>16)&0xff][a2]+g_blendtable[(p1[w]>>16)&0xff][a3]+g_blendtable[(p1[w+1]>>16)&0xff][a4])<<16;
return t;
#else
__asm
{
movd mm6, xp
mov eax, p1
movd mm7, yp
mov esi, w
movq mm4, mmx_blend4_revn
punpcklwd mm6,mm6
movq mm5, mmx_blend4_revn
punpcklwd mm7,mm7
movd mm0, [eax]
punpckldq mm6,mm6
movd mm1, [eax+4]
punpckldq mm7,mm7
movd mm2, [eax+esi*4]
punpcklbw mm0, [mmx_blend4_zero]
movd mm3, [eax+esi*4+4]
psubw mm4, mm6
punpcklbw mm1, [mmx_blend4_zero]
pmullw mm0, mm4
punpcklbw mm2, [mmx_blend4_zero]
pmullw mm1, mm6
punpcklbw mm3, [mmx_blend4_zero]
psubw mm5, mm7
pmullw mm2, mm4
pmullw mm3, mm6
paddw mm0, mm1
// stall (mm0)
psrlw mm0, 8
// stall (waiting for mm3/mm2)
paddw mm2, mm3
pmullw mm0, mm5
psrlw mm2, 8
// stall (mm2)
pmullw mm2, mm7
// stall
// stall (mm2)
paddw mm0, mm2
// stall
psrlw mm0, 8
// stall
packuswb mm0, mm0
// stall
movd eax, mm0
}
#endif
}
static __inline unsigned int BLEND4_16(unsigned int *p1, unsigned int w, int xp, int yp)
{
#ifdef NO_MMX
register int t;
unsigned char a1,a2,a3,a4;
xp=(xp>>8)&0xff;
yp=(yp>>8)&0xff;
a1=g_blendtable[255-xp][255-yp];
a2=g_blendtable[xp][255-yp];
a3=g_blendtable[255-xp][yp];
a4=g_blendtable[xp][yp];
t=g_blendtable[p1[0]&0xff][a1]+g_blendtable[p1[1]&0xff][a2]+g_blendtable[p1[w]&0xff][a3]+g_blendtable[p1[w+1]&0xff][a4];
t|=(g_blendtable[(p1[0]>>8)&0xff][a1]+g_blendtable[(p1[1]>>8)&0xff][a2]+g_blendtable[(p1[w]>>8)&0xff][a3]+g_blendtable[(p1[w+1]>>8)&0xff][a4])<<8;
t|=(g_blendtable[(p1[0]>>16)&0xff][a1]+g_blendtable[(p1[1]>>16)&0xff][a2]+g_blendtable[(p1[w]>>16)&0xff][a3]+g_blendtable[(p1[w+1]>>16)&0xff][a4])<<16;
return t;
#else
__asm
{
movd mm6, xp
mov eax, p1
movd mm7, yp
mov esi, w
movq mm4, mmx_blend4_revn
psrlw mm6, 8
movq mm5, mmx_blend4_revn
psrlw mm7, 8
movd mm0, [eax]
punpcklwd mm6,mm6
movd mm1, [eax+4]
punpcklwd mm7,mm7
movd mm2, [eax+esi*4]
punpckldq mm6,mm6
movd mm3, [eax+esi*4+4]
punpckldq mm7,mm7
punpcklbw mm0, [mmx_blend4_zero]
psubw mm4, mm6
punpcklbw mm1, [mmx_blend4_zero]
pmullw mm0, mm4
punpcklbw mm2, [mmx_blend4_zero]
pmullw mm1, mm6
punpcklbw mm3, [mmx_blend4_zero]
psubw mm5, mm7
pmullw mm2, mm4
pmullw mm3, mm6
paddw mm0, mm1
// stall (mm0)
psrlw mm0, 8
// stall (waiting for mm3/mm2)
paddw mm2, mm3
pmullw mm0, mm5
psrlw mm2, 8
// stall (mm2)
pmullw mm2, mm7
// stall
// stall (mm2)
paddw mm0, mm2
// stall
psrlw mm0, 8
// stall
packuswb mm0, mm0
// stall
movd eax, mm0
}
#endif
}
#pragma warning( pop )
static __inline void mmx_avgblend_block(int *output, int *input, int l)
{
#ifdef NO_MMX
while (l--)
{
*output=BLEND_AVG(*input++,*output);
output++;
}
#else
static int mask[2]=
{
~((1<<7)|(1<<15)|(1<<23)),
~((1<<7)|(1<<15)|(1<<23))
};
__asm
{
mov eax, input
mov edi, output
mov ecx, l
shr ecx, 2
align 16
mmx_avgblend_loop:
movq mm0, [eax]
movq mm1, [edi]
psrlq mm0, 1
movq mm2, [eax+8]
psrlq mm1, 1
movq mm3, [edi+8]
psrlq mm2, 1
pand mm0, [mask]
psrlq mm3, 1
pand mm1, [mask]
pand mm2, [mask]
paddusb mm0, mm1
pand mm3, [mask]
add eax, 16
paddusb mm2, mm3
movq [edi], mm0
movq [edi+8], mm2
add edi, 16
dec ecx
jnz mmx_avgblend_loop
emms
};
#endif
}
static __inline void mmx_addblend_block(int *output, int *input, int l)
{
#ifdef NO_MMX
while (l--)
{
*output=BLEND(*input++,*output);
output++;
}
#else
__asm
{
mov eax, input
mov edi, output
mov ecx, l
shr ecx, 2
align 16
mmx_addblend_loop:
movq mm0, [eax]
movq mm1, [edi]
movq mm2, [eax+8]
movq mm3, [edi+8]
paddusb mm0, mm1
paddusb mm2, mm3
add eax, 16
movq [edi], mm0
movq [edi+8], mm2
add edi, 16
dec ecx
jnz mmx_addblend_loop
emms
};
#endif
}
static __inline void mmx_mulblend_block(int *output, int *input, int l)
{
#ifdef NO_MMX
while (l--)
{
*output=BLEND_MUL(*input++,*output);
output++;
}
#else
__asm
{
mov eax, input
mov edi, output
mov ecx, l
shr ecx, 1
align 16
mmx_mulblend_loop:
movd mm0, [eax]
movd mm1, [edi]
movd mm2, [eax+4]
punpcklbw mm0, [mmx_blend4_zero]
movd mm3, [edi+4]
punpcklbw mm1, [mmx_blend4_zero]
punpcklbw mm2, [mmx_blend4_zero]
pmullw mm0, mm1
punpcklbw mm3, [mmx_blend4_zero]
psrlw mm0, 8
pmullw mm2, mm3
packuswb mm0, mm0
psrlw mm2, 8
packuswb mm2, mm2
add eax, 8
movd [edi], mm0
movd [edi+4], mm2
add edi, 8
dec ecx
jnz mmx_mulblend_loop
emms
};
#endif
}
static void __inline mmx_adjblend_block(int *o, int *in1, int *in2, int len, int v)
{
#ifdef NO_MMX
while (len--)
{
*o++=BLEND_ADJ(*in1++,*in2++,inblendval);
}
#else
__asm
{
movd mm3, [v] // VVVVVVVV
mov ecx, len
packuswb mm3, mm3 // 0000HHVV
mov edx, o
punpcklwd mm3, mm3 // HHVVHHVV
mov esi, in1
movq mm4, [mmx_blend4_revn]
punpckldq mm3, mm3 // HHVVHHVV HHVVHHVV
pand mm3, [mmx_blendadj_mask]
mov edi, in2
shr ecx, 1
psubw mm4, mm3
align 16
_mmx_adjblend_loop:
movd mm0, [esi]
movd mm1, [edi]
punpcklbw mm0, [mmx_blend4_zero]
movd mm6, [esi+4]
punpcklbw mm1, [mmx_blend4_zero]
movd mm7, [edi+4]
punpcklbw mm6, [mmx_blend4_zero]
pmullw mm0, mm3
punpcklbw mm7, [mmx_blend4_zero]
pmullw mm1, mm4
pmullw mm6, mm3
pmullw mm7, mm4
paddw mm0, mm1
paddw mm6, mm7
add edi, 8
psrlw mm0, 8
add esi, 8
psrlw mm6, 8
packuswb mm0, mm0
packuswb mm6, mm6
movd [edx], mm0
movd [edx+4], mm6
add edx, 8
dec ecx
jnz _mmx_adjblend_loop
emms
};
#endif
}
class RString
{
public:
RString() { m_str=0; m_size=0; }
~RString() { if (m_str) GlobalFree(m_str); };
void resize(int size) { m_size=size; if (m_str) GlobalFree(m_str); m_str=0; if (size) m_str=(char*)GlobalAlloc(GPTR,size); }
char *get() { return m_str; }
int getsize() { if (!m_str) return 0; return m_size; }
void assign(char *s) { resize(strlen(s)+1); strcpy(m_str,s); }
void get_from_dlgitem(HWND hwnd, int dlgItem)
{
int l=SendDlgItemMessage(hwnd,dlgItem,WM_GETTEXTLENGTH,0,0);
if ( l < 256) l=256;
resize(l+1+256);
GetDlgItemText(hwnd,dlgItem, m_str, l+1);
m_str[l]=0;
}
private:
char *m_str;
int m_size;
};
void doAVSEvalHighLight(HWND hwndDlg, UINT sub, char *data);
#include "laser/laserline.h"
#endif
|