From: ian Date: Fri, 22 Oct 2004 00:52:26 +0000 (+0000) Subject: it assigns colours - but layout cannot read them yet X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ijackson/git?a=commitdiff_plain;h=14abe2c439963b062eb9e02cdc8a02aaa46cc65a;p=trains.git it assigns colours - but layout cannot read them yet --- diff --git a/layout/segcmapassign b/layout/segcmapassign index 3de3fd3..8ddf3ca 100755 --- a/layout/segcmapassign +++ b/layout/segcmapassign @@ -1,16 +1,27 @@ -#!/usr/bin/perl +#!/usr/bin/perl -w # input file: # lines, with one canonical subsegment specification (csss) each # (need not be unique) # output: # lines: -# +# +# C # where is N/[MP] (see informat.txt) and and # contain no whitespace and are suitable for inserting like this # into the PostScript output: # ...code to compute and stack red in range [0,1>... # setrgbcolor # +# S 0x +# F 0x 0x +# where (1<) { + m,^(\w*)/([A-Za-z_]*)(\d*)$, or die; + ($seg,$movfeat,$movconf)=($1,$2,$3); + if (!length $seg) { + printf("C /%s%s 0 0\n", + $seg, $movfeat, $movconf) + or die $!; + next; + } + die if length $movconf && !length $movfeat; + exists $seg{$seg}{Num}; + $si= $seg{$seg}; + if (length $movfeat) { + exists $si->{Feat}{$movfeat}{Max}; + $fi= $si->{Feat}{$movfeat}; + $fi->{Max}=0 unless exists $fi->{Max}; + $fi->{Max}=$movconf unless $fi->{Max} >= $movconf; + } +} + +sub cssnmap ($$$$) { + my ($seg,$movfeatconf,$segnum,$posinfo) = @_; + my ($green,$blue); + $green= (($segnum >> 8) & 0x03)<<6; + $green |= $posinfo; + $blue= $segnum & 0xff; + printf("C %s/%s %.10f %.10f\n". + "# %s/%s 0x%x 0x%x\n", + $seg,$movfeatconf, + $green/255, $blue/255, + $seg,$movfeatconf, + $green, $blue) + or die $!; +} + +our ($segnum) = 1; + +our ($conf,$posbit,$posbiti,$nextfree); + +foreach $seg (sort keys %seg) { + $si= $seg{$seg}; + $si->{Num}= $segnum++; + die if $si->{Num} >= 1024; + $nextfree= 0; + printf("S %s 0x%x\n", + $seg, $si->{Num}) + or die $!; + cssnmap($seg,'', $si->{Num}, 0x3f); + foreach $movfeat (sort { + $si->{Feat}{$b}{Max} <=> $si->{Feat}{$a}{Max}; + } keys %{ $si->{Feat} }) { + $fi= $si->{Feat}{$movfeat}; + for ($posbit=1,$posbiti=0; + $posbit<=$fi->{Max}; + $posbit<<=1,$posbiti++) { } + $fi->{Prefix}= $nextfree; + $fi->{ConfigMask}= $posbit-1; + $fi->{ConfigBits}= $posbiti; + $nextfree += $posbit; + printf("F %s 0x%x %s 0x%x %d 0x%x\n", + $seg, $si->{Num}, + $movfeat, $fi->{Prefix}, $fi->{ConfigBits}, $fi->{Max}); + foreach ($conf=0; $conf<=$fi->{Max}; $conf++) { + cssnmap($seg, $movfeat.$conf, $si->{Num}, $fi->{Prefix}+$conf); + } + } + die "too many $seg" if $nextfree > 0x03f; +} + +STDIN->error and die $!; +print "E\n" or die $!;