bin/xyzimage.pl
author Axel Jacobs <axel@jaloxa.eu>
Sun, 15 Dec 2013 18:04:49 +0000
changeset 45 aaf822f49732
parent 26 a9f74601ca3c
permissions -rwxr-xr-x
new exe/ directory with Window pp executables
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;
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
     9
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    10
use File::Temp qw/ tempdir /;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    11
use File::Basename;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    12
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    13
my @xiargs = ();   # Options for ximage
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    14
my $popt = '';     # Display primaries (as string)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    15
if( $ENV{DISPLAY_PRIMARIES} ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    16
	$popt = "-p $ENV{DISPLAY_PRIMARIES}";
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    17
}
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    18
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    19
while( $#ARGV ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    20
	$_ = shift @ARGV;
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    21
	if( m/-ge\w*/ or m/-di\w*/ or m/-g$/ or m/-c/ or m/-e/ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    22
		# The following options all require one qualifier and are passed
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    23
		# straight on to ximage:
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    24
		# -geometry (an X11 thing, e.g. 800x600+50+50)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    25
		# -di display (an X11 thing)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    26
		# -c number of colours
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    27
		# -g gamma
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    28
		# -e exposure compensation
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    29
		push( @xiargs, $_, shift @ARGV ) or
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    30
				die( "Missing qualifier for $_ option.\n" );
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    31
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    32
	} elsif( m/=[\S]{3,}/ or m/o\w{1,}/ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    33
		# The qualifier to the -o option is glued to the option.
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    34
		# Passed straight to ximage:
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    35
		# -ospec print spec to STDOUT (defaults to -ood)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    36
		# =geometry (alternative invocation to -geometry)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    37
		push( @xiargs, $_ );
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    38
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    39
	} elsif( m/-b/ or m/-d/ or m/-m/ or m/-f/ or m/-s/ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    40
		# The following switches are passed straight to ximage:
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    41
		# -b black and white output
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    42
		# -d no color dithering
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    43
		# -m monochrome output
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    44
		# -f fast redraw on (-F to turn it off)
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    45
		# -s display multiple picture sequentially
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    46
		push( @xiargs, $_ );
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    47
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    48
	} elsif( m/-p/ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    49
		# The following option requires eight float qualifiers:
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    50
		# -p display primaries
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    51
		my @popts = ('-p');
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    52
		for( my $i=0 ; $i<=7 ; $i++ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    53
			if( $#ARGV <= 0 ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    54
				die("Missing qualifier for -p option: Need eight.\n");
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    55
			}
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    56
			push( @popts, shift @ARGV );
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    57
		}
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    58
		$popt = join( ' ', @popts );
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    59
	} elsif( m/^-/ ) {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    60
		die( "Unknown option: $_\n" );
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    61
	} else {
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    62
		# The remaining command-line args are file names.
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    63
		last;
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    64
	}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    65
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    66
my $xiarg = join(' ', @xiargs);
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    67
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    68
my $td = tempdir( CLEANUP => 0 );
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    69
if ($#ARGV < 0) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    70
	# Input is from STDIN: Capture to file
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    71
	open(FH, ">$td/stdin.rad");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    72
	while (<>) {
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    73
		print FH;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    74
	}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    75
	close FH;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    76
	# Pretend stdin.rad was passed as a filename
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    77
	@ARGV = ("$td/stdin.rad");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    78
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    79
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    80
my @files;
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    81
foreach (@ARGV) {
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    82
	my ($name, $path, $suffix) = fileparse($_);
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    83
	my $cmd = "ra_xyze -r -u $popt $_ $td/$name";
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    84
	system("$cmd") == 0 or
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    85
			die("Error running ra_xyze -r on file $_\n");
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    86
	push(@files, "$td/$name");
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    87
}
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    88
26
a9f74601ca3c xyzimage seems to work now. Upped status to 2.
Axel Jacobs <axel@jaloxa.eu>
parents: 14
diff changeset
    89
system "ximage $xiarg " . join(' ',  @files);
8
9ed02f081b72 Added the rest of the files
Axel Jacobs <axel@jaloxa.eu>
parents:
diff changeset
    90
14
b1e2580a0ca7 Set status of all existing Perl scripts to 1.
Axel Jacobs <axel@jaloxa.eu>
parents: 8
diff changeset
    91
#EOF