#!/usr/bin/perl -w # Copyright 2000 by Zygo Blaxell use strict; my $count = shift(@ARGV) || 30; my $rate = shift(@ARGV) || 1; my $xsize = shift(@ARGV) || 900; my $ysize = shift(@ARGV) || 720; my $isize = shift(@ARGV) || '640x480'; # Handy constant... my $pi = atan2(1,0) * 2; # and function... sub rad { $_[0] / (180/$pi); } # Combine functions my @functions = qw( over over over over in out atop xor plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference plus minus add subtract difference bumpmap bumpmap replacered replacegreen replaceblue replacered replacegreen replaceblue replacematte ); # These are possible, but suck: # replace # These variables are twiddled if the geometry of the final image # significantly changes after mogrification. my $geowidth; my $geoheight; # mogrify operations my @operations = ( .1, sub { '-antialias'; }, .1, sub { '-blur ' . (rand() * 100); }, .1, sub { sprintf('-bordercolor "#%02x%02x%02x"', map(int(rand()*256), (1..3))); }, .05, sub { '-charcoal ' . (rand() * 100); }, .05, sub { rand() < .5 ? '-colorize ' . int(rand() * 100) : '-colorize ' . join('/', map(int(rand() * 100), (1..3))); }, .1, sub { rand() < .5 ? '-contrast' : '+contrast'; }, .05, sub { '-cycle ' . int(rand() * 256); }, .5, sub { '-despeckle'; }, .5, sub { '-dither'; }, .01, sub { '-edge ' . (rand() * 100); }, .05, sub { '-emboss'; }, .5, sub { '-enhance'; }, .1, sub { '-equalize'; }, .1, sub { '-flip'; }, .1, sub { '-flop'; }, .1, sub { rand() < .5 ? '-gamma ' . ((rand() * 1.5) + 0.8) : '-gamma ' . join('/', map((rand() * 1.5 + 0.8), (1..3))); }, .1, sub { '-implode ' . (rand() * 200 - 100); }, .1, sub { '-layer ' . ((qw(Red Green Blue Matte)) [int(rand() * 4)]); }, .1, sub { rand() < .5 ? '-modulate ' . (rand() * 200 - 100) : '-modulate ' . join('/', map((rand() * 200 - 100), (1..3))); }, .05, sub { my $r = rand(); if ($r > 2/3) { return '-monochrome'; } elsif ($r > 1/3) { return '-threshold ' . int(rand() * 256); } else { return '-colors ' . int(rand() * 254 + 2) . ' -colorspace ' . ((qw(GRAY OHTA RGB Transparent XYZ YCbCr YIQ YPbPr YUV CMYK)) [int(rand() * 10)]) . ' -dispose ' . int(rand() * 4) . ' -fuzz ' . int(rand() * 256) . ' -treedepth ' . int(rand() * 9); } }, .1, sub { rand() < .5 ? '-negate' : '+negate'; }, .1, sub { rand() < .5 ? '-noise' : '+noise ' . ((qw(Uniform Gaussian Multiplicative Impulse Laplacian Poisson)) [int(rand() * 6)]); }, .5, sub { '-normalize'; }, .1, sub { '-paint ' . int(rand() * 8); }, .1, sub { sprintf('-roll %+d%+d', int(rand() * $xsize * 2 - $xsize), int(rand() * $xsize * 2 - $xsize)); }, .75, sub { my $angle = int(rand() * 360); my $t = rad($angle); $geowidth = int(abs(cos($t)*$geowidth) + abs(cos($t+$pi/2)*$geoheight) + .9); $geoheight = int(abs(sin($t)*$geowidth) + abs(sin($t+$pi/2)*$geoheight) + .9); "-rotate $angle"; }, .1, sub { sprintf('%sshade %dx%d', rand() < .5 ? '-' : '+', map(int(rand() * 360) || '0.0', (1..2))); }, .25, sub { my $anglex = int(rand() * 90) - 45; my $angley = int(rand() * 90) - 45; my $t = rad($anglex); my $u = rad($angley); $geowidth += int(abs(sin($t) * $geoheight) + .9); $geoheight += int(abs(sin($u) * $geowidth) + .9); "-shear ${anglex}.0x${angley}"; }, .1, sub { '-solarize ' . int(rand() * 256); }, .1, sub { '-spread ' . int(rand() * 64); }, .1, sub { '-swirl ' . int(rand() * 360); }, .5, sub { sprintf('-transparency "#%02x%02x%02x"', map(int(rand()*256), (1..3))); }, .1, sub { sprintf('-wave %dx%d', int(rand() * $ysize/25) + 1, int(rand() * $xsize) + 1); }, # Must appear after all the others because width/height could be modified above .1, sub { my $xs = int(rand() * $geowidth); my $ys = int(rand() * $geoheight); sprintf( '-region %dx%d+%d+%d', $xs, $ys, int(rand() * ($geowidth - $xs)), int(rand() * ($geoheight - $ys)) ); }, ); # Too slow! # sub { sprintf('-segment %dx%g', int(rand() * 64), (rand() * 5)); }, # These just suck... # sub { sprintf('%sraise %dx%d', rand() < .5 ? '-' : '+', int(rand() * 32), int(rand() * 24)); }, # Can't actually use these effects: # sub { '-quality ' . int(rand() * 100); }, # sub { rand() < .5 ? sprintf('-crop %dx%d+%d+%d', map( (int(rand() * $xsize), int(rand() * $ysize)), (1..2))) : '-crop 0x0'; }, # sub { '-filter ' . ((qw(Point Box Triangle Hermite Hanning Hamming Blackman Gaussian Quadratic Cubic Catrom Mitchell Lanczos Bessel Sinc)) [int(rand() * 15)]); }, my $targetratio; if ($xsize/$ysize > 640/480) { $targetratio = $ysize/480; } else { $targetratio = $xsize/640; } my $maxratio = $targetratio * 1.6; my $minratio = $targetratio / 3.2; $minratio = .1 if $minratio < .1; $maxratio = 10 if $maxratio > 10; print STDERR "Ratio = ($minratio .. $maxratio)\n"; die "Maxratio < Minratio" unless $maxratio >= $minratio; my @numbers = sort { rand() < .5 } (0..($count-1)); my $lastname = "."; my $tmpdir = "/tmp/ashget-$$"; my $verbose = '$verbose'; my $igff = 'png'; my $cgff = 'ppm'; # Ultra cheezy way to get an constant-color image with all-zero matte layer print <&1 exec >&2 trap 'rm -rf $tmpdir' 0 mkdir $tmpdir || exit 1 cd $tmpdir || exit 1 streamer -n ntsc -f ppm -r $rate -s $isize -t $count -o img000.ppm rm -f null.$igff scaled.$igff combined.$igff echo -n 2224222422242224 | tr '01234' '\\0\\100\\200\\300\\377' | convert $verbose -size 2x2 -geometry ${xsize}x${ysize}! rgba:- null.$igff PREAMBLE for my $num (@numbers) { my $unscaledname = sprintf("img%03d.$cgff", $num); my $scaledname = sprintf("img%03d.$igff", $num); my $ratio = (rand() * ($maxratio-$minratio) ) + $minratio; $geowidth = int(640*$ratio); $geoheight = int(480*$ratio); my $operation = join(' ', map( (rand() < $operations[$_*2]) ? &{$operations[$_*2+1]} : (), (0..($#operations/2)))); my $geoleft = int((rand() * ($xsize - $geowidth * 1.1)) - $geowidth * .1); my $geotop = int((rand() * ($ysize - $geoheight * 1.1)) - $geoheight * .1); my $cropleft = $geoleft < 0 ? -$geoleft : 0; my $croptop = $geotop < 0 ? -$geotop : 0; $geoleft = $geoleft < 0 ? 0 : $geoleft; $geotop = $geotop < 0 ? 0 : $geotop; my $crop = "-crop +${cropleft}+${croptop}"; my $geometry = "-geometry +${geoleft}+${geotop}"; print <= 1) { my $left = shift(@numbers); my $leftname = sprintf("img%03d.$igff", $left); my $right = shift(@numbers); my $rightname = sprintf("img%03d.$igff", $right); my $function = $functions[int(rand()*($#functions+1))]; my $percentage = int(rand() * 90) + 10; print <&3 POSTAMBLE