/usr/bin/ppmfade is in netpbm 2:10.0-15ubuntu2.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 | #!/usr/bin/perl -w
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
# This program creates a fade (a sequence of frames) between two images.
#
# Author: Wesley C. Barris
# AHPCRC
# Minnesota Supercomputer Center, Inc.
# Date: January 7, 1994
#
# Converted to perl and renamed from pbmfade to ppmfade by Bryan Henderson
# on March 31, 2000 for inclusion in Netpbm. Also, superfluous ability to
# process other formats removed.
#
# Copyright @ 1994, Minnesota Supercomputer Center, Inc.
#
# RESTRICTED RIGHTS LEGEND
#
# Use, duplication, or disclosure of this software and its documentation
# by the Government is subject to restrictions as set forth in subdivision
# { (b) (3) (ii) } of the Rights in Technical Data and Computer Software
# clause at 52.227-7013.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
use strict;
use File::Temp "tempdir";
my $SPREAD = 1;
my $SHIFT = 2;
my $RELIEF = 3;
my $OIL = 4;
my $EDGE = 5;
my $BENTLEY = 6;
my $BLOCK = 7;
my $MIX = 8;
#
# Set some defaults.
#
my $nframes = 30; # total number of files created (1 sec)
my $first_file = "undefined";
my $last_file = "undefined";
my $base_name = "fade"; # default base name of output files
my $image = "ppm"; # default output storage format
my $mode = $SPREAD; # default fading mode
#
# Check those command line args.
#
if (@ARGV == 0) {
usage();
}
my $n; # argument number
for ($n = 0; $n < @ARGV; $n++) {
if ("$ARGV[$n]" eq "-f") {
$n++;
$first_file = $ARGV[$n];
if (-e $first_file) {
} else {
print "I can't find $first_file\n";
exit 20;
}
} elsif ($ARGV[$n] eq "-l") {
$n++;
$last_file = $ARGV[$n];
if (-e $last_file) {
} else {
print "I can't find $last_file\n";
exit 20;
}
} elsif ($ARGV[$n] eq "-base") {
$n++;
$base_name = $ARGV[$n];
} elsif ($ARGV[$n] eq "-spread") {
$mode = $SPREAD;
} elsif ($ARGV[$n] eq "-shift") {
$mode = $SHIFT;
} elsif ($ARGV[$n] eq "-relief") {
$mode = $RELIEF;
} elsif ($ARGV[$n] eq "-oil") {
$mode = $OIL;
} elsif ("$ARGV[$n]" eq "-edge") {
$mode = $EDGE;
} elsif ("$ARGV[$n]" eq "-bentley") {
$mode = $BENTLEY;
} elsif ("$ARGV[$n]" eq "-block") {
$mode = $BLOCK;
} elsif ("$ARGV[$n]" eq "-mix") {
$mode = $MIX;
} elsif ($ARGV[$n] eq "-help" || $ARGV[$n] eq "-h") {
usage();
} else {
print "Unknown argument: $ARGV[$n]\n";
exit 100;
}
}
#
# Define a couple linear ramps.
#
# We don't use element 0 of these arrays.
my @spline10 = (0, 0, 0.11, 0.22, 0.33, 0.44, 0.55, 0.66, 0.77, 0.88, 1.0);
my @spline20 = (0, 0, 0.05, 0.11, 0.16, 0.21, 0.26, 0.32, 0.37, 0.42, 0.47,
0.53, 0.58, 0.63, 0.69, 0.74, 0.79, 0.84, 0.89, 0.95, 1.0);
#
# Just what are we supposed to do?
#
my ($height, $width); # width and height of our frames
if ($first_file ne "undefined") {
if ((`pnmfile $first_file` =~ m{\b(\d+)\sby\s(\d+)} )) {
$width = $1; $height = $2;
} else {
print("Unrecognized results from pnmfile on $first_file.\n");
exit(50);
}
} elsif ($last_file ne "undefined") {
if ((`pnmfile $last_file` =~ m{\b(\d+)\sby\s(\d+)} )) {
$width = $1; $height = $2;
} else {
print("Unrecognized results from pnmfile on $first_file.\n");
exit(50);
}
} else {
print("ppmfade: You must specify -f or -l (or both)\n");
exit(90);
}
print("Frames are " . $width . "W x " . $height . "H\n");
#
# We create a tmp-directory right here
#
my $tempdir = tempdir("ppmfade.XXXXXXX", CLEANUP => 1);
if ($first_file eq "undefined") {
print "Fading from black to ";
system("ppmmake \\#000 $width $height >$tempdir/junk1.ppm");
} else {
print "Fading from $first_file to ";
system("cp", $first_file, "$tempdir/junk1.ppm");
}
if ($last_file eq "undefined") {
print "black.\n";
system("ppmmake \\#000 $width $height >$tempdir/junk2.ppm");
} else {
print "$last_file\n";
system("cp", $last_file, "$tempdir/junk2.ppm");
}
#
# Perform the fade.
#
# Here's what our temporary files are:
# junk1.ppm: The original (fade-from) image
# junk2.ppm: The target (fade-from) image
# junk3.ppm: The frame of the fade for the current iteration of the
# the for loop.
# junk1a.ppm: If the fade involves a ppmmix sequence from one intermediate
# image to another, this is the first frame of that
# sequence.
# junk2a.ppm: This is the last frame of the above-mentioned ppmmix sequence
my $i; # Frame number
for ($i = 1; $i <= $nframes; $i++) {
print("Creating $i of $nframes...\n");
if ($mode eq $SPREAD) {
if ($i <= 10) {
my $n = $spline20[$i] * 100;
system("ppmspread $n $tempdir/junk1.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n;
$n = $spline20[$i] * 100;
system("ppmspread $n $tempdir/junk1.ppm >$tempdir/junk1a.ppm");
$n = (1-$spline20[$i-10]) * 100;
system("ppmspread $n $tempdir/junk2.ppm >$tempdir/junk2a.ppm");
$n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1a.ppm $tempdir/junk2a.ppm >$tempdir/junk3.ppm");
} else {
my $n = (1-$spline20[$i-10])*100;
system("ppmspread $n $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
} elsif ($mode eq $SHIFT) {
if ($i <= 10) {
my $n = $spline20[$i] * 100;
system("ppmshift $n $tempdir/junk1.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n;
$n = $spline20[$i] * 100;
system("ppmshift $n $tempdir/junk1.ppm >$tempdir/junk1a.ppm");
$n = (1-$spline20[$i-10])*100;
system("ppmshift $n $tempdir/junk2.ppm >$tempdir/junk2a.ppm");
$n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1a.ppm $tempdir/junk2a.ppm >$tempdir/junk3.ppm");
} else {
my $n = (1-$spline20[$i-10]) * 100;
system("ppmshift $n $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
} elsif ($mode eq $RELIEF) {
if ($i == 1) {
system("ppmrelief $tempdir/junk1.ppm >$tempdir/junk1r.ppm");
}
if ($i <= 10) {
my $n = $spline10[$i];
system("ppmmix $n $tempdir/junk1.ppm $tempdir/junk1r.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1r.ppm $tempdir/junk2r.ppm >$tempdir/junk3.ppm");
} else {
my $n = $spline10[$i-20];
system("ppmmix $n $tempdir/junk2r.ppm $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
if ($i == 10) {
system("ppmrelief $tempdir/junk2.ppm >$tempdir/junk2r.ppm");
}
} elsif ($mode eq $OIL) {
if ($i == 1) {
system("ppmtopgm $tempdir/junk1.ppm | pgmoil >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk1o.ppm");
}
if ($i <= 10) {
my $n = $spline10[$i];
system("ppmmix $n $tempdir/junk1.ppm $tempdir/junk1o.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1o.ppm $tempdir/junk2o.ppm >$tempdir/junk3.ppm");
} else {
my $n = $spline10[$i-20];
system("ppmmix $n $tempdir/junk2o.ppm $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
if ($i == 10) {
system("ppmtopgm $tempdir/junk2.ppm | pgmoil >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk2o.ppm");
}
} elsif ($mode eq $EDGE) {
if ($i == 1) {
system("ppmtopgm $tempdir/junk1.ppm | pgmedge >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk1o.ppm");
}
if ($i <= 10) {
my $n = $spline10[$i];
system("ppmmix $n $tempdir/junk1.ppm $tempdir/junk1o.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1o.ppm $tempdir/junk2o.ppm >$tempdir/junk3.ppm");
} else {
my $n = $spline10[$i-20];
system("ppmmix $n $tempdir/junk2o.ppm $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
if ($i == 10) {
system("ppmtopgm $tempdir/junk2.ppm | pgmedge >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk2o.ppm");
}
} elsif ($mode eq $BENTLEY) {
if ($i == 1) {
system("ppmtopgm $tempdir/junk1.ppm | pgmbentley >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk1o.ppm");
}
if ($i <= 10) {
my $n = $spline10[$i];
system("ppmmix $n $tempdir/junk1.ppm $tempdir/junk1o.ppm >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1o.ppm $tempdir/junk2o.ppm >$tempdir/junk3.ppm");
} else {
my $n = $spline10[$i-20];
system("ppmmix $n $tempdir/junk2o.ppm $tempdir/junk2.ppm >$tempdir/junk3.ppm");
}
if ($i == 10) {
system("ppmtopgm $tempdir/junk2.ppm | pgmbentley >$tempdir/junko.ppm");
system("rgb3toppm $tempdir/junko.ppm $tempdir/junko.ppm $tempdir/junko.ppm " .
">$tempdir/junk2o.ppm");
}
} elsif ($mode eq $BLOCK) {
if ($i <= 10) {
my $n = 1 - 1.9*$spline20[$i];
system("pnmscale $n $tempdir/junk1.ppm | " .
"pnmscale -width $width -height $height >$tempdir/junk3.ppm");
} elsif ($i <= 20) {
my $n = $spline10[$i-10];
system("ppmmix $n $tempdir/junk1a.ppm $tempdir/junk2a.ppm >$tempdir/junk3.ppm");
} else {
my $n = 1 - 1.9*$spline20[31-$i];
system("pnmscale $n $tempdir/junk2.ppm | " .
"pnmscale -width $width -height $height >$tempdir/junk3.ppm");
}
if ($i == 10) {
system("cp", "$tempdir/junk3.ppm", "$tempdir/junk1a.ppm");
system("pnmscale $n $tempdir/junk2.ppm | " .
"pnmscale -width $width -height $height >$tempdir/junk2a.ppm");
}
} elsif ($mode eq $MIX) {
my $fade_factor = sqrt(1/($nframes-$i+1));
system("ppmmix $fade_factor $tempdir/junk1.ppm $tempdir/junk2.ppm >$tempdir/junk3.ppm");
} else {
print("Internal error: impossible mode value '$mode'\n");
}
my $outfile = sprintf("%s.%04d.ppm", $base_name, $i);
system("cp", "$tempdir/junk3.ppm", $outfile);
}
# The temporary files are automatically deleted
exit(0);
sub usage() {
print "Usage: ppmfade [-f first_file] [-l last_file]\n";
print " [-spread|-relief|-oil|-edge|-bentley|-block]\n";
print " [-base basename]\n";
print "Notes: Default base: fade\n";
print " The resulting image files will be named fade.NNNN.ppm.\n";
exit(100);
}
|