#!/usr1/local/bin/perl5 # # Generate a viewport configuration file for a configuration of # NxM to use with ximage's viewport command. # # Mar. 17, 2000 -- Micah Johnson # Version 1.0 # require "getopts.pl"; require "interface.pl"; require "utils.pl"; # &Getopts('d:v:s:o:m:hc'); # if (defined $opt_h) { print < $vpy ) { $minmar = int(0.1*$dvx); } else { $minmar = int(0.1*$dvy); } if ( $chat ) { print " Minimum margin: $minmar\n"; } } # # Output vpc file if ( defined($opt_o) ) { $outvpc = $opt_o; if ( /^[^.]+$/ ) { $outvpc = $outvpc . ".vpc"; } } else { $outvpc = "${vpx}x${vpy}.vpc"; } open OUTVPC, ">$outvpc" or die "Failed to open output file: $outvpc\n"; print " Writing $outvpc...\n"; print OUTVPC "#\n"; print OUTVPC "# $outvpc\n"; print OUTVPC "# Specs: vpcgen.pl -v ${vpx}x${vpy} -d ${dvx}x${dvy} ", "-s ${szx}x${szy} -m $minmar\n"; print OUTVPC "# Usage in ximage: viewport $outvpc\n"; print OUTVPC "#\n"; # Find size of individual viewports $xmax = int(($dvx - 2*$minmar)/$vpx + 0.0); $ymax = int(($dvy - 2*$minmar)/$vpy + 0.0); if ( $chat ) { print " Max size of viewport x: $xmax y: $ymax\n"; } if ( $szx/$szy < $xmax/$ymax ) { if ( $chat ) { print " Limiting direction: Y\n"; } $y1 = $ymax; $x1 = $y1*($szx/$szy); } else { if ( $chat ) { print " Limiting direction: X\n"; } $x1 = $xmax; $y1 = $x1*($szy/$szx); } if ( $chat ) { print " Size of viewport (pix): $x1 $y1\n"; } $xmar = int(($dvx - $vpx*$x1)/2 + 0.0); $ymar = int(($dvy - $vpy*$y1)/2 + 0.0); if ( $chat ) { print " Final margin (pix): $xmar $ymar\n"; } for ($j = 1; $j <= $vpy; $j++ ) { for ($i = 1; $i <= $vpx; $i++ ) { $v1 = ($xmar + ($i-1)*$x1)/$dvx; $v2 = ($xmar + $i*$x1)/$dvx; $v3 = 1.0 - ($ymar + $j*$y1)/$dvy; $v4 = 1.0 - ($ymar + ($j-1)*$y1)/$dvy; print OUTVPC "$v1 $v2 $v3 $v4\n"; if ( $chat ) { printf "%f %f %f %f\n",$v1*$dvx, $v2*$dvx, $v3*$dvy, $v4*$dvy; } } } close OUTVPC;