#!/usr/bin/perl -w # Matija Nalis , released under GPLv3+, version 2008-11-24 # converts EEE PC 701 framebuffer files (/boot/startup.fb or /boot/shutdown.fb) # to TGA (Targa file) which can be edited with gimp, etc. # # 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 my $comment = 'http://linux.voyager.hr/eee'; # tries to convert 16bit value (RGB 5-6-5) sub col2rgb($) { my ($col) = @_; my $b = $col % 32; # bits 0-4 [5 bits] my $g = ($col >> 5) % 64; # bits 5-10 [6 bits] my $r = ($col >> 11) % 32; # bits 11-15 [5 bits] $r = ($r << 3) + 7; # brighen up by 3 bits shift (+fill low 3 bits) $g = ($g << 2) + 3; # brighen up by 2 bits shift (+fill low 2 bits) $b = ($b << 3) + 7; # brighen up by 3 bits shift (+fill low 3 bits) # printf "ORG=%016b\t\tr=%08b\tg=%08b\tb=%08b\n", $col, $r, $g, $b; return ($r, $g, $b); } # here goes the main... my $fb_file = $ARGV[0]; die "Usage: fb2tga.pl [startup.fb|shutdown.fb]" unless defined $fb_file; open (FB, '<', $fb_file) or die "can't read $fb_file: $!"; # create a .TGA file my $tga_file = $fb_file; $tga_file =~ s/\.fb$//; $tga_file .= '.tga'; open (TGA, '>', $tga_file) or die "can't create $tga_file: $!"; my $clen = length($comment); my $header = pack ('CCCS2CS4CCA*', $clen, # Number of Characters in Identification Field 0, # Color Map Type (0=none included) 2, # Image Type Code (2=Uncompressed RGB images) 0, 0, 0, # Color Map Specification (unused) 0, # X Origin of Image ( lo-hi ) 0, # Y Origin of Image ( lo-hi ) $x_size, # Width of Image ( lo-hi ) $y_size, # Height of Image ( lo-hi ) 24, # Image Pixel Size (BPP) 0+2**5, # Image Descriptor Byte (bit5 = Origin in upper left-hand corner) $comment); # Image Identification Field print TGA $header or die "can't write TGA header: $!"; my $buf=' '; # note: this loop (and col2rgb) has hardcoded 2 bytes ($bpp=16). Need modifying for 24 or 8 bpp. while (sysread (FB, $buf, 2)) { my ($col) = unpack ('S', $buf); my ($r, $g, $b) = col2rgb($col); $buf = pack ('CCC', $b, $g, $r); # 24bit TGA stores them as blue-green-red print TGA $buf or die "can't write TGA: $!"; } close (TGA) or die "can't close TGA: $!"; close (FB); print "Finished.\n";