Diff for /scaleomat/scaleomat.pl between versions 1.2 and 1.6

version 1.2, 2004/07/23 18:00:33 version 1.6, 2004/12/06 10:02:54
Line 1 Line 1
 #!/usr/bin/perl  #!/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 strict;
   use sigtrap qw(die normal-signals);
   
 # MPIWG libraries  # MPIWG libraries
 use lib '/usr/local/mpiwg/scripts';  use lib '/usr/local/mpiwg/scripts';
Line 9  use MPIWGlib; Line 24  use MPIWGlib;
   
 $| = 1; # unblock IO  $| = 1; # unblock IO
   
 my $version = "V0.9.2 (ROC 22.4.2004)";  my $version = "V0.9.4 (ROC 6.12.2004)";
   
 $debug = 0;  $debug = 0;
   
Line 26  my $overwrite = 0; # overwrite already c Line 41  my $overwrite = 0; # overwrite already c
   
 # image file extensions and formats  # image file extensions and formats
 my %img_type_ext = ("tif" => "TIFF", "tiff" => "TIFF", "gif" => "GIF",   my %img_type_ext = ("tif" => "TIFF", "tiff" => "TIFF", "gif" => "GIF", 
         "jpg" => "JPEG", "png" => "PNG");          "jpg" => "JPEG", "png" => "PNG", "dcr" => "RAW");
 # destination image file extensions  # destination image file extensions
 my %target_ext_type = ("TIFF" => "jpg", "JPEG" => "jpg");  my %target_ext_type = ("TIFF" => "jpg", "JPEG" => "jpg");
   
Line 115  sub findfile { Line 130  sub findfile {
     return;      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)  # ($basename, $extension) = splitfn($filename)
Line 142  sub mmkdir { Line 175  sub mmkdir {
     # does the directory already exist?      # does the directory already exist?
     if (-d $dirname) {      if (-d $dirname) {
     chmod $dir_perm, $dirname or do {      chmod $dir_perm, $dirname or do {
         logger('ERROR', "unable to change permission on $dirname!");          logger('WARNING', "unable to change permission on $dirname!");
         return 0;  
     };      };
     return 1;      return 1;
     }      }
Line 175  sub mmkdir { Line 207  sub mmkdir {
 #  #
 sub identify {  sub identify {
     my ($filepath) = @_;      my ($filepath) = @_;
     my $pictype;      my $pictype = "";
     my $picwidth;      my $picwidth = 0;
     my $picheight;      my $picheight = 0;
     my $bitdepth = 0;      my $bitdepth = 0;
     # use quickident first      # use quickident first
     $pictype = quickident($filepath);      $pictype = quickident($filepath);
Line 188  sub identify { Line 220  sub identify {
         while (<IDENT>) {          while (<IDENT>) {
         chomp;          chomp;
         if (/Image Width:\s*(\d+)\s*Image Length:\s*(\d+)/) {          if (/Image Width:\s*(\d+)\s*Image Length:\s*(\d+)/) {
             $picwidth = $1;              $picwidth = $1 if ($1 > $picwidth);
             $picheight = $2;              $picheight = $2 if ($2 > $picheight);
             next;              next;
         }          }
         if (/Bits\/Sample:\s*(\d+)/) {          if (/Bits\/Sample:\s*(\d+)/) {
             $bitdepth = $1;              $bitdepth = $1 if ($1 > $bitdepth);
             next;              next;
         }          }
         }          }
         if ($picwidth) {          if ($picwidth) {
         logger('DEBUG', "TIFF $1 x $2");          logger('DEBUG', "TIFF $picwidth x $picheight");
         return ($pictype, $picwidth, $picheight, $bitdepth);          return ($pictype, $picwidth, $picheight, $bitdepth);
         }          }
     }      }
Line 605  sub convert_file { Line 637  sub convert_file {
     #      #
     $pictype = quickident("$srcdir/$filename");      $pictype = quickident("$srcdir/$filename");
     if ($pictype) {      if ($pictype) {
       if ($pictype eq "RAW") {
           logger('DEBUG', "skipping raw file '$srcdir/$filename'");
           return 0;
       }
     my $newext = $target_ext_type{$pictype};      my $newext = $target_ext_type{$pictype};
     if ($newext) {      if ($newext) {
         $newfn = $filebase . ".$newext";          $newfn = $filebase . ".$newext";
Line 621  sub convert_file { Line 657  sub convert_file {
     }      }
     } else {      } else {
     # quick ident failed -- do it slowly      # quick ident failed -- do it slowly
   
     ($pictype, $picwidth, $picheight, $bitdepth) = identify("$srcdir/$filename");      ($pictype, $picwidth, $picheight, $bitdepth) = identify("$srcdir/$filename");
     if ((! $pictype)||($picwidth == 0)||($picheight == 0)) {      if ((! $pictype)||($picwidth == 0)||($picheight == 0)) {
         logger('WARNING', "unknown file type '$srcdir/$filename'");          logger('WARNING', "unknown file type '$srcdir/$filename'");
Line 778  checksoft(); Line 813  checksoft();
 my $args = parseargs();  my $args = parseargs();
   
 # source dir  # source dir
 my $srcdir = $$args{'src'};  my $srcdir = cleanpath($$args{'src'}, 1);
   
 # destination dir  # destination dir
 my $destdir = $$args{'dest'};  my $destdir = cleanpath($$args{'dest'}, 1);
   
 # working dir  # working dir
 my $workdir = $$args{'dir'};  my $workdir = cleanpath($$args{'dir'});
   
 # destination size  # destination size
 if ($$args{'scaleby'}) {  if ($$args{'scaleby'}) {

Removed from v.1.2  
changed lines
  Added in v.1.6


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>