#!/usr/bin/env perl # bmp2png.wrapper - Wrapper for "bmp2png" # License: BSD-style # Revision: 071103 #--------------------------------------------------------------------- # module setup #--------------------------------------------------------------------- require 5.6.1; use strict; use Carp; use warnings; # Trap warnings $SIG {__WARN__} = sub { die @_; }; #--------------------------------------------------------------------- # basic constants #--------------------------------------------------------------------- use constant ZERO => 0; # Zero use constant ONE => 1; # One use constant FALSE => 0; # Boolean FALSE use constant TRUE => 1; # Boolean TRUE #--------------------------------------------------------------------- # main routine #--------------------------------------------------------------------- sub Main { my $ifname; my $ofname; my $tmp_pnm = "$>_1.tmp"; my $tmp_png = "$>_2.tmp"; my $FlagOptimize; $FlagOptimize = TRUE; $FlagOptimize = FALSE if $0 =~ m@/[^/]*fast[^/]*\z@i; for $ifname (@ARGV) { next if $ifname =~ m@^-@; next if $ifname !~ m@\.bmp\z@i; $ofname = $ifname; $ofname =~ s@\.bmp\z@.png@i; system ("bmp2png.bin -9 -O $tmp_png $ifname"); #ifdef NOTDEF # Old version - Uses "pngcrush" # system ("pngcrush $tmp_png $ofname") if $FlagOptimize; #else # New version - Uses "optipng" system ("optipng $tmp_png") if $FlagOptimize; rename ($tmp_png, $ofname); #endif # Endif NOTDEF unlink $tmp_png; my $mtime = (stat $ifname) [9]; if (defined ($mtime)) { utime ($mtime, $mtime, $ofname) || die "Error: Can't set timestamp: $!:\n$ofname\n"; } print "$ofname\n"; } undef; } #--------------------------------------------------------------------- # main program #--------------------------------------------------------------------- &Main(); # Call the main routine exit ZERO; # Normal exit