#!/usr/bin/perl -w # $Id$ # Convert Photoshop curves files (.acv) to GIMP curves # Assume 5 curves/channels per file # Outputs to stdout # ajr, 2005-06-30 $DEBUG = 0; my $file=$ARGV[0]; open(FILE, "<$file") or die("Couldn't open $file for reading: $!\n"); # read number of curves read(FILE, $header, 4) == 4 or die "Short read: $!\n"; @header=unpack("n n", $header); $curves=$header[1]; print STDERR "$curves curves in $file\n" if $DEBUG; warn("More than 5 curves, output may be invalid!\n") if ($curves > 5); print "# GIMP Curves File\n"; for ($i = 1; $i <= $curves; $i++) { read(FILE, $points, 2) == 2 or die "Short read: $!\n"; @points = unpack("n", $points); $points = $points[0]; print STDERR "Curve #$i: $points points\n" if $DEBUG; warn("$points in curve $i, some points will be ignored") if ($points > 17); for ($p = 1; $p < $points; $p++) { read(FILE, $pair, 4) == 4 or die("Short read: $!\n"); @pair=unpack("n n", $pair); # ACV pairs are in y,x order so swap: print "$pair[1] $pair[0] "; } # pad with null pairs up to 16 points for ($p = 1; $p <= (17 - $points); $p++) { print "-1 -1 "; } # final point read(FILE, $pair, 4) == 4 or die("Short read: $!\n"); @pair=unpack("n n", $pair); print "$pair[1] $pair[0]\n"; } warn("Unread data left in file\n") if (!eof(FILE)); close(FILE);