Debian Codegraph @

Data_Generators/misc/tga2cpr.pas

raw
1 program tga2cpr;
2 (********************************************************************
3 This program is free software: you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation, either version 3 of the License, or
6 (at your option) any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <https://www.gnu.org/licenses/>.
15
16 On Debian systems, the complete text of the GNU General Public
17 License, version 3, can be found in /usr/share/common-licenses/GPL-3.
18 ********************************************************************)
19
20 {*********************************************
21 Data Generator: Converts .TGA back to .CPR (while preserving palette)
22 see https://en.wikipedia.org/wiki/Truevision_TGA for Targa format
23
24 Copyright:
25 2020 Matija Nalis <[email protected]>
26 **********************************************}
27
28 uses data2, sysutils;
29
30 const COLOR_FACTOR = 4;
31
32 var basename: String;
33 i,j: word;
34 temppal: paltype;
35 flags: byte;
36 w,h: word;
37
38 begin
39 basename := paramstr(1);
40 if basename = '' then
41 begin
42 writeln ('Usage: tga2cpr <BASENAME>');
43 writeln (' opens somewhat standard BASENAME.tga and creates compressed BASENAME.cpr');
44 errorhandler('Wrong cmdline usage',6)
45 end;
46
47 flags := 1;
48 w := 320;
49 h := 200;
50 fillchar(screen,sizeof(screen),0);
51 fillchar(colors,sizeof(colors),0);
52
53 writeln ('Loading uncompressed file ', basename, '.tga');
54 loadtga(basename+'.tga');
55 w := tga_head.width;
56 h := tga_head.height;
57
58 { update brightness and fix TGA R/G/B little-endian ordering }
59 temppal[0,1] := 0; { move will initialize it, this is just to keep compiler warnings happy }
60 move(colors,temppal,sizeof(paltype));
61
62 for i:=0 to 255 do
63 for j:=1 to 3 do
64 colors[i,j] := temppal[i,4-j] div COLOR_FACTOR;
65
66 { write CPR to disk }
67 writeln ('Saving ', w,'x', h,' compressed file ', basename, '.cpr with flags=', flags);
68 compressfile (basename, @screen,w,h,flags);
69
70 writeln ('Done!');
71 end.
72