#!/usr/bin/perl #----------------------------------------------------------------------------- # Included support for 8bit-Color-Screenshots # Included extraction out of Files rather than directly from palm # (c) 2001 by Martin Gisch (palmscreen@roquas.de) # palmscreen2xpm (c) 2000 by FreeStone Systems, Matthias Cramer # # License: GPL # # This Program is intended to work with the screenshot.prc programmed by # LinkeSoft Christian Linke, Berlin, Germany # (http://linkesoft.com/english/screenshothack/) # # This Program is tested with V1.1, V1.2 and V1.4 of the program. # # It can read 2, 4 and 8 bit images. #----------------------------------------------------------------------------- # Used Modules: # PDA::Pilot (from pilot-link toolkit) # MD5 (for the pilot-link toolkit) #----------------------------------------------------------------------------- use strict; use PDA::Pilot; sub usage { print "Usage: $0 h\n"; print " Extracts from Pilot in cradle, installed on /dev/pilot\n\n"; print " $0 f\n"; print " Extracts from file ScreenShotDB.pdb located in act.dir\n\n"; print " if a 2nd Parameter is included, it will replace the\n"; print " standard device or file name\n\n"; print "Examples: $0 h /dev/ttyS0\n"; print " or $0 f ~/pilot/backup/ScreenShotDB.pdb\n"; die "\n"; } my $mode; my $wherefrom; if((scalar @ARGV)<1){ usage; }else{ if($ARGV[0]=~/^[hH]/){ $mode = 0; $wherefrom = "/dev/pilot"; }else{ if($ARGV[0]=~/^[fF]/){ $mode = 1; $wherefrom = "./ScreenShotDB.pdb"; }else{ usage; } } } if((scalar @ARGV)>1){ $wherefrom = $ARGV[1]; } my $r; my $record = 0; my $file; if($mode == 0){ my $socket = PDA::Pilot::openPort($wherefrom); print "Now press the HotSync button ...\n"; my $dlp = PDA::Pilot::accept($socket); $file = $dlp->open("ScreenShotDB"); }else{ $file = PDA::Pilot::File::open($wherefrom); } while(defined($r = $file->getRecord($record++))) { my @data = split(//, $r->{raw}); if($#data == 26623){ my $i; my $b; my @pal; @data = map(ord,split(//, $r->{raw})); if (!open (FILEOUT, ">$record.ppm")) { die("Can't open $record.ppm"); } else { print "Fetching screenshot $record as $record.ppm\n"; } for($i=0;$i<256;$i++){ $b = 25600+$i*4; $pal[$data[$b]] = (chr($data[$b+1]).chr($data[$b+2]).chr($data[$b+3])); } print FILEOUT "P6\n160 160\n255\n"; for($i=0;$i<25600;$i++){ print FILEOUT $pal[$data[$i]]; } close FILEOUT; }else{ my @gray; if (!open (FILEOUT, ">$record.xpm")) { die("Can't open $record.xpm"); } else { print "Fetching screenshot $record as $record.xpm\n"; } if ($#data == 3199) { print FILEOUT "/* XPM */\n"; print FILEOUT "static char *xpm_image[] = {\n"; print FILEOUT "\"160 160 2 1\",\n"; print FILEOUT "\" c None\",\n"; print FILEOUT "\"X c #000000\",\n"; print FILEOUT "\""; @gray = (" ","X"); } else { if ($#data == 12799) { print FILEOUT "/* XPM */\n"; print FILEOUT "static char *xpm_image[] = {\n"; print FILEOUT "\"160 160 16 1\",\n"; print FILEOUT "\"a c \#ffffff\",\n"; print FILEOUT "\"b c \#eeeeee\",\n"; print FILEOUT "\"c c \#dddddd\",\n"; print FILEOUT "\"d c \#cccccc\",\n"; print FILEOUT "\"e c \#bbbbbb\",\n"; print FILEOUT "\"f c \#aaaaaa\",\n"; print FILEOUT "\"g c \#999999\",\n"; print FILEOUT "\"h c \#888888\",\n"; print FILEOUT "\"i c \#777777\",\n"; print FILEOUT "\"j c \#666666\",\n"; print FILEOUT "\"k c \#555555\",\n"; print FILEOUT "\"l c \#444444\",\n"; print FILEOUT "\"m c \#333333\",\n"; print FILEOUT "\"n c \#222222\",\n"; print FILEOUT "\"o c \#111111\",\n"; print FILEOUT "\"p c \#000000\",\n"; print FILEOUT "\""; @gray = ("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p"); }else{ print FILEOUT "/* XPM */\n"; print FILEOUT "static char *xpm_image[] = {\n"; print FILEOUT "\"160 160 4 1\",\n"; print FILEOUT "\" c None\",\n"; print FILEOUT "\". c \#3f3f3f\",\n"; print FILEOUT "\"x c \#7f7f7f\",\n"; print FILEOUT "\"X c \#000000\",\n"; print FILEOUT "\""; @gray = (" ",".","x","X"); } } my $byte; my $i; my $ret; for (my $pos; $pos <= $#data; $pos++) { $byte = ord($data[$pos]); if ($#data == 3199) { $ret = ($byte & 0x80)/128; print FILEOUT $gray[$ret]; $ret = ($byte & 0x40)/64; print FILEOUT $gray[$ret]; $ret = ($byte & 0x20)/32; print FILEOUT $gray[$ret]; $ret = ($byte & 0x10)/16; print FILEOUT $gray[$ret]; $ret = ($byte & 0x08)/8; print FILEOUT $gray[$ret]; $ret = ($byte & 0x04)/4; print FILEOUT $gray[$ret]; $ret = ($byte & 0x02)/2; print FILEOUT $gray[$ret]; $ret = ($byte & 0x01); print FILEOUT $gray[$ret]; $i++; if (($i % 20) == 0) { print FILEOUT "\",\n\""; } } else { if ($#data == 12799) { $ret = ($byte & 0xf0)/16; print FILEOUT $gray[$ret]; $ret = ($byte & 0x0f); print FILEOUT $gray[$ret]; $i++; if (($i % 80) == 0) { print FILEOUT "\",\n\""; } } else { $ret = ($byte & 0xc0)/64; print FILEOUT $gray[$ret]; $ret = ($byte & 0x30)/16; print FILEOUT $gray[$ret]; $ret = ($byte & 0x0c)/4; print FILEOUT $gray[$ret]; $ret = ($byte & 0x03); print FILEOUT $gray[$ret]; $i++; if (($i % 40) == 0) { print FILEOUT "\",\n\""; } } } } print FILEOUT "\"};"; close(FILEOUT); print "$i chars read\n"; } }