diff options
author | Andy Shevchenko <andy@smile.org.ua> | 2008-08-25 21:08:06 +0000 |
---|---|---|
committer | Andy Shevchenko <andy@smile.org.ua> | 2008-08-25 21:08:06 +0000 |
commit | 98e959358454b696c3eebc3733072372194f50e6 (patch) | |
tree | 075e15db3d1d10af48bbabe1f298b4101f889d01 | |
parent | 0a88e0a636815ee0073d7d2186a60423da6a6975 (diff) | |
download | renrot-98e959358454b696c3eebc3733072372194f50e6.tar.gz renrot-98e959358454b696c3eebc3733072372194f50e6.tar.bz2 |
Optimize if...then condition in contact sheet generator and make it more readable.
git-svn-id: file:///svnroot/renrot/branches/andy@555 fe2816f4-e837-0410-b10a-f608c9d244a1
-rwxr-xr-x | renrot | 95 |
1 files changed, 49 insertions, 46 deletions
@@ -551,10 +551,10 @@ sub getOptions { dbgmsg (1, "We have Image::Magick package and could proceed with --contact-sheet related functionality.\n"); } elsif ($cfgOpts{'contact sheet'} == 1 or defined $contactSheet) { errmsg ("To use --contact-sheet related functionality you need Image::Magick package!\n", - "Contact Sheet generation disabled.\n\n"); + "Contact Sheet generation disabled.\n"); } elsif ($gen_thm != 0) { errmsg ("To use --generate-thumb functionality you need Image::Magick package!\n", - "ThumbnailImage generation is disabled.\n\n"); + "ThumbnailImage generation is disabled.\n"); } # preparing Software tag according the usage or not of ImageMagick @@ -1252,46 +1252,49 @@ sub contactSheetGenerator { foreach $file (keys %filenameshash) { $info = $exifToolObj->ImageInfo($file); $orientation = $exifToolObj->GetValue("Orientation", 'ValueConv'); - $filefull = $file; - if ($contactSheetThm != 0 and defined $orientation and $orientation > 1) { - $filefull = rot_thm_cs ($file, $rotorient{$orientation}, $workdir); - } elsif ($contactSheetThm != 0 and defined $orientation and $orientation == 1) { - # We need this since rotated imgage will be at $workdir, but others are - # in current - $ThumbnailOriginal = File::Spec->catfile($workdir, $file); - copy ($file, $ThumbnailOriginal) or die "copy failed: $!"; - $filefull = $ThumbnailOriginal; - } elsif ($contactSheetThm == 0 and defined ${$$info{ThumbnailImage}}) { - $ThumbnailOriginal = File::Spec->catfile($workdir, $file); - unless (open (OLDTHUMBNAIL, ">$ThumbnailOriginal")) { - die "$ThumbnailOriginal wasn't opened!\n"; - } - binmode OLDTHUMBNAIL; - print OLDTHUMBNAIL ${$$info{ThumbnailImage}}; - unless (close (OLDTHUMBNAIL)) { warn "$ThumbnailOriginal wasn't closed!\n"; } + $filefull = $file; - if (not defined $orientation) { - $orientation = $exifToolObj->GetValue("Rotation", 'ValueConv'); + if ($contactSheetThm != 0 and defined $orientation) { + if ($orientation > 1) { + $filefull = rot_thm_cs ($file, $rotorient{$orientation}, $workdir); + } elsif ($orientation == 1) { + # We need this since rotated imgage will be at $workdir, but others are + # in current + $ThumbnailOriginal = File::Spec->catfile($workdir, $file); + copy ($file, $ThumbnailOriginal) || ( fatalmsg ("copy failed: $!"), die ); + $filefull = $ThumbnailOriginal; } + } elsif ($contactSheetThm == 0) { + if (defined ${$$info{ThumbnailImage}}) { + $ThumbnailOriginal = File::Spec->catfile($workdir, $file); + open (OLDTHUMBNAIL, ">$ThumbnailOriginal") || ( fatalmsg ("$ThumbnailOriginal wasn't opened!\n"), die; ) + binmode OLDTHUMBNAIL; + print OLDTHUMBNAIL ${$$info{ThumbnailImage}}; + close (OLDTHUMBNAIL) || { warnmsg ("$ThumbnailOriginal wasn't closed!\n"); } + + if (not defined $orientation) { + $orientation = $exifToolObj->GetValue("Rotation", 'ValueConv'); + } - if (defined $orientation and $orientation > 1) { - $filefull = rot_thm_cs ($ThumbnailOriginal, $orientation, File::Spec->curdir()); + if (defined $orientation and $orientation > 1) { + $filefull = rot_thm_cs ($ThumbnailOriginal, $orientation, File::Spec->curdir()); + } else { + $filefull = $ThumbnailOriginal; + } } else { - $filefull = $ThumbnailOriginal; + my $ffwf = File::Spec->catfile($workdir, $file); + if ($gen_thm == 0) { + warnmsg ("$filefull has no ThumbnailImage tag. Stub thumbnail image will be used.\n"); + my $thmbstubjpg = File::Spec->catfile($workdir, "thmbstub.jpg"); + thm_gen_stub($thmbstubjpg) if (not -f $thmbstubjpg); + copy ($thmbstubjpg, $ffwf); + } else { + warnmsg ("$filefull has no ThumbnailImage tag. Thumbnail image will be generated.\n"); + move (thm_gen_orig($file, 0), $ffwf); + } + $filefull = $ffwf; } - } elsif ($contactSheetThm == 0 and not defined ${$$info{ThumbnailImage}} and $gen_thm == 0) { - warnmsg ("$filefull has no ThumbnailImage tag. Stub thumbnail image'll be used.\n"); - my $thmbstubjpg = File::Spec->catfile($workdir, "thmbstub.jpg"); - thm_gen_stub($thmbstubjpg) if (not -f $thmbstubjpg); - my $ffwf = File::Spec->catfile($workdir, $file); - copy ($thmbstubjpg, $ffwf); - $filefull = $ffwf; - } elsif ($contactSheetThm == 0 and not defined ${$$info{ThumbnailImage}} and $gen_thm != 0) { - warnmsg ("$filefull has no ThumbnailImage tag. Thumbnail image'll be generated.\n"); - my $ffwf = File::Spec->catfile($workdir, $file); - move (thm_gen_orig($file, 0), $ffwf); - $filefull = $ffwf; } $infothm = $exifToolObj->ImageInfo($filefull); @@ -1364,7 +1367,7 @@ sub contactSheetGenerator { $readres = $image->Read($thumbnailes_sorted[$csIter]); if (not $readres) { dbgmsg (4, "$thumbnailes_sorted[$csIter] was successfully read.\n"); - } else { errmsg ("Image::Magick error: $readres\n\n"); } + } else { errmsg ("Image::Magick error: $readres\n"); } # ranking $substrFile = substr($thumbnailes_sorted[$csIter], length($cfgOpts{'contact sheet dir'}) + 1); @@ -1391,7 +1394,7 @@ sub contactSheetGenerator { stroke => 'none', ); - if (not ref($montage)) { errmsg ("Image::Magick error: $montage\n\n"); } + if (not ref($montage)) { errmsg ("Image::Magick error: $montage\n"); } else { dbgmsg (1, "$csIterator montage've finished successfully.\n"); } $montage->Set ( @@ -1418,8 +1421,8 @@ sub contactSheetGenerator { text => $left_up_row[1], ); $writeres = $montage->Write(); - if (not $writeres) { dbgmsg (1, "Successfully written $montagename file.\n\n"); } - else { errmsg ("Image::Magick error: $writeres\n\n"); } + if (not $writeres) { dbgmsg (1, "Successfully written $montagename file.\n"); } + else { errmsg ("Image::Magick error: $writeres\n"); } $infoMontage = $exifToolObj->ImageInfo($montagename); @@ -1451,7 +1454,7 @@ sub contactSheetGenerator { for ($readIndex = 0, $csIteration = $csIterator * $tileMul; $csIteration < $csIterationNumber; $csIteration++, $readIndex++) { $readres = $image->Read($thumbnailes_sorted[$csIteration]); if (not $readres) { dbgmsg (4, "$thumbnailes_sorted[$csIteration] was successfully red.\n"); } - else { errmsg ("Image::Magick error: $readres\n\n"); } + else { errmsg ("Image::Magick error: $readres\n"); } # ranking $substrFile = substr($thumbnailes_sorted[$csIteration], length($cfgOpts{'contact sheet dir'}) + 1); @@ -1482,7 +1485,7 @@ sub contactSheetGenerator { stroke => 'none', ); - if (not ref($montage)) { errmsg ("Image::Magick error: $montage\n\n"); } + if (not ref($montage)) { errmsg ("Image::Magick error: $montage\n"); } else { dbgmsg (1, "Montage've finished successfully.\n"); } $montage->Set ( @@ -1509,8 +1512,8 @@ sub contactSheetGenerator { text => $left_up_row[1], ); $writeres = $montage->Write(); - if (not $writeres) { dbgmsg (1, "Successfully written $montagename file.\n\n"); } - else { errmsg ("Image::Magick error: $writeres\n\n"); } + if (not $writeres) { dbgmsg (1, "Successfully written $montagename file.\n"); } + else { errmsg ("Image::Magick error: $writeres\n"); } undef $image; $infoMontage = $exifToolObj->ImageInfo($montagename); @@ -1555,7 +1558,7 @@ sub thm_gen_stub { my $thmbnum = $thmb->Write(); - if ($thmbnum) { errmsg ("$thmbnum\n\n"); } + if ($thmbnum) { errmsg ("$thmbnum\n"); } undef $thmb; procmsg ("Stub thumbnail image has been created.\n"); @@ -1586,7 +1589,7 @@ sub thm_gen_orig { my $thmbnum = $thmb->Write(); - if ($thmbnum) { errmsg ("$thmbnum\n\n"); } + if ($thmbnum) { errmsg ("$thmbnum\n"); } undef $thmb; if ($unlink) { |