#!/usr/bin/perl -w # Matija Nalis , released under GPLv3+, version 2008-11-24 # converts TGA (Targa file) which can be edited with gimp etc (make sure you UNCHECK # both "RLE compression" and "origin at bottom left" when saving it) # to EEE PC 701 framebuffer files (to replace /boot/startup.fb or /boot/shutdown.fb) # # see http://en.wikipedia.org/wiki/Truevision_TGA and # http://www.gamers.org/dEngine/quake3/TGA.txt for TGA format use strict; # vga=785 of eeePC_701 is 640x480x16bits (64k color) my $x_size = 640; my $y_size = 480; my $bpp = 16; # note: hardcoded below in sysread... # no user configurable parts below # tries to convert 24bit R+G+B to 16bit HiColor value (RGB 5-6-5) sub rgb2col($$$) { my ($r, $g, $b) = @_; # ORG=11100 101111 00101 r=11100(111) g=101111(11) b=00101(111) my $col = (($r >> 3) << 11) + (($g >> 2) << 5) + ($b >> 3); # printf "r=%08b\tg=%08b\tb=%08b\t\tCOL=%016b\n", $r, $g, $b, $col; return $col; } # here goes the main... my $tga_file = $ARGV[0]; die "Usage: tga2fb.pl [startup.tga|shutdown.tga]" unless defined $tga_file; open (TGA, '<', $tga_file) or die "can't open $tga_file: $!"; my $buf; sysread TGA, $buf, 18 or die "can't read TGA header from $tga_file: $!"; my ($clen, $cm_type, $img_type, $cs1, $cs2, $cs3, $xorig, $yorig, $xsize, $ysize, $pixsize, $img_dsc) = unpack ('CCCS2CS4CC', $buf); die "can't handle color map type: $cm_type" if $cm_type; die "can't handle image type: $img_type" if $img_type != 2; die "can't handle colormap: $cs1, $cs2, $cs3" if $cs1+$cs2+$cs3; die "can't handle origin: $xorig, $yorig" if $xorig+$yorig; die "can't handle size $xsize x $ysize" if ($xsize != $x_size) or ($ysize != $y_size); die "can't handle bpp $pixsize" if $pixsize != 24; die "can't handle image descriptor: $img_dsc" if $img_dsc != 2**5; if ($clen) { sysread TGA, $buf, $clen or die "can't read header comment from TGA $tga_file: $!"; print "found TGA comment: $buf\n"; } # create a .FB file my $fb_file = $tga_file; $fb_file =~ s/\.tga$//; $fb_file .= '.fb'; open (FB, '>', $fb_file) or die "can't create $fb_file: $!"; # note: this loop (and rgb2col) has hardcoded 3=>2 bytes (TGA 24bit to FB 16bit). Needs modifying for other combinations. while (sysread (TGA, $buf, 3)) { my ($b, $g, $r) = unpack ('CCC', $buf); # 24bit TGA stores them as blue-green-red my $col = rgb2col($r, $g, $b); $buf = pack ('S', $col) ; print FB $buf or die "can't write FB: $!"; } close (FB) or die "can't close FB: $!"; close (TGA); print "Finished.\n";