| 1 |
#!/usr/bin/perl |
| 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 |
# Copyright: |
| 20 |
# 2020 Matija Nalis <[email protected]> |
| 21 |
|
| 22 |
# |
| 23 |
# Data Generator: converts data/icons.vga & data/main.pal to standard ppm(5) P3 ASCII image |
| 24 |
# |
| 25 |
|
| 26 |
use strict; |
| 27 |
use warnings; |
| 28 |
use autodie qw/:all/; |
| 29 |
|
| 30 |
my $COLOR_FACTOR = $ENV{COLORF} || 4; # game seems to be using <<2, which is *4 |
| 31 |
|
| 32 |
my $scr = shift; |
| 33 |
my $pal = shift; |
| 34 |
my $width = $ENV{WIDTH} || 15; |
| 35 |
my $height = $ENV{HEIGHT} || 17; |
| 36 |
my $icon_count = $ENV{COUNT} || 81; |
| 37 |
|
| 38 |
if (!defined $scr) { |
| 39 |
print "Usage: $0 <icons.vga> [main.pal]\n"; |
| 40 |
print "Converts Ironseed icons.vga 81 17x15 icons file to PPM on stdout\n"; |
| 41 |
print "Display with: $0 data/icons.vga data/main.pal | xli -zoom 200 -gamma 1 -dispgamma 1 stdin\n"; |
| 42 |
exit 1; |
| 43 |
} |
| 44 |
|
| 45 |
undef $/; # slurp file in one go |
| 46 |
|
| 47 |
my @PALETTE=(); |
| 48 |
if (defined $pal) { |
| 49 |
open my $pal_fd, '<', $pal; |
| 50 |
@PALETTE = unpack "C*", <$pal_fd>; |
| 51 |
} |
| 52 |
|
| 53 |
print "P3\n"; # see ppm(5) |
| 54 |
print $height * $icon_count . "\n"; |
| 55 |
print $width . "\n"; |
| 56 |
print "255\n"; |
| 57 |
|
| 58 |
open my $scr_fd, '<', $scr; |
| 59 |
my @icons = unpack "C*", <$scr_fd>; |
| 60 |
close $scr_fd; |
| 61 |
|
| 62 |
for my $x (0 .. $width-1) { |
| 63 |
for my $icon (0 .. $icon_count-1) { |
| 64 |
for my $y (0 .. $height-1) { |
| 65 |
my $idx = ($icon * $width * $height) + ($y * $width) + $x; |
| 66 |
my $b = $icons[$idx]; |
| 67 |
if (@PALETTE) { |
| 68 |
my $c1 = $PALETTE[$b*3] * $COLOR_FACTOR; |
| 69 |
my $c2 = $PALETTE[$b*3+1] * $COLOR_FACTOR; |
| 70 |
my $c3 = $PALETTE[$b*3+2] * $COLOR_FACTOR; |
| 71 |
print "$c1 $c2 $c3\n"; |
| 72 |
} else { # grayscale |
| 73 |
print "$b $b $b\n"; # idx=$idx icon=$icon y=$y x=$x\n"; |
| 74 |
} |
| 75 |
} |
| 76 |
} |
| 77 |
} |