#!/usr/bin/perl # # $Id: showcase2html,v 1.23 1999/09/30 22:41:09 sc Exp $ # # --- Legal Statement --------------------------------------------------------- # # Copyright (c) 1999, Silicon Graphics, Inc. -- ALL RIGHTS RESERVED # # Permission is granted to copy, modify, use and distribute this software # free of charge provided you include the entirety of this notice in all # copies made. # # THIS SOFTWARE IS PROVIDED ON AN 'AS IS' BASIS, WITHOUT WARRANTY OF ANY # KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, # WARRANTIES THAT THE SUBJECT SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT # FOR A PARTICULAR PURPOSE OR NON-INFRINGING. SGI ASSUMES NO RISK AS TO THE # QUALITY AND PERFORMANCE OF THE SOFTWARE. SHOULD THE SOFTWARE PROVE # DEFECTIVE IN ANY RESPECT, SGI ASSUMES NO COST OR LIABILITY FOR ANY # SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES # AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY SUBJECT SOFTWARE IS # AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. # # UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING, # WITHOUT LIMITATION, NEGLIGENCE OR STRICT LIABILITY), CONTRACT, OR # OTHERWISE, SHALL SGI BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL, # INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER WITH RESPECT TO THE # SOFTWARE INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL, WORK # STOPPAGE, LOSS OF DATA, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL # OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SGI SHALL HAVE BEEN INFORMED OF # THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT # APPLY TO LIABILITY RESULTING FROM SGI's NEGLIGENCE TO THE EXTENT APPLICABLE # LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE # EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT # EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. # # These license terms shall be governed by and construed in accordance with # the laws of the United States and the State of California as applied to # agreements entered into and to be performed entirely within California # between California residents. Any litigation relating to these license # terms shall be subject to the exclusive jurisdiction of the Federal Courts # of the Northern District of California (or, absent subject matter # jurisdiction in such courts, the courts of the State of California), with # venue lying exclusively in Santa Clara County, California. # # ----------------------------------------------------------------------------- # # This converter needs "gs" (GhostScript) and the netpbm utilities. It can # be made to produce transparent slides which can then be placed on a different # coloured background. If you have the tools, you can also generate any other # type of image file as the output. # # This doesn't seem to work for 5.001. You really should have a more up to # date version anyway! require 5.003; use Carp; use File::Basename; use Getopt::Long; $VERSION = sprintf("%d.%02d", q$Revision: 1.23 $ =~ /(\d+)\.(\d+)/); $width = 550; &GetOptions ("width=i" => \$width, "portrait" => \$portrait, "quality=s" => \$quality, "transparent:s" => \$transparency); $temp_prefix = ".out.$$"; $temp = $temp_prefix . '-%02d.ppm'; $name = shift; $showcase_hack = '| sed -e \'s/1e\+30 [0-9][0-9\.]* M//g\''; if ($name =~ m/\.sc$/) { $base = basename ($name, '.sc'); $cvter = 'showcase -p ' . $name; $cvter .= $showcase_hack; } elsif ($name =~ m/(\.e?ps)$/) { $base = basename ($name, $1); $cvter = 'cat ' . $name; $cvter .= $showcase_hack; } elsif ($name =~ m/(\.pdf)$/) { $base = basename ($name, $1); undef $cvter; } else { croak "Unknown file type, cannot convert\n"; } if (defined $quality) { $dpi = ($quality eq 'high') ? 300 : ($quality eq 'low') ? 50 : 100; } else { $dpi = 100; } print "Converting $name -> image files\n"; if (defined $cvter) { system "$cvter | gs -q -r$dpi -dNOPAUSE -sDEVICE=ppmraw -sOutputFile='${temp}' - -c quit"; } else { system "gs -q -r$dpi -dNOPAUSE -sDEVICE=ppmraw -sOutputFile='${temp}' $name -c quit"; } opendir (DIR, '.'); @cvtnames = grep (/^$temp_prefix/, readdir(DIR)); if (defined $portrait) { $scale = "pnmscale -xsize $width 2>/dev/null"; $rot = ''; } else { # Scaling occurs before rotation $scale = "pnmscale -ysize $width 2>/dev/null"; $rot = 'pnmrotate -90 2>/dev/null'; } $quant = 'ppmquant 256 2>/dev/null'; if ($transparency) { $transparency = "#ffffff" if ($transparency eq ''); $transparency = "#ffffff" if (lc($transparency) eq 'white'); $transparency = "#000000" if (lc($transparency) eq 'black'); $conv = 'ppmtogif -transparent ' . "\Q${transparency}\E" . ' 2>/dev/null'; } else { $conv = 'ppmtogif 2>/dev/null'; } foreach $in (sort @cvtnames) { ($out=$in) =~ s/^${temp_prefix}(-\d+).ppm$/${base}\1.gif/; ($tmp1=$in) =~ s/^(${temp_prefix}-\d+).ppm$/\1-1.ppm/; ($tmp2=$in) =~ s/^(${temp_prefix}-\d+).ppm$/\1-2.ppm/; $namemap{$in} = $out; print "Converting $in -> $out\n"; system "$scale $in >$tmp1"; unlink $in; if ($rot) { system "$rot $tmp1 >$tmp2"; unlink $tmp1; } else { rename $tmp1, $tmp2; } system "$quant $tmp2 >$tmp1"; unlink $tmp2; # For some reason the first column will end up containing junk pixels. # This will show up as a line if you turn on transparency -- the solution # is to remove the first column of pixels. $size = `pnmfile $tmp1`; ($type, $x, $y) = ($size =~ m/PPM (raw|plain), (\d+) by (\d+)/); if ($x && $y and $x != 0 and $y != 0) { $crop = "pnmcut 1 0 " . ($x-1) . " " . $y . " 2>/dev/null"; $sizemap{$in} = join (",", ($x-1), $y); system "$crop $tmp1 >$tmp2"; rename $tmp2, $tmp1; } system "$conv $tmp1 >$out"; unlink $in, $tmp1, $tmp2; } print "Creating HTML file ${base}.html\n"; open (HTML, ">${base}.html") || croak 'cannot create html output file'; print HTML <<_EOF_;
Conversion courtesy of showcase2html (Version $VERSION)
by Simon Cooper