🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: comp.lang.postscript
3 messages
3 total messages Started by Brian Cherkauer Mon, 02 Nov 1992 20:28
EPS preview bitmap
#109
Author: Brian Cherkauer
Date: Mon, 02 Nov 1992 20:28
17 lines
1073 bytes
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.
 
Could someone please suggest something?
 
Thanks,
 
Brian Cherkauer
  cherkaue@ee.rochester.edu
Re: EPS preview bitmap
#114
Author: Kevin Grover
Date: Mon, 02 Nov 1992 22:35
135 lines
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);
Re: EPS preview bitmap
#110
Author: Jon White
Date: Mon, 02 Nov 1992 22:47
234 lines
7313 bytes
cherkaue@ee.rochester.edu (Brian Cherkauer) writes:
: 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.

eps2epsi is a perl script written by Gisle Aas that converts 
all types of EPS files to the EPSI format with a preview bitmap.  
Enjoy...

--cut here--
#!/bin/sh
# This is a shell archive (produced by shar 3.49)
# To extract the files from this archive, save it to a file, remove
# everything above the "!/bin/sh" line above, and type "sh file_name".
#
# made 09/23/1992 11:04 UTC by aas@solnes
# Source directory /nr/boeygen/u2/aas/eps2epsi
#
# existing files will NOT be overwritten unless -c is specified
#
# This shar contains:
# length  mode       name
# ------ ---------- ------------------------------------------
#   5005 -rwxr-xr-x eps2epsi
#
# ============= eps2epsi ==============
if test -f 'eps2epsi' -a X"$1" != X"-c"; then
        echo 'x - skipping eps2epsi (File already exists)'
