-
Notifications
You must be signed in to change notification settings - Fork 7
/
video.h
1832 lines (1506 loc) · 50.1 KB
/
video.h
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
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is part of: Geiss screensaver and Winamp music visualization plug-in
// ___ ___ ___ ___ ___
// / __| __|_ _/ __/ __|
// | (_ | _| | |\__ \__ \
// \___|___|___|___/___/
// 3-Clause BSD License
//
// Copyright (c) 1998-2022 Ryan Geiss (@geissomatik)
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. 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.
//
// 3. Neither the name of the copyright holder 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 HOLDER 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 GEISS_VIDEO
#define GEISS_VIDEO 1
// this file contains:
// 1. merge_all_vs() functions (320 and regular)
// 2. palette functions
// 3. loadimage and screenshot functions
#define y_inc 18
#define MY_TEXT_COLOR RGB(255, 240, 125) //RGB( 140, 140, 240 )
#if PLUGIN
void Check_For_New_Song_Title()
{
// get song name (as a text string)
char g_newtitle[256];
if (g_bDisableSongTitlePopups) return;
if (g_hit >= 0) return;
if (1)//(intframe%5)==0 || g_hit>0)//==g_song_tooltip_frames)
{
::GetWindowText(this_mod_hwndParent, g_newtitle, sizeof(g_newtitle));
// remove '- Winamp' or '- Winamp [Paused]' at end
if (strlen(g_newtitle) > 8)
{
int check_pos = strlen(g_newtitle) - 8;
if (strcmp("- Winamp", (char *)(g_newtitle + check_pos)) == 0)
g_newtitle[check_pos] = 0;
}
if (strlen(g_newtitle) > 17)
{
int check_pos = strlen(g_newtitle) - 17;
if (strcmp("- Winamp [Paused]", (char *)(g_newtitle + check_pos)) == 0)
g_newtitle[check_pos] = 0;
}
// remove song # and period
if (strlen(g_newtitle) > 6)
{
int dot_pos = 1;
int len = strlen(g_newtitle);
while (dot_pos < len && dot_pos < 6)
{
if (g_newtitle[dot_pos-1] == '.' && g_newtitle[dot_pos] == ' ')
{
for (int i = dot_pos; i < len; i++)
g_newtitle[i - dot_pos] = g_newtitle[i];
g_newtitle[len - dot_pos] = 0;
break;
}
dot_pos++;
}
}
if (strcmp(g_newtitle, g_song_title) != 0)
{
g_title_R = 128 + rand() % 99;
g_title_G = 128 + rand() % 99;
g_title_B = 128 + rand() % 99;
strcpy(g_song_title, g_newtitle);
if (!g_LastMessageWasCustom)
{
g_hit = g_song_tooltip_frames*fps_at_last_mode_switch/30.0f;
}
g_LastMessageWasCustom = false;
}
}
}
#endif
#if (GRFX==1)
void Plop_Songtitle_Using_Backbuffer_As_Scratch(int phase)
{
// phase = 0: we haven't copied VS to backbuffer yet; so we must textout to backbuffer & copy to VS
// phase = 1: we textout to the back buffer just before the page flip
/*
#if PLUGIN
if (g_bDisableSongTitlePopups)
{
return;
}
#endif
*/
// merge into VS
if (g_hit >= 2)// && g_hit <= g_song_tooltip_frames)
{
HDC hdc;
//g_song_title_y = FXH/2;
//g_song_title_x = FXW/2;
HRESULT ddrval;
LPDIRECTDRAWSURFACE lpDDSurf = lpDDSBack;
if ((ddrval = lpDDSurf->GetDC(&hdc)) == DD_OK)
{
// load font if not loaded
if ( g_title_font==NULL &&
#if PLUGIN
!g_bDisableSongTitlePopups &&
#endif
FXW>320 )
{
dumpmsg("calling CreateFont()");
g_title_font = CreateFont(
// best combination so far: 24x10 with 700 thickness
24, //height - 24
10, //width - 10
0,
0,
700, // thickness/strength - 400 normal, 700 bold
false, //italics - looks good!
false, //underline
false, //strikethrough
DEFAULT_CHARSET,
OUT_DEFAULT_PRECIS,
CLIP_DEFAULT_PRECIS,
DEFAULT_QUALITY,
VARIABLE_PITCH | FF_DONTCARE,
NULL
);
dumpmsg("finished CreateFont()");
}
if (g_title_font)
{
SelectObject(hdc, g_title_font);
}
SIZE siz;
::GetTextExtentPoint(hdc, g_song_title, lstrlen(g_song_title), &siz);
int y_range = (FXH - FX_YCUT_HIDE*2 - siz.cy);
int x_range = (FXW-siz.cx);
static int g_hit_prev = -1;
if (g_hit_prev < g_hit)//(g_hit==g_song_tooltip_frames)
{
if (x_range > 0)
g_song_title_x = (rand() % (x_range/4)) +
(rand() % (x_range/4)) +
(rand() % (x_range/4)) +
(rand() % (x_range/4));
else
g_song_title_x = 0;
g_song_title_y = FX_YCUT_HIDE +
(rand() % (y_range/4)) +
(rand() % (y_range/4)) +
(rand() % (y_range/4)) +
(rand() % (y_range/4));
//g_song_title_x = x_range/3 + rand() % (x_range/3);
//g_song_title_y = FX_YCUT_HIDE + y_range/3 + rand() % (y_range/3);
}
g_hit_prev = g_hit;
//SetBkColor( hdc, RGB( 1, 1, 1 ) );
SetBkColor( hdc, RGB( 0, 0, 0 ) ); // hopefully fixes the white-palette WHITE BLOCK shown during song title popups
if (g_hit==2)
//if (g_hit>=2 && g_hit<=8)
{
SetBkMode( hdc, OPAQUE );
}
else
{
SetBkMode( hdc, TRANSPARENT );
}
if (g_hit>2)
//if (g_hit>8)
{
SetTextColor( hdc, RGB( 20, 20, 20 ) );
TextOut( hdc, g_song_title_x+1, g_song_title_y+1, g_song_title, lstrlen(g_song_title) );
}
if (g_hit>2 || (g_hit==2 && phase==0))
//if (g_hit>8 || (g_hit>=2 && g_hit<=8 && phase==0))
{
SetTextColor( hdc, RGB( 225, 225, 225 ) );
TextOut( hdc, g_song_title_x, g_song_title_y, g_song_title, lstrlen(g_song_title) );
}
lpDDSurf->ReleaseDC(hdc);
//---------------------------------------------
// now copy from backbuffer (scratchpad) to VS.
//---------------------------------------------
if (g_hit==2 && phase==0)
//if (g_hit>=2 && g_hit <= 8 && phase==0)
{
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(ddsd);
// lock the buffer
HRESULT ddrval = lpDDSurf->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
if (ddrval == DD_OK)
{
unsigned char *dest = (unsigned char *)ddsd.lpSurface;
unsigned char *dest2 = NULL;
int linesize = ddsd.lPitch;
int x, y;
int vs_index;
int first_x = g_song_title_x;
int last_x = min(FXW-2, g_song_title_x + siz.cx);
if (iDispBits==8)
{
for (y=0; y<siz.cy; y++)
{
dest2 = (unsigned char *)(dest + linesize*(g_song_title_y + y));
vs_index = (g_song_title_y + y)*FXW + g_song_title_x;
for (x = first_x; x < last_x; x++)
{
if (dest2[x] > 1) VS1[vs_index] = 225;
vs_index++;
}
}
}
else
{
int lookat_inc = 0;
if (iDispBits==32) lookat_inc = 4;
if (iDispBits==24) lookat_inc = 3;
if (iDispBits==16) lookat_inc = 2;
//int lookat_inc = (iDispBits==16) ? 2 : 4; // 3.40
first_x *= lookat_inc;
last_x *= lookat_inc;
for (y=0; y<siz.cy; y++)
{
dest2 = (unsigned char *)(dest + linesize*(g_song_title_y + y));
vs_index = ((g_song_title_y + y)*FXW + g_song_title_x) << 2;
for (x = first_x; x < last_x; x += lookat_inc)
{
if (dest2[x] > 1)
{
VS1[vs_index ] = g_title_R;//225;
VS1[vs_index + 1] = g_title_G;//225;
VS1[vs_index + 2] = g_title_B;//225;
}
vs_index += 4;
}
}
}
ddrval = lpDDSurf->Unlock(NULL);
if (ddrval != DD_OK)
{
dumpmsg("Plop_Songtitle_Using_Backbuffer_As_Scratch: lpDDSurf->Unlock() failed");
//Try_To_Recover(lpDDSurf, ddrval, true);
return;
}
}
else
{
dumpmsg("Plop_Songtitle_Using_Backbuffer_As_Scratch: lpDDSurf->Lck() failed");
//Try_To_Recover(lpDDSurf, ddrval, true);
return;
}
}
}
else
{
dumpmsg("Plop_Songtitle_Using_Backbuffer_As_Scratch: lpDDSurf->GetDC() failed");
//Try_To_Recover(lpDDSurf, ddrval, true);
return;
}
}
}
void Merge_All_VS_To_Backbuffer()
{
unsigned char *dest = NULL;
unsigned int linesize, linesize_over_FXW, linesize_over_FXW4, linesize_over_FXW3, half_linesize, quarter_linesize, linesize_over_FXW2;
unsigned int FX_YCUT_HIDE_xFXW4 = FX_YCUT_HIDE*FXW*4;
unsigned long FX_YCUT_HIDE_xLINESIZE;
unsigned long LINES_TO_DISPLAY;
unsigned __int16 FXW_DIV_4 = FXW/4;
clock_t temp_clock = clock();
WORD *worddest = NULL;
DWORD *dworddest = NULL;
DWORD pos1, pos2;
unsigned char clr1, clr2, clr3;
unsigned __int16 w;
unsigned __int32 dw;
unsigned long x2, y2, offset;//, x, y, bx2, by2, x_times_4, y_offset, offset;
unsigned __int16 FXW_DIV_2 = FXW/2;
unsigned __int16 FXW_DIV_8 = FXW/8;
unsigned __int16 FXW_DIV_16 = FXW/16;
unsigned __int16 FXW_DIV_32 = FXW/32;
unsigned __int16 FXW_DIV_40 = FXW/40;
DDSURFACEDESC ddsd;
ddsd.dwSize = sizeof(ddsd);
// lock the buffer
HRESULT ddrval = lpDDSBack->Lock(NULL, &ddsd, DDLOCK_WAIT, NULL);
//if (rand()%40==0) Try_To_Recover(lpDDSBack, ddrval+1, true);
if (ddrval != DD_OK)
{
// crazy crack patch for when the program comes back from SC_MONITORPOWER
// state and the palette won't be attached for a while
iBlendsLeftInPal = 3;
//Try_To_Recover(lpDDSBack, ddrval, true);
//dumpmsg("Merge_All_VS_To_Backbuffer: lpDDSBack->Lock() failed");
return;
/*
switch(ddrval)
{
case DDERR_INVALIDOBJECT: dumpmsg(" [DDERR_INVALIDOBJECT]"); break;
case DDERR_INVALIDPARAMS: dumpmsg(" [DDERR_INVALIDPARAMS]"); break;
case DDERR_SURFACEBUSY: dumpmsg(" [DDERR_SURFACEBUSY]"); break;
case DDERR_SURFACELOST: dumpmsg(" [DDERR_SURFACELOST]"); break;
case DDERR_WASSTILLDRAWING: dumpmsg(" [DDERR_WASSTILLDRAWING]"); break;
case DDERR_OUTOFMEMORY: dumpmsg(" [DDERR_OUTOFMEMORY]"); break;
case DD_OK: dumpmsg(" [OK]"); break;
default: dumpmsg(" [UNKNOWN]"); break;
}
if (ddrval==DDERR_SURFACELOST)
{
dumpmsg("Calling ->Restore()...");
ddrval = lpDDSBack->Restore();
switch(ddrval)
{
case DDERR_INVALIDOBJECT: dumpmsg(" [DDERR_INVALIDOBJECT]"); break;
case DDERR_INVALIDPARAMS: dumpmsg(" [DDERR_INVALIDPARAMS]"); break;
case DDERR_GENERIC: dumpmsg(" [DDERR_GENERIC]"); break;
case DDERR_IMPLICITLYCREATED: dumpmsg(" [DDERR_IMPLICITLYCREATED]"); break;
case DDERR_INCOMPATIBLEPRIMARY: dumpmsg(" [DDERR_INCOMPATIBLEPRIMARY]"); break;
case DDERR_OUTOFMEMORY: dumpmsg(" [DDERR_OUTOFMEMORY]"); break;
case DDERR_NOEXCLUSIVEMODE: dumpmsg(" [DDERR_NOEXCLUSIVEMODE]"); break;
case DDERR_UNSUPPORTED: dumpmsg(" [DDERR_UNSUPPORTED]"); break;
case DDERR_WRONGMODE: dumpmsg(" [DDERR_WRONGMODE]"); break;
case DD_OK: dumpmsg(" [OK]"); break;
default: dumpmsg(" [UNKNOWN]"); break;
}
}
return; // we'll get it right next time.
//Try_To_Recover(lpDDSBack, ddrval, true);
*/
}
//stuff
dest = (unsigned char *)ddsd.lpSurface;
worddest = (WORD *)ddsd.lpSurface;
dworddest = (DWORD *)ddsd.lpSurface;
if (intframe==30) clearframes = max(clearframes, 3);
#if PLUGIN
if (intframe==80) clearframes = max(clearframes, 3);
#endif
#if SAVER
if (intframe==25 && !g_bDisableCdControls && g_bAutostartCD)
{
//dumpmsg(" -ready to autostart CD. Checking current state.");
//CheckForNewCD();
dumpmsg(" -issuing cdaudio commands.");
if (eDiscState == PAUSED)
{
SHOW_TRACK_MSG = 30;
eDiscState = PLAYING;
mciSendString("resume cdaudio wait",NULL,NULL,NULL);
}
else if (eDiscState == STOPPED)
{
SHOW_TRACK_MSG = 30;
eDiscState = PLAYING;
mciSendString("stop cdaudio",NULL,NULL,NULL);
mciSendString("seek cdaudio to 1", NULL, NULL, NULL);
mciSendString("play cdaudio",NULL,NULL,NULL);
}
dumpmsg(" -cdaudio commands complete.");
}
#endif
if (intframe<20)
{
dumpmsg("[frame %d/20 ok]", intframe);
}
if (clearframes > 0)//(intframe <= 4)
{
dumpmsg("frame %d: clearing edges", intframe);
//temp_clock = clock();
clearframes--;
memset(ddsd.lpSurface, 0, ddsd.lPitch*FXH);
//clock_debt += (clock() - temp_clock);
}
//memset((unsigned char *)(dest + (intframe%CurVideoHeight)*ddsd.lPitch), 0, ddsd.lPitch);
if (!bLocked)
{
if (y_map_pos == -1) FX_Pick_Random_Mode(); // sets global 'mode' to a valid random number.
GenerateChunkOfNewMap();
/*
if (--frames_til_auto_switch == 0)
{
frames_til_auto_switch = 1000;
FX_Pick_Random_Mode();
GenerateChunkOfNewMap();
FX_Random_Palette();
}
*/
}
linesize = ddsd.lPitch;
half_linesize = linesize/2;
quarter_linesize = linesize/4;
linesize_over_FXW = linesize-FXW; // 768
linesize_over_FXW2 = linesize-FXW*2;
linesize_over_FXW3 = linesize-FXW*3;
linesize_over_FXW4 = linesize-FXW*4;
//linesize_over_FXW8 = linesize-FXW*8;
FX_YCUT_HIDE_xLINESIZE = FX_YCUT_HIDE * linesize;
LINES_TO_DISPLAY = (FXH-FX_YCUT_HIDE*2);
//dumpmsg("ltd=%d", LINES_TO_DISPLAY);
//dumpmsg("linesize_over_FXW=%d", linesize_over_FXW);
if (iDispBits==8)
{
if (bMMX) // use MMX copy over memcpy()
{
if (FXW%32 == 0) // we can do 32 bytes per loop
__asm
{
push edi
push esi
mov edi, dworddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW
// [edi] is start pt. on back surface
// [eax] points to VS1
// ecx is the loop counter
// ebx holds linesize_over_FXW
mov ebx, linesize_over_FXW
mov ecx, LINES_TO_DISPLAY
Scanline_Loop3:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_32
PixelChunk_Loop3:
// load, saturate & store the red, green, & blue values
MOVQ mm0, [eax] // read 8 bgrx pixels
MOVQ mm1, [eax+8] // read 8 bgrx pixels
MOVQ mm2, [eax+16] // read 8 bgrx pixels
MOVQ mm3, [eax+24] // read 8 bgrx pixels
MOVQ [edi], mm0
MOVQ [edi+8], mm1
MOVQ [edi+16], mm2
MOVQ [edi+24], mm3
ADD eax, 32
ADD edi, 32
dec cx
jnz PixelChunk_Loop3
add edi, ebx // extra bytes per line
shr ecx, 16
dec cx
jnz Scanline_Loop3
EMMS
pop esi
pop edi
}
else if (FXW%40==0)
__asm // use MMX over memcpy()
{
push edi
push esi
mov edi, dworddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW
// [edi] is start pt. on back surface
// [eax] points to VS1
// ecx is the loop counter
// ebx holds linesize_over_FXW
mov ebx, linesize_over_FXW
mov ecx, LINES_TO_DISPLAY
Scanline_Loop3b:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_40
PixelChunk_Loop3b:
// load, saturate & store the red, green, & blue values
MOVQ mm0, [eax] // read 8 bgrx pixels
MOVQ mm1, [eax+8] // read 8 bgrx pixels
MOVQ mm2, [eax+16] // read 8 bgrx pixels
MOVQ mm3, [eax+24] // read 8 bgrx pixels
MOVQ mm4, [eax+32] // read 8 bgrx pixels
MOVQ [edi], mm0
MOVQ [edi+8], mm1
MOVQ [edi+16], mm2
MOVQ [edi+24], mm3
MOVQ [edi+32], mm4
ADD eax, 40
ADD edi, 40
dec cx
jnz PixelChunk_Loop3b
add edi, ebx // extra bytes per line
shr ecx, 16
dec cx
jnz Scanline_Loop3b
EMMS
pop esi
pop edi
}
else
{
dumpmsg("BAD VIDEO MODE: (FXH %% 32 != 0 and FXH %% 40 != 0)");
}
}
else
{
if (linesize==FXW)
{
offset = FX_YCUT_HIDE*FXW;
pos1 = FX_YCUT_HIDE*linesize;
memcpy(&dest[pos1], &VS1[offset], (FXH-FX_YCUT_HIDE*2)*FXW );
}
else
{
offset = FX_YCUT_HIDE*FXW;
for (y2 = FX_YCUT_HIDE; y2<(FXH-FX_YCUT_HIDE); y2++)
{
pos1 = y2*linesize;
memcpy(&dest[pos1], &VS1[offset], FXW);
offset += FXW;
}
}
}
}
else if (iDispBits==16)
{
if (!bMMX)
{
unsigned __int32 *VSX = (unsigned __int32 *)VS1;
unsigned __int32 val;
unsigned __int8 val1, val2, val3;
offset = FX_YCUT_HIDE*FXW;
if (VIDEO_CARD_FUCKED==1)
for (y2 = FX_YCUT_HIDE; y2<(FXH-FX_YCUT_HIDE); y2++)
{
pos1 = y2*(linesize/2); // .../2 because we're writing WORDs
for (x2 = 0; x2<FXW; x2++)
{
val = VSX[offset++];
//val1 = REMAP[(val >> 16) ];
//val2 = REMAP[(val >> 8) & 255];
//val3 = REMAP[(val ) & 255];
//worddest[pos1++] = ((val1 >> 3) << 10) | ((val2 >> 3) << 5) | (val3 >> 3);
val1 = REMAP[(val >> 16) ];
val2 = REMAP[(val >> 8) & 255];
val3 = REMAP[(val ) & 255];
worddest[pos1++] = ((val1 ) << 10) | ((val2 ) << 5) | (val3 );
}
}
else
for (y2 = FX_YCUT_HIDE; y2<(FXH-FX_YCUT_HIDE); y2++)
{
pos1 = y2*(linesize/2); // .../2 because we're writing WORDs
for (x2 = 0; x2<FXW; x2++)
{
val = VSX[offset++];
//val1 = REMAP[(val >> 16) ];
//val2 = REMAP[(val >> 8) & 255];
//val3 = REMAP[(val ) & 255];
//worddest[pos1++] = ((val1 >> 3) << 11) | ((val2 >> 2) << 5) | (val3 >> 3);
val1 = REMAP2[(val >> 16) ];
val2 = REMAP2[(val >> 8) & 255];
val3 = REMAP2[(val ) & 255];
worddest[pos1++] = ((val1 >> 1 ) << 11) | ((val2 ) << 5) | (val3 >> 1 );
}
}
}
else
{
// special MMX optimization for going FXWxFXHx16 display mode
if (VIDEO_CARD_FUCKED==1)
__asm
{
push edi
push esi
mov edi, worddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW4
// [edi] is start pt. on back surface
// [eax] points to VS1
// ecx is the loop counter
// ebx holds linesize_over_FXW (times 4)
mov ebx, linesize_over_FXW2
mov ecx, LINES_TO_DISPLAY
Scanline_Loop16b:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_2
PixelChunk_Loop16b:
MOVQ mm0, [eax] // read 64 bits [RGBxRGBx]
PADDUSB mm0, mm0 // saturate (gamma-correction)
MOVQ mm1, mm0
MOVQ mm2, mm0 //|????????rrrrrrrr|ggggggggbbbbbbbb|????????bbbbbbbb|ggggggggrrrrrrrr|
PSRLD mm0, 16+3 //|0000000000000000|00000000000rrrrr|0000000000000000|00000000000rrrrr|
PSRLD mm1, 8+3 //|0000000000000000|000rrrrrrrrggggg|0000000000000000|0000000000gggggg|
PSRLD mm2, 3 //|00000000000rrrrr|rrrggggggggbbbbb|0000000000000000|00000000000bbbbb|
PSLLD mm0, 32-5 //|rrrrr00000000000|0000000000000000|0000000000000000|00000000000rrrrr|
PSLLD mm1, 32-5 //|ggggg00000000000|0000000000000000|0000000000000000|0000000000gggggg|
PSLLD mm2, 32-5 //|bbbbb00000000000|0000000000000000|0000000000000000|00000000000bbbbb|
PSRLD mm0, 1 //|0rrrrr0000000000|0000000000000000|0000000000000000|00000000000rrrrr|
PSRLD mm1, 1+5 //|000000ggggg00000|0000000000000000|0000000000000000|0000000000gggggg|
PSRLD mm2, 1+5+5 //|00000000000bbbbb|0000000000000000|0000000000000000|00000000000bbbbb|
POR mm0, mm1
POR mm0, mm2 //|0rrrrrgggggbbbbb|0000000000000000|rrrrrggggggbbbbb|0000000000000000|
MOVQ mm1, mm0
PSRLQ mm0, 16
PSRLQ mm1, 32
POR mm0, mm1 //|????????????????|????????????????|0rrrrrgggggbbbbb|0rrrrrgggggbbbbb|
MOVD [edi], mm0 // puts lower 32 bits to memory (2 dest. pixels)
ADD eax, 8
ADD edi, 4
dec cx
jnz PixelChunk_Loop16b
add edi, ebx // extra bytes per line
shr ecx, 16
dec cx
jnz Scanline_Loop16b
EMMS
pop esi
pop edi
}
else
__asm
{
push edi
push esi
mov edi, worddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW4
// [edi] is start pt. on back surface
// [eax] points to VS1
// ecx is the loop counter
// ebx holds linesize_over_FXW (times 4)
mov ebx, linesize_over_FXW2
mov ecx, LINES_TO_DISPLAY
Scanline_Loop16a:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_2
// IF DOUBLING THE WORKLOAD:
//shr cx, 1
PixelChunk_Loop16a:
MOVQ mm0, [eax] // read 64 bits [RGBxRGBx]
PADDUSB mm0, mm0 // saturate (gamma-correction)
//MM0 (high half) MM1 (high half) MM2 (high half)
//----------------------------------- ----------------------------------- -----------------------------------
//|........rrrrrrrr|ggggggggbbbbbbbb|
MOVQ mm1, mm0 //|........rrrrrrrr|ggggggggbbbbbbbb| |........rrrrrrrr|ggggggggbbbbbbbb|
PSRLW mm0, 3 //|000........rrrrr|000ggggggggbbbbb| |........rrrrrrrr|ggggggggbbbbbbbb|
PSRLW mm1, 10 //|000........rrrrr|000ggggggggbbbbb| |0000000000......|0000000000gggggg|
PSLLW mm0, 11 //|rrrrr00000000000|bbbbb00000000000| |0000000000......|0000000000gggggg|
PSLLD mm1, 21 //|rrrrr00000000000|bbbbb00000000000| |00000gggggg00000|0000000000000000|
MOVQ mm2, mm0 //|rrrrr00000000000|bbbbb00000000000| |00000gggggg00000|0000000000000000| |rrrrr00000000000|bbbbb00000000000|
POR mm0, mm1 //|rrrrrgggggg00000|bbbbb00000000000| |rrrrr00000000000|bbbbb00000000000|
PSLLD mm2, 5 //|rrrrrgggggg00000|bbbbb00000000000| |00000000000bbbbb|0000000000000000|
POR mm0, mm2 //|rrrrrggggggbbbbb|bbbbb00000000000|rrrrrggggggbbbbb|bbbbb00000000000|
PSRLD mm0, 16 //|0000000000000000|rrrrrggggggbbbbb|0000000000000000|rrrrrggggggbbbbb|
MOVQ mm1, mm0
PSRLQ mm1, 16
POR mm0, mm1
MOVD [edi], mm0 // puts lower 32 bits to memory (2 16-bit RGB quantities == 2 pixels)
ADD eax, 8//16//8
ADD edi, 4//8//4
dec cx
jnz PixelChunk_Loop16a
add edi, ebx // extra bytes per line
shr ecx, 16
dec cx
jnz Scanline_Loop16a
EMMS
pop esi
pop edi
}
}
}
else if (iDispBits==24)
{
//if (bMMX)
__asm
{
push edi
push esi
mov edi, dworddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW4
mov esi, eax
// [esi] points to VS1
// [edi] is start pt. on back surface
// ecx is the loop counter
mov ebx, linesize_over_FXW3
mov ecx, LINES_TO_DISPLAY
Scanline_Loop4:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_8
PixelChunk_Loop4:
mov eax, dword ptr [esi]
mov ebx, dword ptr [esi+4]
mov edx, dword ptr [esi+8]
// fill high byte of EAX w/ 'r' of pixel #2
rol eax, 8
mov al, bl
ror eax, 8
// fill high word of EBX with 'g' and 'b' of pixel #3
rol ebx, 8
mov bx, dx
ror ebx, 16
// fill bottom 3 bytes of edx with value of pixel #4
mov edx, [esi+12]
rol edx, 8
mov dl, [esi+10] //!
// write four pixels, packed into 3 [eax:ebx:edx]
mov [edi], eax
mov [edi+4], ebx
mov [edi+8], edx
add esi, 16
add edi, 12
mov eax, dword ptr [esi]
mov ebx, dword ptr [esi+4]
mov edx, dword ptr [esi+8]
// fill high byte of EAX w/ 'r' of pixel #2
rol eax, 8
mov al, bl
ror eax, 8
// fill high word of EBX with 'g' and 'b' of pixel #3
rol ebx, 8
mov bx, dx
ror ebx, 16
// fill bottom 3 bytes of edx with value of pixel #4
mov edx, [esi+12]
rol edx, 8
mov dl, [esi+10] //!
// write four pixels, packed into 3 [eax:ebx:edx]
mov [edi], eax
mov [edi+4], ebx
mov [edi+8], edx
add esi, 16
add edi, 12
dec cx
jnz PixelChunk_Loop4
add edi, linesize_over_FXW3 //ebx // extra bytes per line
shr ecx, 16
dec cx
jnz Scanline_Loop4
EMMS
pop esi
pop edi
}
/*
else
{
// with gamma correction:
unsigned __int32 val;
unsigned __int8 val1, val2, val3;
unsigned __int32 *VSX = (unsigned __int32 *)VS1;
int x;
offset = FX_YCUT_HIDE*FXW;
for (y2 = FX_YCUT_HIDE; y2<(FXH-FX_YCUT_HIDE); y2++)
{
pos1 = y2*linesize;
for (x=0; x<FXW; x++)
{
val = VSX[offset++];
dest[pos1] = REMAP[(val >> 16) ];
dest[pos1+1] = REMAP[(val >> 8) & 255];
dest[pos1+2] = REMAP[(val ) & 255];
pos1 += 3;
}
}
}
*/
}
else if (iDispBits==32)
{
if (bMMX)
__asm
{
push edi
push esi
mov edi, dworddest
add edi, FX_YCUT_HIDE_xLINESIZE
mov eax, VS1
add eax, FX_YCUT_HIDE_xFXW4
// [edi] is start pt. on back surface
// [eax] points to VS1
// ecx is the loop counter
// ebx holds linesize_over_FXW (times 4)
mov ebx, linesize_over_FXW4
mov ecx, LINES_TO_DISPLAY
Scanline_Loop5:
// upper word of ECX: # of scanlines left
// lower word of ECX: # of pixels left in current scanline.
shl ecx, 16
mov cx, FXW_DIV_16
PixelChunk_Loop5:
// load, saturate & store the red, green, & blue values
MOVQ mm0, [eax] // read 2 bgrx pixels
MOVQ mm1, [eax+8] // read 2 bgrx pixels
MOVQ mm2, [eax+16] // read 2 bgrx pixels
MOVQ mm3, [eax+24] // read 2 bgrx pixels
MOVQ mm4, [eax+32] // read 2 bgrx pixels
MOVQ mm5, [eax+40] // read 2 bgrx pixels
MOVQ mm6, [eax+48] // read 2 bgrx pixels
MOVQ mm7, [eax+56] // read 2 bgrx pixels
PADDUSB mm0, mm0
PADDUSB mm1, mm1