--- scaleomat/scaleomat.pl 2004/07/23 18:00:33 1.2 +++ scaleomat/scaleomat.pl 2004/12/06 10:02:54 1.6 @@ -1,6 +1,21 @@ #!/usr/bin/perl +# Copyright (C) 2003,2004 Robert Casties, IT-Group MPIWG +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 2 of the License, or (at your option) +# any later version. +# +# Please read license.txt for the full details. A copy of the GPL may be found +# at http://www.gnu.org/copyleft/lgpl.html +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 59 Temple +# Place, Suite 330, Boston, MA 02111-1307 USA + use strict; +use sigtrap qw(die normal-signals); # MPIWG libraries use lib '/usr/local/mpiwg/scripts'; @@ -9,7 +24,7 @@ use MPIWGlib; $| = 1; # unblock IO -my $version = "V0.9.2 (ROC 22.4.2004)"; +my $version = "V0.9.4 (ROC 6.12.2004)"; $debug = 0; @@ -26,7 +41,7 @@ my $overwrite = 0; # overwrite already c # image file extensions and formats my %img_type_ext = ("tif" => "TIFF", "tiff" => "TIFF", "gif" => "GIF", - "jpg" => "JPEG", "png" => "PNG"); + "jpg" => "JPEG", "png" => "PNG", "dcr" => "RAW"); # destination image file extensions my %target_ext_type = ("TIFF" => "jpg", "JPEG" => "jpg"); @@ -115,6 +130,24 @@ sub findfile { return; } +# +# $p = cleanpath($path, $startslash). +# +# returns a pathname with trailing and starting slash removed (if +# $startslash is true the starting slash is not removed) +# +sub cleanpath { + my ($path, $startslash) = @_; + + if ($path =~ /^(\/)*(.*?)\/*$/) { + if ($startslash) { + return $1 . $2; + } else { + return $2; + } + } + return $path; +} # # ($basename, $extension) = splitfn($filename) @@ -142,8 +175,7 @@ sub mmkdir { # does the directory already exist? if (-d $dirname) { chmod $dir_perm, $dirname or do { - logger('ERROR', "unable to change permission on $dirname!"); - return 0; + logger('WARNING', "unable to change permission on $dirname!"); }; return 1; } @@ -175,9 +207,9 @@ sub mmkdir { # sub identify { my ($filepath) = @_; - my $pictype; - my $picwidth; - my $picheight; + my $pictype = ""; + my $picwidth = 0; + my $picheight = 0; my $bitdepth = 0; # use quickident first $pictype = quickident($filepath); @@ -188,17 +220,17 @@ sub identify { while () { chomp; if (/Image Width:\s*(\d+)\s*Image Length:\s*(\d+)/) { - $picwidth = $1; - $picheight = $2; + $picwidth = $1 if ($1 > $picwidth); + $picheight = $2 if ($2 > $picheight); next; } if (/Bits\/Sample:\s*(\d+)/) { - $bitdepth = $1; + $bitdepth = $1 if ($1 > $bitdepth); next; } } if ($picwidth) { - logger('DEBUG', "TIFF $1 x $2"); + logger('DEBUG', "TIFF $picwidth x $picheight"); return ($pictype, $picwidth, $picheight, $bitdepth); } } @@ -605,6 +637,10 @@ sub convert_file { # $pictype = quickident("$srcdir/$filename"); if ($pictype) { + if ($pictype eq "RAW") { + logger('DEBUG', "skipping raw file '$srcdir/$filename'"); + return 0; + } my $newext = $target_ext_type{$pictype}; if ($newext) { $newfn = $filebase . ".$newext"; @@ -621,7 +657,6 @@ sub convert_file { } } else { # quick ident failed -- do it slowly - ($pictype, $picwidth, $picheight, $bitdepth) = identify("$srcdir/$filename"); if ((! $pictype)||($picwidth == 0)||($picheight == 0)) { logger('WARNING', "unknown file type '$srcdir/$filename'"); @@ -778,13 +813,13 @@ checksoft(); my $args = parseargs(); # source dir -my $srcdir = $$args{'src'}; +my $srcdir = cleanpath($$args{'src'}, 1); # destination dir -my $destdir = $$args{'dest'}; +my $destdir = cleanpath($$args{'dest'}, 1); # working dir -my $workdir = $$args{'dir'}; +my $workdir = cleanpath($$args{'dir'}); # destination size if ($$args{'scaleby'}) {