Article View: comp.lang.postscript
Article #114Re: EPS preview bitmap
From: Kevin Grover
Date: Mon, 02 Nov 1992 22:35
Date: Mon, 02 Nov 1992 22:35
135 lines
5506 bytes
5506 bytes
In article <1992Nov2.202828.26752@ee.rochester.edu>, cherkaue@ee.rochester.edu (Brian Cherkauer) writes:
) From: cherkaue@ee.rochester.edu (Brian Cherkauer)
) Subject: EPS preview bitmap
) Date: Mon, 2 Nov 92 12:28:28 PST
) Organization: Univ of Rochester, College of Engineering and Applied Science
)
) Forgive me if this is a FAQ, but I read through as much of the monthly
) posting as I had time to and didn't see it anywhere.
)
) I'm in need of a utility which can take an eps file which does not contain
) a "preview bitmap" and generate the preview bitmap so that graphics
) editors which contain no postscript interpretors, yet allow for the
) inclusion of eps files, are able to display the image on screen.
)
) Specifically, I'm working on a Sun4 (SunOS-4.1.1) with OpenWindows 3
) using eps files generated through gnuplot v3.2 and included into xfig v2.1.4.
)
I've written a little PERL script that sorta-almost does this. You
need to convert the PS to a bitmap (PBM to be exact) and crop it to
the correct size, before it'll work
What i do:
1) us ghostscript to create the pbm file
2) use xv to to crop the pbm file
3) run pbm2pspre to create a PostScript Preview section from
the pbm file (I write it to a file)
4) insert this info into original PS file
What could be done
- use pnmcut to do the croping automatically
- I should also modify the script to accept ascii versions
(currently only raw files are accpted) and also pgm files
should be allowed.)
- modify the PERL script to insert the code into to correct
place in the original PS file.
(These modifications could make the entire process automatic
assuming the original PS file had some minimal DSC comments
in it).
--------------------------------------------------------------------------
Kevin O. Grover | UNLV Computer Science and Electrical Engineering
grover@isri.unlv.edu | ISRI - Information Science Research Institute
CServe: [73627,1677] | 4505 S. Maryland Parkway, Las Vegas NV 89154-1017
Here's the PERL script. NOTE: It's very limited right now...
#!/local/perl/bin/perl
# =================================================================== pbm2pspre
# Convert a PBM file to an EPSF Preview section (in the EPSI
# "Encapsulated PostScript Interchange" format).
# According to the EPSF Specification 3.0, the output of this program
# should be included in the EPSF file directly after the
# "%%EndComments" comment.
#
# - Kevin O. Grover, grover@isri.unlv.edu
# 04 Jun 1992 - Original Version (PBM Raw only)
#
# I use this when I design a PostScript image or logo that is fairly
# static. First, I use GhostScript (2.4.1 currently) to create a
# PBMRAW file which I feed to this program to generate the
# PostScript Preview, which I instert into the original PS code (so
# that the preview can be used on systems that support it.)
#
# To Do:
# - Make it handle 8-bit PGM files
# - Make it handle 8-bit RGB (PPM) files, use formula in Image Processing
# book to come up with a gray value based on the RGB values
# - Allow it to handle ASCII versions (as well as raw versions)
# - When all of above implemented, rename to "pnm2pspre"
# =============================================================================
# Get the filename from the command line
$file = shift @ARGV || die "Usage: pbm2pspre file\n";
# Open the file
open(IN, "<" . $file) || die "Can't open file $file: $!\n";
# Get first line and make sure file is PBM Raw format
<IN> =~ m/^P4/o || die "$file: not a pbm raw file (P4)\n";
# Skip all comment lines
while (($l = <IN>) =~ m/^#/) {} # Skip Comments
# Get the height and width info from line following comments
$l =~ m/(\d+) (\d+)/;
$x = $1; $y = $2;
# Put file into binary mode (in case this is an MSDOS machine)
binmode(IN);
# Find the number of bytes per line of image (8 bits per byte)
$bytesperline = int($x/8);
if (($x/8)-$bytesperline) { $bytesperline++; }
# Find the number of lines in the file needed for 35 pixels (2 bytes
# each = 70 characters) per line of the file
$numlines = int($bytesperline * $y / 35);
if (($bytesperline*$y/35)-$numlines) { $numlines++; }
# Print the DSC comments
print "%%BeginPreview: $x $y 1 $numlines\n";
# Process each pixel (i.e. read 1 byte at a time)
$chars = 0;
$needcmt = 1;
while (read(IN,$c,1)) {
$c = unpack("C",$c); # Extract value
if ($needcmt) { # Print ps comment if needed
print "%";
$needcmt = 0;
}
printf ("%02X", $c); # Print Hex value
if ( ($char += 2) == 70 ) { # Do newline if needed
print "\n";
$char = 0;
$needcmt = 1;
}
}
if ($char) { print "\n"; }
print "%%EndPreview\n";
close(IN);
Technical Details
Message-ID:
<1992Nov2.223526.28957@unlv.edu>Path:
arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!mrccrc!doc.ic.ac.uk!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!caen!nic.umass.edu!news.mtholyoke.edu!news.unomaha.edu!nevada.edu!jimi!mighty-joe.isri.unlv.edu!groverReferences:
<1992Nov2.202828.26752@ee.rochester.edu>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.postscript Path: arc1-ca.pugleaf.net!sparky!uunet!pipex!warwick!mrccrc!doc.ic.ac.uk!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!uwm.edu!caen!nic.umass.edu!news.mtholyoke.edu!news.unomaha.edu!nevada.edu!jimi!mighty-joe.isri.unlv.edu!grover From: grover@mighty-joe.isri.unlv.edu (Kevin Grover) Subject: Re: EPS preview bitmap Message-ID: <1992Nov2.223526.28957@unlv.edu> Sender: news@unlv.edu (News User) Reply-To: grover@isri.unlv.edu Organization: Information Science Research Institute (UNLV-ISRI) References: <1992Nov2.202828.26752@ee.rochester.edu> Date: Mon, 2 Nov 92 22:35:26 GMT Lines: 136