#!/usr/bin/perl

use strict;
use warnings;
use File::Spec;

my @files = @ARGV;
@files = map File::Spec->rel2abs ($_), @files;

for my $pto (@files)
{
    my $stub = $pto;
    $stub =~ s/\.pto$//i;

    use Panotools::Script;

    my $p = new Panotools::Script;
    $p->{stitcher} = 'nona-mask';
    $p->Read ($pto);
    $p->Panorama->Set (n => '"TIFF_m c:DEFLATE"');
    $p->Stitch ($stub .'_');

    my @temp_files;
    for my $index (0 .. scalar @{$p->{image}} - 1)
    {
         push @temp_files, ($stub .'_'. sprintf ('%.4d', $index) .'.tif');
    }

    my @args = ('-a');
    push @args ,'-w' if $p->Panorama->{v} == 360;

    system ('enblend-mask', @args, '-o', "$stub.tif", @temp_files);
    system ('convert', "$stub.tif", "$stub.jpg");

    print STDERR "Done: $stub.tif\n";
}

__END__

=head1 NAME

pto2tiff - Batch process hugin project files

=head1 Synopsis

  pto2tiff project1.pto [project2.pto ...]

=head1 DESCRIPTION

The nona stitcher can be used for batch stitching hugin pto projects.  This
tool is a simple wrapper that forces the output format into a suitable input
format for enblend, it then runs enblend (actually enblend-mask) with
appropriate arguments to generate a single blended output.

L<http://hugin.sourceforge.net/>
L<http://enblend.sourceforge.net/>

=head1 License

This software is distributed under the same terms as enblend and hugin.

=head1 See Also

L<perl>, L<Panotools::Script>

=head1 Author

Bruno Postle <bruno AT postle.net>

