| 1 |
program cpr2tga; |
| 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 .CPR to .TGA (while preserving palette), |
| 22 |
on which we can use ImageMagick convert(1) or netpm tga2ppm(1) etc. to convert further - https://en.wikipedia.org/wiki/Truevision_TGA |
| 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, palname: String; |
| 33 |
i,j: word; |
| 34 |
temppal: paltype; |
| 35 |
has_palette: boolean; |
| 36 |
|
| 37 |
begin |
| 38 |
basename := paramstr(1); |
| 39 |
if basename = '' then |
| 40 |
begin |
| 41 |
writeln ('Usage: cpr2tga <BASENAME>'); |
| 42 |
writeln (' opens compressed BASENAME.cpr (and optionally BASENAME.pal if it exists) and creates uncompressed BASENAME.tga'); |
| 43 |
errorhandler('Wrong cmdline usage',6) |
| 44 |
end; |
| 45 |
|
| 46 |
has_palette := false; |
| 47 |
fillchar(screen,sizeof(screen),0); |
| 48 |
fillchar(colors,sizeof(colors),0); |
| 49 |
palname := basename + '.pal'; |
| 50 |
if FileExists(palname) then |
| 51 |
begin |
| 52 |
writeln ('Loading default palette from ', palname); |
| 53 |
loadpal (palname); { load default palette if it exists } |
| 54 |
has_palette := true; |
| 55 |
end; |
| 56 |
|
| 57 |
writeln ('Loading compressed file ', basename, '.cpr'); |
| 58 |
loadscreen(basename, @screen); |
| 59 |
if (cpr_head.flags and 1)=1 then has_palette:=true; |
| 60 |
|
| 61 |
if not has_palette then errorhandler(basename+'.cpr does not have palette, and .pal does not exist',5); |
| 62 |
|
| 63 |
{ update brightness and fix TGA R/G/B little-endian ordering } |
| 64 |
temppal[0,1] := 0; { move will initialize it, this is just to keep compiler warnings happy } |
| 65 |
move(colors,temppal,sizeof(paltype)); |
| 66 |
for i:=0 to 255 do |
| 67 |
for j:=1 to 3 do |
| 68 |
begin |
| 69 |
assert (colors[i,j] * COLOR_FACTOR <= 255, 'pal value too big'); |
| 70 |
colors[i,j] := temppal[i,4-j] * COLOR_FACTOR; |
| 71 |
end; |
| 72 |
|
| 73 |
{ write TARGA to disk } |
| 74 |
writeln ('Outputing ', cpr_head.width,'x', cpr_head.height,' uncompressed indexed TGA file to ', basename, '.tga'); |
| 75 |
savetga(basename, @screen); |
| 76 |
|
| 77 |
writeln ('Done!'); |
| 78 |
end. |