#!/usr/bin/perl # # hack, hack # # Invocation: # # colorizexpm.pl MyGrayXpm.xpm darkblue lightblue > MyBlueXpm.xpm # # This script takes a gray scale pixmap and two color names, # and produces a colored pixmap, by replacing the gray values # by interpolated values between the two colors. The first given # color is mapped to the darkest gray tone, the second color # is mapped to the lightes gray tone. So if you don't want your # new pixmap to appear 'inverted', the first color should be darker # than the second. Use it to generate a custom color pixmap to # each of your color schemes. # # Notes: the xpm parser is a hack. I used gimp to generate a # grey scale pixmap, so if you do the same, the script should work. # # The script uses some color functions I put in a separate file. # This should be in the same directory as the script ('colorfun.pl'). # Also the file 'rgb.txt' should be in the same directory. # # Bug: for some reason it doesn't yet work if you take 2 grey # colors for interpolating. # # Good luck, # # Jos van Riswick (josvanr@xs4all.nl) do './jos-colorfun'; $Start=ConvertColor($ARGV[1]); #dark substitute color $Stop=ConvertColor($ARGV[2]); #light substitute color open(INFILE,$ARGV[0]); while () {$c=$c.$_;} close(INFILE); $c=~s/\n//g; @l=split('","',$c); @ll=split(" ",$l[0]); $ncol=$ll[9]; #number of colors #get the colors $min=255; $max=0; $j=0; foreach $i (1..$ncol) { @ll=split("\t",$l[$i]); @lll=split(" ",$ll[1]); $lll=$lll[1]; if ($lll=~/None/) { ; } else { $j++; $b=ConvertColor($lll); $C[$j]=$lll; $ccc=$$b[0]; $cc[$j]=$ccc; if ($ccc<$min) {$min=$ccc}; if ($ccc>$max) {$max=$ccc}; } } $dx=$max-$min; $x1=$min/$dx; $x2=$max/$dx; foreach $i (1..$ncol) { $cc[$i]=$cc[$i]/$dx;} sub Interpolate { my ($c1, $c2, $x) = @_; return - $c1*($x-$x2) + $c2*($x-$x1); } foreach $i (1..$ncol-1) { $r=Interpolate($$Start[0],$$Stop[0],$cc[$i]); $g=Interpolate($$Start[1],$$Stop[1],$cc[$i]); $b=Interpolate($$Start[2],$$Stop[2],$cc[$i]); # $New[$i]=GimpColor2aabbcc([int($r),int($g),int($b)]); $New[$i]=GimpColor2aabbcc([$r,$g,$b]); } $c=""; open(INFILE,$ARGV[0]); while () { $c=$c.$_; } close(INFILE); foreach $i (1..$ncol-1) { $c=~s/$C[$i]/$New[$i]/; } print $c;