bin/xyzimage.pl
author Axel Jacobs <axel@jaloxa.eu>
Mon, 27 Jun 2011 21:08:08 +0100
changeset 24 c273e54dd38f
parent 14 b1e2580a0ca7
child 26 a9f74601ca3c
permissions -rwxr-xr-x
Upped status of objpict and objview to 3.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     1
#!/usr/bin/perl
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     2
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     3
# Display one or more CIE XYZE pictures using ximage
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     4
#
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     5
# This is re-write of Greg's xyzimage.csh.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     6
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     7
use strict;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     8
use warnings;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
     9
#use Getopt::Long qw(:config no_auto_abbrev no_ignore_case require_order
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    10
# We need auto_abbrev for -display and -geometry.
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    11
use Getopt::Long qw(:config auto_abbrev no_ignore_case require_order
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    12
		prefix_pattern=(-));
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    13
use File::Temp qw/ tempdir /;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    14
use File::Basename;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    15
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    16
my @xiargs;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    17
my @popts;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    18
print $#ARGV . ": " . join(', ', @ARGV) . "\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    19
14
b1e2580a0ca7 Set status of all existing Perl scripts to 1.
Axel Jacobs <axel@jaloxa.eu>
parents: 8
diff changeset
    20
#TODO: Don't use Getopt. Parse by hand.
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    21
GetOptions(
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    22
	'g=f'         => sub { push(@xiargs, '-g') }, # ximage: -g gamma
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    23
	'c=i'         => sub { push(@xiargs, '-c') }, # ximage: -c ncolors
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    24
	'geometry=s'  => sub { push(@xiargs, '-c') }, # ximage: -geometry geometry
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    25
	#TODO: deal with =geometry
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    26
	'di=s'        => sub { push(@xiargs, '-c') }, # ximage: -di display
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    27
	'e=s'         => sub { push(@xiargs, '-e') }, # ximage: -e exposure
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    28
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    29
	'p=f{8}'        => \@popts, # ra_xyze: -p display_primaries
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    30
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    31
	'b'           => sub { push(@xiargs, '-b') }, # ximage: -b (black+white)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    32
	'd'           => sub { push(@xiargs, '-d') }, # ximage: -d (no ditering)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    33
	'm'           => sub { push(@xiargs, '-m') }, # ximage: -m (monochrome)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    34
	'f'           => sub { push(@xiargs, '-f') }, # ximage: -f (fast refresh)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    35
	's'           => sub { push(@xiargs, '-s') }, # ximage: -s (sequential)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    36
	#'o*'          => sub { push(@xiargs, '-l') }, # ximage: -ospec
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    37
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    38
) or die("Error parsing options.\n");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    39
print $#ARGV . ": " . join(', ', @ARGV) . "\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    40
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    41
# Handle display primaries:
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    42
# Use -p option, $DISPLAY_PRIMARIES, or nothing (in that order!)
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    43
#print "popts: $#popts -> " . join(', ', @popts) . "\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    44
my $popt = "";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    45
if($#popts != 7) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    46
	if($ENV{'DISPLAY_PRIMARIES'}) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    47
		#print "DISPLAY_PRIMARIES: $ENV{'DISPLAY_PRIMARIES'}\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    48
		$popt = '-p ' . $ENV{'DISPLAY_PRIMARIES'};
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    49
	}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    50
} else {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    51
	unshift(@popts, '-p');
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    52
	$popt = join(' ', @popts);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    53
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    54
print "popt: $popt\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    55
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    56
my $xiarg = join(' ', @xiargs);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    57
print "xiarg: $xiarg\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    58
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    59
my $td = tempdir( CLEANUP => 0 );
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    60
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    61
if ($#ARGV < 0) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    62
	# Input is from STDIN: Capture to file
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    63
	open(FH, ">$td/stdin.rad");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    64
	while (<>) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    65
		print FH;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    66
	}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    67
	close FH;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    68
	# Pretend stdin.rad was passed as a filename
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    69
	@ARGV = ("$td/stdin.rad");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    70
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    71
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    72
print $#ARGV . ": " . join(', ', @ARGV) . "\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    73
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    74
my @files;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    75
foreach (@ARGV) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    76
	my ($name, undef, undef) = fileparse($_);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    77
	my $cmd = "ra_xyze -r -u $popt $name $td/$name";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    78
	print "cmd: $cmd\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    79
	system("$cmd") == 0 or
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    80
			die("$0: Error running ra_xyze -r on file $_\n. Exit code: $?\n");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    81
	push(@files, "$td/$name");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    82
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    83
print "temp dir: $td\n";
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    84
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    85
system("ximage $xiarg " . join(' ',  @files));
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    86
14
b1e2580a0ca7 Set status of all existing Perl scripts to 1.
Axel Jacobs <axel@jaloxa.eu>
parents: 8
diff changeset
    87
#EOF