-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrwpal.pas
780 lines (694 loc) · 21.9 KB
/
rwpal.pas
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
{$mode TP}
{$PACKRECORDS 1}
unit rwpal;
interface
uses
SysUtils,LazFileUtils,RMCore,rmxgfcore,rwxgf,gwbasic;
Const
ColorIndexFormat = 1;
ColorFourBitFormat =2;
ColorSixBitFormat =3;
ColorEightBitFormat =4;
ColorOnePercentFormat = 5;
ColorTwoBitFormat = 6;
Function ReadPAL(Filename : String;pm : integer) : Word;
Function WritePAL(Filename : String) : Word;
function WritePalData(filename : string; Lan,rgbFormat : integer) : word;
function WritePalConstants(filename : string; Lan,rgbFormat : integer) : word;
function WritePalStatements(filename : string; Lan,rgbFormat : integer) : word;
function WriteRGBPackedPalArray(filename : string; Lan : integer; vsprite : boolean) : word;
procedure WritePalToArrayBuffer(var data : BufferRec;imagename : string; Lan,rgbFormat : integer);
procedure WritePalToBuffer(var data : BufferRec; rgbFormat : integer);
function WritePalToArrayFile(filename : string; Lan,rgbFormat : integer) : word;
function WritePalToFile(filename : string; rgbFormat : integer) : word;
implementation
type
PalType = Array[0..255,0..2] of Byte;
function GetPalSize(ncolors,rgbFormat : integer) : integer;
begin
if rgbFormat = ColorIndexFormat then GetPalSize:=nColors else GetPalSize:=nColors*3;
end;
function ColorFormatToStr(rgbFormat: integer) : string;
begin
ColorFormatToStr:='';
Case rgbFormat of ColorIndexFormat:ColorFormatToStr:='Color Index';
ColorFourBitFormat:ColorFormatToStr:='4 Bit';
ColorSixBitFormat:ColorFormatToStr:='6 Bit';
ColorEightBitFormat:ColorFormatToStr:='8 Bit';
ColorOnePercentFormat:ColorFormatToStr:='1 Percent';
ColorTwoBitFormat:ColorFormatToStr:='2 Bit';
end;
end;
function ColorValueToStr(Invalue,OutFormat : integer) : string;
begin
ColorValueToStr:='';
Case OutFormat of ColorIndexFormat:ColorValueToStr:=IntToStr(InValue);
ColorFourBitFormat:ColorValueToStr:=IntToStr(EightToFourBit(InValue));
ColorSixBitFormat:ColorValueToStr:=IntToStr(EightToSixBit(InValue));
ColorEightBitFormat:ColorValueToStr:=IntToStr(InValue);
ColorOnePercentFormat:ColorValueToStr:=FormatFloat('0.00',EightToFourBit(InValue)*0.0669);
ColorTwoBitFormat:ColorValueToStr:=IntToStr(EightToTwoBit(InValue));
end;
end;
function LanToStr(Lan: integer) : string;
begin
LanToStr:='';
Case Lan of ABLan:LanToStr:='AmigaBASIC';
APLan:LanToStr:='Amiga Pascal';
ACLan:LanToStr:='Amiga C';
PBLan:LanToStr:='Power/Turbo BASIC';
TPLan:LanToStr:='Turbo Pascal';
TCLan:LanToStr:='Turbo C';
GWLan:LanToStr:='GWBASIC/PC-BASIC';
QBLan:LanToStr:='QuickBASIC';
AQBLan:LanToStr:='Amiga QuickBasic';
QCLan:LanToStr:='QuickC';
QPLan:LanToStr:='QuickPascal';
FBLan:LanToStr:='FreeBASIC';
FBinQBModeLan:LanToStr:='FreeBASIC';
FPLan:LanToStr:='FreePascal';
OWLan:LanToStr:='Open Watcom C';
BAMLan:LanToStr:='BAM Basic';
TMTLan:LanToStr:='TMT Pascal';
end;
end;
function PaletteCmdToStr(Lan,ColorFormat : integer) : string;
begin
PaletteCmdToStr:='Palette';
if ((Lan=TPLan) OR (Lan=FPLan)) and (ColorFormat=ColorIndexFormat) then
begin
PaletteCmdToStr:='SetPalette(';
end
else if (Lan=TPLan) OR (Lan=FPLan) OR (Lan=TMTLan) then
begin
PaletteCmdToStr:='SetRGBPalette(';
end
else if (Lan=TCLan) and (ColorFormat=ColorIndexFormat) then
begin
PaletteCmdToStr:='setpalette(';
end
else if (Lan=TCLan) then
begin
PaletteCmdToStr:='setrgbpalette(';
end
else if (Lan=QCLan) or (Lan=OWLan) then
begin
PaletteCmdToStr:='_remappalette(';
end
else if (Lan=QPLan) then
begin
PaletteCmdToStr:='result:=_RemapPalette('; //need to have a variable result defined in QuickPascal programs
end
else if (Lan=PBLan) and (ColorFormat=ColorSixBitFormat) then //Turbo/PB do not support additional palette information for VGA rgb formula
begin //maybe in future will replacement function for PB
PaletteCmdToStr:='Call PaletteX('; //PaletteX is wrapper function - PB does not support palettes in VGA - see channel code on replacement function
end;
end;
function LineTrmToStr(Lan : integer) : string;
begin
LineTrmToStr:='';
Case Lan of QPLan,TPLan,FPLan,TMTLan,APLan:LineTrmToStr:=');';
TCLan,QCLan,ACLan,OWLan:LineTrmToStr:='};';
end;
end;
function CommentBeginToStr(Lan : integer) : string;
begin
CommentBeginToStr:=#39;
Case Lan of QPLan,TPLan,FPLan,TMTLan,APLan:CommentBeginToStr:='(*';
TCLan,QCLan,ACLan,OWLan:CommentBeginToStr:='/*';
end;
end;
function CommentEndToStr(Lan : integer) : string;
begin
CommentEndToStr:='';
Case Lan of QPLan,TPLan,FPLan,TMTLan,APLan:CommentEndToStr:='*)';
TCLan,QCLan,ACLan,OWLan:CommentEndToStr:='*/';
end;
end;
function CommandEndBracketToStr(Lan : integer) : string;
begin
CommandEndBracketToStr:=');';
Case Lan of ABLan,FBinQBModeLan,QBlan,PBLan,GWLan,BAMLan:CommandEndBracketToStr:='';
end;
end;
function FileNameToPaletteName(filename : string) : string;
begin
FileNameToPaletteName:=ExtractFileName(ExtractFileNameWithoutExt(filename));
end;
// write basic data statements just for basic compilers
function WritePalData(filename : string; Lan,rgbFormat : integer) : word;
var
NColors : integer;
BFormat : string;
F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr : string;
CR : TRMColorRec;
begin
SetCoreActive;
SetGWStartLineNumber(1000);
{$I-}
Assign(F,filename);
Rewrite(F);
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
Writeln(F,LineCountToStr(Lan),CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors, ' Format= ',BFormat);
For i:=0 to NColors-1 do
begin
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
WriteLn(F,LineCountToStr(Lan),'DATA ',cistr); //linecounttostr is blank unless is GWLan
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
WriteLn(F,LineCountToStr(Lan),'DATA ',rstr,', ',gstr,', ',bstr); //linecounttostr is blank unless js GWLan
end;
// inc(LineCounter,10);
end;
Close(F);
WritePalData:=IORESULT;
{$I+}
end;
//for C/pascal languages
function WritePalConstants(filename : string; Lan,rgbFormat : integer) : word;
var
NColors : integer;
BFormat : string;
F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr : string;
palettenamestr : string;
arraysize : integer;
CR : TRMColorRec;
begin
SetCoreActive;
{$I-}
Assign(F,filename);
Rewrite(F);
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
WriteLn(F,CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors,' Format=',BFormat,' ',CommentEndToStr(Lan));
palettenamestr:=filenametoPalettename(filename);
if rgbformat =ColorIndexFormat then
begin
arraysize:=NColors;
end
else
begin
arraysize:=Ncolors*3;
end;
If (Lan=TPlan) OR (Lan =FPLan) OR (Lan=QPlan) OR (Lan=TMTlan) OR (Lan = APLan) then
begin
Writeln(F,palettenamestr, ' : array[0..',arraysize-1,'] of byte = (');
end
Else if (Lan = QCLan) or (Lan = TCLan) or (Lan = OWLan) then
begin
Writeln(F,'char ',palettenamestr,'[',arraysize,'] = {');
end
Else if (Lan=ACLan) then
begin
Writeln(F,'UBYTE ',palettenamestr,'[',arraysize,'] = {');
end;
For i:=0 to NColors-1 do
begin
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
Write(F,cistr);
if (i<>NColors-1) then Write(F,',')
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
Write(F,' ',rstr,', ',gstr,', ',bstr);
if (i<>NColors-1) then //if its the last color we don't write a comma at end of line
begin
Write(F,',');
Writeln(F);
end;
end;
end;
writeln(F,LineTrmToStr(Lan));
Close(F);
WritePalConstants:=IORESULT;
{$I+}
end;
// palette command statement all languages
function WritePalStatements(filename : string; Lan,rgbFormat : integer) : word;
var
NColors : integer;
BFormat : string;
F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr :string;
pcmdstr : string;
LineTrmStr : string;
PBasicEndBracket : string;
CR : TRMColorRec;
begin
SetCoreActive;
SetGWStartLineNumber(1000);
{$I-}
Assign(F,filename);
Rewrite(F);
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
pcmdstr:=PaletteCmdToStr(Lan,rgbFormat);
LineTrmStr:=CommandEndBracketToStr(Lan);
Writeln(F,LineCountToStr(Lan),CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette Commands, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors,' Format=',BFormat,' ',CommentEndToStr(Lan));
For i:=0 to NColors-1 do
begin
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if ((Lan=QBLan) or (Lan=FBinQBModeLan) or (Lan=GWLan) or (Lan=PBLan) or (Lan=QCLan) or (Lan=QPLan) or (Lan=OWLan)) and (rgbFormat = ColorSixBitFormat) then
begin
cistr:=IntToStr(EightToSixBit(r)+(EightToSixBit(g)*256)+(EightToSixBit(b)*65536));
if (Lan=PBlan) then PBasicEndBracket:=')' else PBasicEndBracket:='';
WriteLn(F,LineCountToStr(Lan),pcmdstr,' ',i,', ',cistr,LineTrmStr,PBasicEndBracket); // only for Call PaletteX(index,color) otherwise normal Palette command structure
end
else if Lan=BAMLan then
begin
WriteLn(F,pcmdstr,' ',i,', _BGR(',b,',',g,',',r,')');
end
else if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
WriteLn(F,LineCountToStr(Lan),pcmdstr,' ',i,', ',cistr,LineTrmStr);
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
WriteLn(F,LineCountToStr(Lan),pcmdstr,' ',i,', ',rstr,', ',gstr,', ',bstr,LineTrmStr);
end;
// inc(LineCounter,10);
end;
Close(F);
WritePalStatements:=IORESULT;
{$I+}
end;
Function WritePAL(FileName : String): Word;
Var
F : File;
myPal : Array[0..255,0..2] of Byte;
Colors : Word;
Error : Word;
i : integer;
CR : TRMColorRec;
begin
SetCoreActive;
{$I-}
Colors:=GetMaxColor+1;
//GrabPaletteList(myPal,Colors);
For i:=0 to 255 do
begin
GetColor(i,CR);
myPal[i,0]:=CR.r;
myPal[i,1]:=CR.g;
myPal[i,2]:=CR.b;
end;
Assign(F,FileName);
Rewrite(F,1);
BlockWrite(F,myPAL,Colors*3);
Close(F);
Error:=IORESULT;
WritePAL:=Error;
{$I+}
end;
Function ReadPAL(Filename : String; pm : integer) : Word;
Var
F : File;
Fsize : LongInt;
Colors : word;
Error : Word;
myPal : Array[0..255,0..2] of Byte;
cr : TRMColorRec;
i : integer;
begin
SetCoreActive;
Colors:=GetMaxCOlor+1;
Assign(F,FileName);
Reset(F,1);
Fsize:=FIleSize(F);
If (Fsize<>6) AND (Fsize<>12) AND (Fsize<>24) AND (Fsize<>48) AND (Fsize<>96) AND (Fsize<>768) then
begin
ReadPAL:=1000;
Exit;
end;
Colors :=Fsize div 3;
if Colors > 256 then Colors:=256;
BlockRead(F,myPAL,Colors*3);
Close(F);
Error:=IORESULT;
ReadPAl:=Error;
If (CanLoadPaletteFile(pm)) and (Colors > 0) then //we do not load palette for mono and cga
begin
if pm=PaletteModeEGA then //if we are in ega palette mode we need to be able to remap rgb color ega64 palette
begin //if not we skip setting that color
for i:=0 to Colors-1 do
begin
cr.r:=mypal[i,0];
cr.g:=mypal[i,1];
cr.b:=mypal[i,2];
if RGBToEGAIndex(cr.r,cr.g,cr.b) > -1 then //if this returns an index to EGA color we can accept it
begin
// RMCoreBase.Palette.SetColor(i,cr);
SetColor(i,cr);
end;
end;
end
else if isAmigaPaletteMode(pm) then
begin
for i:=0 to Colors-1 do
begin
cr.r:=FourToEightBit(EightToFourBit(mypal[i,0]));
cr.g:=FourToEightBit(EightToFourBit(mypal[i,1]));
cr.b:=FourToEightBit(EightToFourBit(mypal[i,2]));
// RMCoreBase.Palette.SetColor(i,cr);
SetColor(i,cr);
end;
end
else if (pm=PaletteModeVGA) or (pm=PaletteModeVGA256) then
begin
for i:=0 to Colors-1 do
begin
cr.r:=SixToEightBit(EightToSixBit(mypal[i,0])); //we bitshift because if palette was saved when PaletteModeXga or PaletteModeXga256
cr.g:=SixToEightBit(EightToSixBit(mypal[i,1])); //we will have invalid values
cr.b:=SixToEightBit(EightToSixBit(mypal[i,2]));
// RMCoreBase.Palette.SetColor(i,cr);
SetColor(i,cr);
end;
end
else if (pm=PaletteModeXGA) or (pm=PaletteModeXGA256) then
begin
for i:=0 to Colors-1 do
begin
cr.r:=mypal[i,0];
cr.g:=mypal[i,1];
cr.b:=mypal[i,2];
// RMCoreBase.Palette.SetColor(i,cr);
SetColor(i,cr);
end;
end;
end;
end;
function WriteRGBPackedPalArray(filename : string; Lan : integer; vsprite : boolean) : word;
var
F : Text;
palettenamestr : string;
TR : TRMColorRec;
color : word;
startcol,endcol : word;
arsize : word;
i : word;
begin
SetCoreActive;
{$I-}
Assign(F,filename);
Rewrite(F);
palettenamestr:=filenametoPalettename(filename);
startcol:=0;
endcol:=GetMaxColor;
arsize:=endcol+1;
if vsprite then
begin
startcol:=1;
endcol:=3;
arsize:=3;
end;
If Lan = APlan then
begin
if vsprite then writeln(F,'(* VSprite Colors *)') else writeln(F,'(* LoadRGB4 Colors *)');
Writeln(F,' ',palettenamestr, ' : Array[1..',arsize,'] of WORD = (');
end
Else if Lan = ACLan then
begin
if vsprite then writeln(F,'/* VSprite Colors */') else writeln(F,'/* LoadRGB4 Colors */');
Writeln(F,' WORD ',palettenamestr,'[',arsize,'] = {');
end;
for i:=startcol to endcol do
begin
RMCoreBase.Palette.GetColor(i,TR);
Color:=(EightToFourBit(TR.r) SHL 8) + (EightToFourBit(TR.g) SHL 4) + EightToFourBit(TR.b);
if Lan=APLan then Write(F,' $',HexStr(Color,4));
if Lan=ACLAN then Write(F,' 0x',LowerCase(HexStr(Color,4)));
if i <> endcol then writeln(F,',')
end;
if Lan=APLan then writeln(F,');');
if Lan=ACLan then writeln(F,'};');
Close(F);
WriteRGBPackedPalArray:=IORESULT;
{$I+}
end;
function WritePalCPascalStatementsBuffer(var data : BufferRec; imagename : string; Lan,rgbFormat : integer) : word;
var
NColors : integer;
BFormat : string;
// F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr :string;
pcmdstr : string;
LineTrmStr : string;
// LineCounter : integer;
CR : TRMColorRec;
begin
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
pcmdstr:=PaletteCmdToStr(Lan,rgbFormat);
LineTrmStr:=LineTrmToStr(Lan);
// LineCounter:=1000;
Writeln(data.fText,CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette Commands, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors, ' Format=',BFormat,' ',CommentEndToStr(Lan));
For i:=0 to NColors-1 do
begin
(* r:=RMCoreBase.Palette.GetRed(i);
g:=RMCoreBase.Palette.GetGreen(i);
b:=RMCoreBase.Palette.GetBlue(i);
*)
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if (Lan=QBLan) and (rgbFormat = ColorSixBitFormat) then
begin
cistr:=IntToStr(EightToSixBit(r)+(EightToSixBit(g)*256)+(EightToSixBit(b)*65536));
WriteLn(data.fText,LineCountToStr(Lan),pcmdstr,' ',i,', ',cistr,LineTrmStr);
end
else if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
WriteLn(data.fText,LineCountToStr(Lan),pcmdstr,' ',i,', ',cistr,LineTrmStr);
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
WriteLn(data.fText,LineCountToStr(Lan),pcmdstr,' ',i,', ',rstr,', ',gstr,', ',bstr,LineTrmStr);
end;
// inc(LineCounter,10);
end;
{$I+}
end;
function WritePalBasicBuffer(var data : BufferRec; imagename : string; Lan,rgbFormat : integer) : word;
var
NColors : integer;
BFormat : string;
//F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr : string;
//LineCounter : integer;
CR : TRMColorRec;
begin
// LineCounter:=1000;
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
Writeln(data.fText,LineCountToStr(Lan),CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors,' Format=',BFormat);
For i:=0 to NColors-1 do
begin
(*
r:=RMCoreBase.Palette.GetRed(i);
g:=RMCoreBase.Palette.GetGreen(i);
b:=RMCoreBase.Palette.GetBlue(i);
*)
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
WriteLn(data.fText,LineCountToStr(Lan),'DATA ',cistr); //linecounttostr is blank unless is GWLan
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
WriteLn(data.fText,LineCountToStr(Lan),'DATA ',rstr,', ',gstr,', ',bstr); //linecounttostr is blank unless js GWLan
end;
// inc(LineCounter,10);
end;
end;
//for C/pascal languages
Procedure WritePalCPascalBuffer(var data : BufferRec;imagename : string; Lan,rgbFormat : integer);
var
NColors : integer;
BFormat : string;
// F : Text;
i : integer;
r,g,b : integer;
cistr,rstr,gstr,bstr : string;
palettenamestr : string;
arraysize : integer;
CR : TRMColorRec;
begin
NColors:=GetMaxColor+1;
BFormat:=ColorFormatToStr(rgbFormat);
WriteLn(data.fText,CommentBeginToStr(Lan),' ',LanToStr(Lan),' Palette, ',' Size= ',GetPalSize(nColors,rgbFormat),' Colors= ',NColors, ' Format= ',BFormat,' ',CommentEndToStr(Lan));
palettenamestr:=imagename;
if rgbformat =ColorIndexFormat then
begin
arraysize:=NColors;
end
else
begin
arraysize:=Ncolors*3;
end;
If (Lan = TPlan) OR (Lan = QPlan) OR (Lan =FPLan) OR (Lan = APLan) then
begin
Writeln(data.fText,palettenamestr, ' : array[0..',arraysize-1,'] of byte = (');
end
Else if (Lan = QCLan) or (Lan = TCLan) or (Lan = OWLan) then
begin
Writeln(data.fText,'char ',palettenamestr,'[',arraysize,'] = {');
end
Else if (Lan=ACLan) then
begin
Writeln(data.fText,'UBYTE ',palettenamestr,'[',arraysize,'] = {');
end;
For i:=0 to NColors-1 do
begin
(* r:=RMCoreBase.Palette.GetRed(i);
g:=RMCoreBase.Palette.GetGreen(i);
b:=RMCoreBase.Palette.GetBlue(i);
*)
GetColor(i,CR);
r:=CR.r;
g:=CR.g;
b:=CR.b;
if rgbFormat = ColorIndexFormat then
begin
cistr:=ColorValueToStr(RGBToEGAIndex(r,g,b),rgbFormat);
Write(data.fText,cistr);
if (i<>NColors-1) then Write(data.fText,',')
end
else
begin
rstr:=ColorValueToStr(r,rgbFormat);
gstr:=ColorValueToStr(g,rgbFormat);
bstr:=ColorValueToStr(b,rgbFormat);
Write(data.fText,' ',rstr,', ',gstr,', ',bstr);
if (i<>NColors-1) then //if its the last color we don't write a comma at end of line
begin
Write(data.fText,',');
Writeln(data.fText);
end;
end;
end;
writeln(data.fText,LineTrmToStr(Lan));
end;
//write c/pascal constants and basic data statements
procedure WritePalToArrayBuffer(var data : BufferRec;imagename : string; Lan,rgbFormat : integer);
begin
case Lan of BAMLan,ABLan,AQBLan,QBLan,PBLan,GWLAN,FBinQBModeLan:WritePalBasicBuffer(data,imagename,Lan,rgbFormat);
TPLan,QPLan,APLan,FPLan,TCLan,QCLan,ACLan,OWLan:WritePalCPascalBuffer(data,imagename,Lan,rgbFormat);
end;
end;
//write from RES called function
Procedure WritePalToBuffer(var data : BufferRec; rgbFormat : integer);
var
nColors : integer;
CR : TRMColorRec;
i : integer;
ColorBuf : array[0..767] of byte;
ColorBufEGA : array[0..15] of byte;
begin
nColors:=GetMaxColor+1;
for i:=0 to nColors-1 do
begin
GetColor(i,CR);
case rgbFormat of ColorIndexFormat: begin
ColorBufEGA[i]:=RGBToEGAIndex(CR.r,CR.g,CR.b);
end;
ColorOnePercentFormat,ColorFourBitFormat: begin
ColorBuf[i*3]:= EightToFourBit(cr.r);
ColorBuf[i*3+1]:= EightToFourBit(cr.g);
ColorBuf[i*3+2]:= EightToFourBit(cr.b);
end;
ColorSixBitFormat: begin
ColorBuf[i*3]:= EightToSixBit(cr.r);
ColorBuf[i*3+1]:= EightToSixBit(cr.g);
ColorBuf[i*3+2]:= EightToSixBit(cr.b);
end;
ColorEightBitFormat: begin
ColorBuf[i*3]:= cr.r;
ColorBuf[i*3+1]:= cr.g;
ColorBuf[i*3+2]:= cr.b;
end;
end;
end;
if rgbFormat = ColorIndexFormat then BlockWrite(data.f,ColorBufEGA,ncolors)
else Blockwrite(data.f,ColorBuf,nColors*3);
end;
function WritePalToArrayFile(filename : string; Lan,rgbFormat : integer) : word;
var
data : BufferRec;
imagename : string;
begin
SetCoreActive;
SetGWStartLineNumber(1000);
{$I-}
Assign(data.fText,filename);
Rewrite(data.fText);
WritePalToArrayBuffer(data,imagename,Lan,rgbformat);
Close(data.fText);
{$I+}
WritePalToArrayFile:=IORESULT;
end;
function WritePalToFile(filename : string; rgbFormat : integer) : word;
var
data : BufferRec;
begin
SetCoreActive;
Assign(data.f,FileName);
{$I-}
Rewrite(data.f,1);
WritePalToBuffer(data,rgbformat);
Close(data.f);
{$I+}
WritePalToFile:=IORESULT;
end;
begin
end.