else
echo 'x - extracting eps2epsi (Text)'
sed 's/^X//' << 'SHAR_EOF' > 'eps2epsi' &&
#!/usr/local/bin/perl
'di';
'ig00';
X
# EPSI file generator. Written by Gisle Aas, NR, 1991
# Converts all types of EPS-files to the EPSI format where a bitmap preview
# is included. You need GhostScript to render the bitmaps for you.
X
# $Log: eps2epsi,v $
# Revision 1.4  1992/09/08  17:41:27  aas
# Some applications makes real (not integer) boundingbox coordinates, despite
# what the DSC says.  These applications should really be fixed.  But while we
# wait for that to happen....
#
# Revision 1.3  1992/08/25  14:56:05  aas
# Hvis kommentarene i begynnelsen ikke sluttet med %%EndComments, se spiste
# vi opp fxrste linje av postscript koden.
#
# Revision 1.2  1992/07/30  13:32:19  aas
# Oppdatert for GhostScript versjon 2.4.  Det var ny syntaks for
# makeimagedevice.
#
# Revision 1.1  1991/05/28  09:18:04  aas
# Initial revision
#
X
$prog_name = substr($0,rindex($0,"/")+1);
require 'getopts.pl';
unless (&Getopts('w:')) {
X  print STDOUT "Usage: $prog_name [-w <preview width>] [<file>]\n";
X  exit 1;
}
X
die 'To many files' if ($#ARGV > 0);
X
@epsfile = <>;                  # slurp
die 'Not PostScript file' unless ($epsfile[0] =~ /^%!PS-Adobe-/);
X
# Get the dimensions of the picture
for (@epsfile) {
X   ($llx, $lly, $urx, $ury) =
X      /^%%BoundingBox:\s*(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)\s+(-?[0-9\.]+)/;
X   last if defined($llx);
}
die "No %%BoundingBox found in file" unless defined($llx);
X
# Calculate 
$preview_width = int(($opt_w || 79) / 2) * 8;
$width  = $urx - $llx + 1;
$height = $ury - $lly + 1;
$scalefactor = $preview_width / $width;
$width  = int($width * $scalefactor);
$height = int($height * $scalefactor);
X
# Produce GhostScript program
$gsfile = "/tmp/gs$$.tmp";
open(GSFILE, ">$gsfile") || die "Can't write to file $gsfile";
print GSFILE <<"---EndGhostScriptProgram---";
%!GhostScript
/BITIMAGE_WIDTH $width def
/BITIMAGE_HEIGHT $height def
/BITIMAGE_FILE (%stdout) def
X
%---- Setup a memory device --------
[1 0 0 -1 0 BITIMAGE_HEIGHT]
BITIMAGE_WIDTH BITIMAGE_HEIGHT
%
% [1 1 1 rgbcolor 0 0 0 rgbcolor] <-- 2.3 arguments
% <ff 00>                         <-- 2.4 arguments from ghost@aladdin.com
%
<ff 00> 
makeimagedevice
setdevice
X
%--- Some transformations
/showpage {} def
$scalefactor dup scale
$llx neg $lly neg translate
X
%--- The old EPS file
@epsfile
X
%---- Print bitmap on a file -------
/line BITIMAGE_WIDTH 8 idiv 1 add string def
/output BITIMAGE_FILE (w) file def
output (---------) writestring
output 10 write
0  1  BITIMAGE_HEIGHT 1 sub { %for
X   output (%) writestring
X   currentdevice exch
X   line copyscanlines
X   output exch writehexstring
X   output 10 write
} for
output flushfile
quit
---EndGhostScriptProgram---
X
close GSFILE;
close STDIN;    # so that GhostScript can't read it.
X
@gsoutput = `gs -q -DNODISPLAY $gsfile`;   # run GhostScript
die "Can't run GhostScript" unless $? == 0;
unlink $gsfile;
X
@preview = grep(/^-----/ .. 1, @gsoutput);   # remove GhostScript garbage
shift(preview);
if ($#preview < 0) {
X  print STDERR "GhostScript gives no output for the specified file\n";
X  print STDERR @gsoutput;
X  exit 1;
}
X
print shift(epsfile);
$_ = shift(epsfile);
while (/^%%/) {
X  if (/^%%BoundingBox:/) {
X    print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
X    $boundingbox = 1;
X  } elsif (/^%%EndComments/) {
X    last;
X  } else {
X    print;
X  }
X  $_ = shift(epsfile);
}
print "%%BoundingBox: $llx $lly $urx $ury\n" if !defined($boundingbox);
print "%%EndComments
%%BeginPreview: $width $height 1 $height\n";
print @preview;
print "%%EndPreview\n";
X
print $_ unless /^%%/;
print grep(!(/^%%BeginPreview:/ .. /^%%EndPreview/) && !/^%%BoundingBox:/,
X          @epsfile);
X
X
X
X
X
###########################################################################
X       # These next few lines are legal in both Perl and nroff.
X
.00;                    # finish .ig
X 
'di                     \" finish diversion--previous line must be blank
.nr nl 0-1              \" fake up transition to first page again
.nr % 0                 \" start at page 1
';<<'.ex'; #__END__ #### From here on it's a standard manual page #########
.TH EPS2EPSI 1 "May 1991"
.SH NAME
eps2epsi \- Filter for inclusion of a preview in an EPS file
.SH SYNOPSIS
.B eps2epsi
[
.B \-w
.I preview_width
] [
.I filename
]
.SH DESCRIPTION
.B Eps2epsi
puts a preview section in a PostScript file (preferably EPSF).
The preview produced
is in the encapsulated PostScript interchange format (EPSI)
suitable for import by FrameMaker and other document composing
systems.
.B Eps2epsi
reads the file specified (or standard input) and sends the new file
with the preview included to standard output.
.PP
.B Esp2epsi
uses
.B GhostScript
to render the preview bitmap, which means that
.B GhostScript
must be installed at your system before you can use
.B eps2epsi.
.SH OPTIONS
.TP 5
.BI \-w " n"
Set the width (in characters) of the preview section. This also specifies the
resolution of the preview as
.I n
times 4 horizontally.
.SH SEE ALSO
.BR perl (1),
.BR gs(1)
.SH AUTHOR
Gisle Aas, Norwegian Computing Center (NR), Oslo, Norway.
<Gisle.Aas@nr.no>
.ex
SHAR_EOF
chmod 0755 eps2epsi ||
echo 'restore of eps2epsi failed'
Wc_c="`wc -c < 'eps2epsi'`"
test 5005 -eq "$Wc_c" ||
        echo 'eps2epsi: original size 5005, current size' "$Wc_c"
fi
exit 0
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads