ps2eps/ 0000755 0005702 0001750 00000000000 11766326360 011307 5 ustar bless bless ps2eps/doc/ 0000755 0005702 0001750 00000000000 11766326360 012054 5 ustar bless bless ps2eps/doc/src/ 0000755 0005702 0001750 00000000000 11766326360 012643 5 ustar bless bless ps2eps/doc/src/ps2eps.sgml 0000644 0005702 0001750 00000063420 11766326360 014750 0 ustar bless bless
Roland">
Bless">
May 7, 2010">
1">
roland at bless.de">
ps2eps">
ps2eps">
Debian">
GNU">
GPL">
]>
&dhemail;
&dhfirstname;
&dhsurname;
2009&dhusername;
&dhdate;
&dhucpackage;
&dhsection;
&dhpackage;
convert PostScript to EPS (Encapsulated PostScript) files
&ps2eps;
psfile1psfile2...DESCRIPTIONThis manual page documents &ps2eps; version &ps2epsver;.&ps2eps; is a tool (written in Perl) to produce
Encapsulated PostScript Files (EPS/EPSF) from usual one-paged Postscript
documents. It calculates correct Bounding Boxes for those EPS files and
filters some special postscript command sequences that can produce
erroneous results on printers. EPS files are often needed for including
(scalable) graphics of high quality into TeX/LaTeX (or even Word) documents.
Without any argument, ps2eps reads from standard input
and writes to standard output.
If filenames are given as arguments they are processed
one by one and output files are written to filenames
with extension .eps. If input filenames have the
extension .ps or .prn, this extension is replaced with .eps.
In all other cases .eps is appended to the input filename.
Please note that PostScript files for input should contain
only one single page (you can possibly use the psselect from the
psutils package to extract a single page from a document that
contains multiple pages).
If BoundingBox in output seems to be wrong, please try options or
. See also section TROUBLESHOOTING.
OPTIONS
&ps2eps; follows the usual &gnu; command line syntax,
with long options starting with two dashes (`-'). A summary of
options is included below.
,
Show summary of options.,
Show version of program.,
Force overwriting existing files. &ps2eps;
will not overwrite files by default to avoid deleting original EPS
files accidently.
,
quiet operation (no output while processing files, except errors).,
do not insert any postscript code. Normally a few postscript
instructions are added around the original postscript code by
&ps2eps; which can be turned off by this option.
,
do not filter %%Orientation: header comment.,
do not try to fix postscript code by filtering some instructions.,
remove preview image (smaller file, but no preview anymore).,
fix postscript code unconditionally. Otherwise, filtering is
usually triggered by detection of certain drivers only.
,
preserve document structure comments.,
insert postscript code for clipping. Unless
is specified, the HiResBoundingBox
(enlarged by 0.1 points) is used for clipping. ,
use black/white bitmap as base for calculation (default: off)., =pagedimwhere pagedim is a pre-defined standard page size
(e.g., a4,a0,b0,letter,...) or explicitly specified in a
format pagedim:=XxY[cm|in],
where X and Y are numbers (floating points are accepted) followed by
units centimeter (cm) or inch (in), (default: cm).
Use to list pre-defined pagesizes.
See also environment variable PS2EPS_SIZE.,
specify an x,y offset (may be negative) in postscript points
(1/72 dpi) for drawing. This option may be required
if your drawing has negative coordinates which usually lets &gs;
cut the negative part of your picture, because it starts to render
at positive coordinates. The resulting output will
also be shifted.
,
specify a resolution in dpi (dots per inch) for drawing under
ghostscript. Default
resolution is 144 dpi which is the double of the typical 72 dpi.
This option may help if there is a hardware dependent resolution
encoded in the postscript, e.g., 600dpi. Example:
ps2eps -l -r 600 test.ps,
This option rotates the resulting EPS output.
The parameter direction determines the direction of
rotation: + means +90 degrees (clockwise),- means -90 degrees
(counter-clockwise), and ^ means 180 degrees (up-side down).
,
expand the original tight bounding box by one point in each
direction.,
do not use existing bounding box as page size for
rendering.,
do not use %%EOF as hint for end of file. Otherwise, &ps2eps; assumes
that postscript code ends after the last %%EOF comment, because
some drivers add trailing binary garbage code which gets deleted
by &ps2eps; by default.
,
use internal bbox device of &gs; instead of the external C
program bbox. The internal bbox device of &gs;
generates different values (sometimes even incorrect),
so using the provided bbox should be more robust.
See also environment variable PS2EPS_GSBBOX.
,
do not generate a %%HiResBoundingBox comment for output.
,
increase the accuracy by turning subsample antialiasing on (may be slower)
,
show licensing information.,
show &gs; call. This may be helpful for solving problems that
occur during a &gs; call.,
show warnings about sanity of generated EPS file. Certain
postscript commands should not be contained in an EPS file.
With this option set &ps2eps; will issue a warning if it
detects at least one of them.
TROUBLESHOOTINGBased on the given postscript source code (in most cases generated by
some postscript printer driver) there are many potential obstacles or
problems that may occur when trying to create proper EPS files. Please
read this section carefully to be aware of common pitfalls.Incomplete/Clipped Imagesor how to determine the right size for &gs;.If you have documents that are larger than your
&gs; default (usually A4 or US letter), you have to
specify the page dimensions explicitly using the
option. Otherwise your EPS
might be cut off during rasterizing by &gs; resulting
in a wrongly calculated bounding box. You can pass
all pre-defined page sizes to that &gs; understands. These are
currently: 11x17, ledger, legal, letter, lettersmall, archA, archB, archC, archD, archE
a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, isob0, isob1, isob2, isob3, isob4, isob5, isob6,
b0, b1, b2, b3, b4, b5, c0, c1, c2, c3, c4, c5, c6, jisb0, jisb1,
jisb2, jisb3, jisb4, jisb5, jisb6, flsa, flse, halfletter.
Unfortunately, all sizes are currently only available in portrait
orientation (not landscape).
By default, &ps2eps; uses an already given %%BoundingBox
from the source file, which often corresponds to the size of
the physical page format for which the document was
printed. However, you should be aware that this already
specified bounding box may be not correct, thus resulting in a
wrongly cropped (or even no usable) .eps-file.
&ps2eps; can only do as good as &gs; does in rendering the original
postscript file (though &ps2eps; even works with negative and
fractional values are contained in the original bounding box by using
automatic translation). Therefore, if the given bounding box is to
small or incorrect anyway, you can ignore the existing bounding box with the
option, which will cause &gs; to use its internal
default size (or use ). However, if the
BoundingBox has negative coordinates, which is not allowed by
the specification, &ps2eps; will shift the output to positive values.
Hint: to avoid rotating the picture
if you have the original drawing in landscape format, you may
use the Encapsulated Postscript option in the printer driver
which should generate an EPS file (but with a bounding box of
the sheet size!). But some Windows printer drivers are drawing
the image with an offset from the bottom of the portrait page,
so that a part of it is drawn outside the landscape oriented
page. In this case, you'll have to specify a square size of
the page using the maximum length, e.g., 29.7cm x 29.7cm for
an A4 page.Clippingor why gets some of my text deleted above the included .eps file?
Some postscript drivers draw a white rectangle from the top left
corner of the page to the right lower corner of the object. This may
erase some or even all text above your imported/included EPS file,
which is very annoying. In order to prevent this, most programs have a
clipping option for imported .eps files (within LaTeX you can use
\includegraphics*{}) for this purpose. If this is unfortunately not
the case, you can use the option of &ps2eps; which will (hopefully)
do it for you. Unfortunately, PScript.dll 5.2 (Windows XP) introduced
new very badly behaving Postscript code (initclip) which will even
override the outer clipping! Thus, a new filter had to be installed
in &ps2eps; which will fix it.
However, because most programs clip directly on the bounding box,
you still may loose some pixels of your image, because the bounding
box is described in the coarse resolution of postscript points,
i.e. 72 dpi. In order to prevent this, you can use the
option or option (for the latter, clipping by the importing program
should be disabled then) to allow for a 1 point larger bounding box.
clips around a 1 point enlarged bounding box and enlarges the
bounding box values by 1 point (you can also combine both options).
Included Filters
Some postscript sequences, e.g., for using specific printer
features (featurebegin ...), are not working well within an .eps
file, so &ps2eps; tries to filter them out. But please note that
filters for postscript code may not work properly for your printer
driver (&ps2eps; was mainly tested with HP and Adobe printer
drivers, although it may work for all printers using the
PScript.dll). In this case you can try to turn of filtering by
using option , or try to find the bad sequence in the postscript
code and adapt the filter rule in the &ps2eps; script (variables
$linefilter, $rangefilter_begin, $rangefilter_end; linefilter is
an expression for filtering single lines, rangefilter_... are
expressions that filter all lines between a pattern matching
$rangefilter_begin and $rangefilter_end; drop me an e-mail with
your modifications). However, things may change as the printer
drivers (e.g., PScript.dll) or postscript language evolve.
Some applications or drivers generate postscript code with leading
or trailing binary code, which often confuses older postscript
interpreters. &ps2eps; tries to remove such code, but it may
sometimes make a wrong guess about start and end of the real
postscript code (drop me an e-mail with a zipped postscript
source, see section BUGS).
Comment lines or even blank lines are removed
(which is the default to make .eps files smaller), which may corrupt your
output. Please check the next section how to fix this.
&ps2eps; removes blank lines and also <CR> (carriage ceturn
\r) at the end of lines. However, nicely formatted postscript code
gives a hint by using %%BeginBinary%%EndBinary comments. When
&ps2eps; detects these comments it will refrain from any filtering
action within the marked binary sections.
&ps2eps; filters also %%Orientation: comments by
default (you can use option to turn off filtering),
because &gs; may automagically rotate images when generating PDF
images, which is not desired in most cases. Hint: you can turn off that
feature in &gs; unconditionally by specifying -dAutoRotatePages=/None.
Corrupted Output
Some postscript code may get corrupted when comment lines or even blank
lines are removed (which is the default to make .eps files smaller),
because those files may contain encoded images
which also have a % as first character in a line or use a special
comment as end of image delimiter. If this is the case, use the
option to prevent filtering comments.
Color and memory&ps2eps; supports colored postscript, consequently
letting &gs; consume more resources for drawing its bitmap
(roughly 6MBytes for an A4 page). bbox is reading
the bitmap line by line so it consumes only minimal memory. If you experience problems
with memory consumption of &gs;, you may use the option
for using a monochrome image. But this will probably result in wrongly
determined bounding boxes with colored
images, because &gs; has to do black/white dithering and may thus suppress
objects drawn in light colors.Another option in case of memory problems and too long run times
is to use the much more memory efficient internal &gs bbox by using the
option.
ENVIRONMENT VARIABLESPlease note that a command line option always takes precedence over
the related environment variable.The environment variable PS2EPS_SIZE can be used
to specify a default page size and take any argument that
accepts. Examples: export PS2EPS_SIZE=a0 (bash-like syntax)
or setenv PS2EPS_SIZE letter (csh syntax). If the environment variable PS2EPS_GSBBOX is set
the internal bbox device of &gs; will be used instead of the external
command bbox. Examples: export PS2EPS_GSBBOX=true (bash-like syntax)
or setenv PS2EPS_GSBBOX 1 (csh syntax).EXAMPLESThe usual call is simply:
ps2eps -l fileA relatively failsafe call would be (if your postscript is smaller
than iso b0 [100cm x 141.4cm] and you have a fast computer with enough memory):
ps2eps -l -B -s b0 -c -n fileIf output is not correct try:
ps2eps -l -B -s b0 -F fileAUTHOR&ps2eps; was written by &dhusername;. WHY?
Other programs like ps2epsi do not calculate the
bounding box always correctly (because the values are put on the
postscript stack which may get corrupted by bad postscript code) or
rounded it off so that clipping the EPS cut off some part of the
image. &ps2eps; uses a double precision resolution
of 144 dpi and appropriate rounding to get a proper bounding
box. The internal bbox device of &gs; generates different values
(sometimes even incorrect), so using the provided bbox
should be more robust.
However, because normal clipping has only a resolution of 1/72dpi
(postscript point), the clipping process may still erase parts of your
EPS image. In this case please use the option to add
an additional point of white space around the tight bounding box.
ACKNOWLEDGMENTSSome people contributed code or suggestions to improve &ps2eps;. Here
are at least some names (sorry if I forgot your name):
Christophe Druet, Hans Ecke, Berend Hasselman, Erik Joergensen, Koji Nakamaru, Hans Fredrik Nordhaug, Michael Sharpe.
Special thanks goes to Michael Sharpe from UCSD who suggested a lot of useful features for ps2eps and
who fixed bbox to become more precise and robust.
An earlier version of this manual page was originally written by
Rafael Laboissiere rafael at debian.org for
the &debian; system. Thank you Rafael!
Permission is granted to copy, distribute and/or modify this document under
the terms of the &gnu; Free Documentation
License, Version 1.1 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover
Texts and no Back-Cover Texts.BUGS
If you experience problems, please check carefully all hints in the section
TROUBLESHOOTING
first. Otherwise, check for an updated
version at
or send a gzipped file of
relevant postscript source code with your error description
and &ps2eps; version number to &dhemail; (please allow some time
to reply).
SEE ALSObbox (1), gs (1), ps2epsi (1)
ps2eps/doc/src/bbox.sgml 0000644 0005702 0001750 00000011576 11766326360 014473 0 ustar bless bless
Roland">
Bless">
January 22, 2004">
1">
roland@bless.de">
bbox">
bbox">
Debian">
GNU">
GPL">
]>
&dhemail;
&dhfirstname;
&dhsurname;
2003&dhusername;
&dhdate;
&dhucpackage;
&dhsection;
&dhpackage;
prints out the bounding box of a rawppm or rawpbm image
&bbox;
rawpbmfileDESCRIPTION&bbox; reads a rawppm or rawpbm file
and prints out the bounding box of the image (as postscript comment and
in postscript points, i.e. 1/72dpi) as well as the high resolution
bounding box. Input is read from standard input if no filename is
specified.
Example output:
%%BoundingBox: 12 253 829 837
%%HiResBoundingBox: 12.500000 253.000000 828.500000 837.00000
&bbox; has only very limited memory requirements
as it reads the input line by line and thus needs to store only one picture
line in memory.
OPTIONSShow summary of options.Show version of program.resolution of picture in dpiloose bounding box (integer bounding box is expanded by 1
point, hires bounding box is expanded by 0.5 points)SEE ALSOps2eps (1)AUTHOR&bbox; was written by &dhusername;. ACKNOWLEDGMENTSSpecial thanks goes to Michael Sharpe from UCSD who suggested a lot of improvements for
bbox to become more precise and robust, especially for small drawings.An earlier version of this manual page was originally written by
Rafael Laboissiere rafael@debian.org for
the &debian; system. Thank you Rafael! Permission is
granted to copy, distribute and/or modify this document under
the terms of the &gnu; Free Documentation
License, Version 1.1 or any later version published by the Free
Software Foundation; with no Invariant Sections, no Front-Cover
Texts and no Back-Cover Texts.BUGS
Though the code is quite small and the probability for bugs
is now small, there may be some left somewhere between the lines.
In case you find one, please send a short description with
&bbox; version number to &dhemail; (please allow some time
to reply).
ps2eps/doc/src/Makefile 0000644 0005702 0001750 00000002617 11766326360 014311 0 ustar bless bless # -----------------------------------*- mode: Makefile; -*--
# Makefile for ps2eps documentation
# ----------------------------------------------------------
# $Id: Makefile 139 2012-06-14 08:40:32Z bless $
# $Source: /home/bless/src/ps2eps/cvs-repository/ps2eps/doc/Makefile,v $
# ----------------------------------------------------------
# `$@' The file name of the target of the rule.
# `$%' The target member name, when the target is an archive member.
# `$<' The name of the first prerequisite.
# `$?' The names of all the prerequisites that are newer than the target, with spaces between them.
# `$^' The names of all the prerequisites, with spaces between them.
.PHONY: manpages pdf html
DOCBOOK_FLAGS=-c /usr/share/sgml/docbook/dtd/catalog
DOCBOOK_TO_MAN=docbook2man
DOCBOOK_TO_HTML=docbook2html
DOCBOOK_TO_PDF=docbook2pdf #needs pdfjadetex
MANPAGES=ps2eps.1 bbox.1
PDF=ps2eps.pdf bbox.pdf
HTML=ps2eps.html bbox.html
all: manpages pdf html
manpages: $(MANPAGES)
pdf: $(PDF)
html: $(HTML)
%.pdf : %.1
groff -m mandoc $< | ps2pdf - $@ # when having .1
# $(DOCBOOK_TO_PDF) $(DOCBOOK_FLAGS) $<
%.html : %.sgml
# groff -m mandoc -Thtml $< >$@ # when having .1
$(DOCBOOK_TO_HTML) $(DOCBOOK_FLAGS) $<
mv index.html $@
%.1 : %.sgml
$(RM) $@
$(DOCBOOK_TO_MAN) $(DOCBOOK_FLAGS) $<
clean:
rm $(MANPAGES) $(PDF) $(HTML) manpage.refs manpage.links
# --------------------------------------------------------
ps2eps/Latest_is_1.68 0000644 0005702 0001750 00000000000 11766326360 013623 0 ustar bless bless ps2eps/src/ 0000755 0005702 0001750 00000000000 11766326360 012076 5 ustar bless bless ps2eps/src/C/ 0000755 0005702 0001750 00000000000 11766326360 012260 5 ustar bless bless ps2eps/src/C/bbox.c 0000644 0005702 0001750 00000036404 11766326360 013365 0 ustar bless bless /********************************************************************/
/** bbox -- calculates Bounding Box of a pbmraw/ppmraw-picture **/
/** Created: Nov. 1997, revised Feb. 1998, Dec. 1999, June 2009 **/
/** Author: Roland Bless **/
/** Copyright (C) 1998-2009 Roland Bless **/
/** To compile simply use: **/
/** "cc bbox.c -o bbox" or "make bbox" **/
/********************************************************************/
/*
* $Id: bbox.c 139 2012-06-14 08:40:32Z bless $
*/
/**
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**/
/* Quoting EPSF Spec:
http://partners.adobe.com/public/developer/en/ps/5002.EPSF_Spec.pdf
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: llx lly urx ury
The four arguments of the bounding box comment correspond to the
lower-left (llx, lly) and upper-right (urx, ury) corners of the
bounding box. They are expressed in the default PostScript
coordinate system. For an EPS file, the bounding box is the smallest
rectangle that encloses all the marks painted on the single page of
the EPS file.
*/
#include
#include
#include
#if defined(_WIN32) && !defined(__CYGWIN__)
#include /* needed for _setmode() */
#include
#endif
/**********************
* global variables *
**********************/
const char *const version= "$Rev: 139 $";
const char *const prgname= "bbox";
const double round_precision= 1e-6;
unsigned char bitval[8]=
{
1 << 7,
1 << 6,
1 << 5,
1 << 4,
1 << 3,
1 << 2,
1 << 1,
1
};
unsigned int minus_one(const unsigned x)
{
return (x == 0) ? x : x-1;
}
unsigned int plus_one(const unsigned x)
{
return (x == (unsigned int) ~0U) ? x : x+1;
}
/***************************** readppm_and_calcbb ***********************
* input: name, resolution, tight *
* output: - (stdout) *
* *
* Reads a RAWPPM or RAWPBM picture file (name or STDIN) and *
* calculates its Bounding Box on-the-fly (line-by-line). *
* *
* Parameters: *
* name: name of the PBMRAW file or NULL (input from stdin) *
* resolution: Pixel per Inch (DPI) *
* tight: boolean value, if false 1 Postscript Point is added to *
each Bounding Box parameter, otherwise the BB is tight *
* The Bounding Box is given in Postscript Points (72 dots/inch) *
* and printed to stdout *
************************************************************************/
/* calculate the bounding box in postscript points, given a resolution in dpi */
void readppm_and_calcbb(const char *name,
const unsigned int resolution,
const unsigned char tight)
{
FILE *inputfile;
char inputline[1024];
unsigned char magic_found= 0;
int x,y,byte_x,i;
const double pt_dpi_dbl= 72.0;
unsigned int x_min, x_max, y_min, y_max;
unsigned int llx, lly, urx, ury; /* bounding box */
double hllx, hlly, hurx, hury; /* hires bounding box */
unsigned char *image_row, /* ImageRow */
*tmpcolumnbytep;
unsigned int width,height; /* Image Size */
unsigned int byte_width;
unsigned char stepsize;
unsigned char colormax= 0; /* max color value */
unsigned int ui_colormax= 0; /* max color value */
if ( name == NULL )
{
inputfile = stdin;
name = "- STDIN -";
}
else
{
inputfile = fopen(name,"r");
if ( inputfile == NULL )
{
fprintf(stderr,"%s: ERROR -- could not open file %s\n",
prgname, name);
return;
}
}
/** check for magic number **/
do
{
fgets(inputline, 1024, inputfile);
#ifdef DEBUG
fprintf(stderr,"read:[%s]\n",inputline);
#endif
if ( strcmp(inputline,"P4\n") == 0 )
{
stepsize= 1;
magic_found= 4;
}
else
if ( strcmp(inputline,"P6\n") == 0 )
{
stepsize= 3;
magic_found= 6;
}
}
while ( !feof(inputfile) && !magic_found );
if ( !magic_found )
{
fprintf(stderr,"%s: ERROR -- %s is not in ppmraw or pbmraw format\n",
prgname, name);
return;
}
/** skip comments **/
do
{
fgets(inputline, 1024, inputfile);
#ifdef DEBUG
fprintf(stderr,"read:[%s]\n",inputline);
#endif
if (*inputline == '#')
continue;
else
break;
}
while ( !feof(inputfile) );
/** read picture size: width, height **/
sscanf(inputline,"%u %u",&width,&height);
if ( magic_found == 6 ) /* PPM file has maximum color-component value */
{
fgets(inputline, 1024, inputfile);
sscanf(inputline,"%u",&ui_colormax);
colormax = (unsigned char) ui_colormax; /* this is safer */
}
#ifdef DEBUG
fprintf(stderr,"\nreading picture: %s size X: %u Y: %u\n",name,width,height);
#endif
x_min= width>0 ? width-1 : 0;
x_max= 0;
y_min= height>0 ? height-1 : 0;
y_max= 0;
if ( magic_found == 4 ) /* PBMRAW = Bitmap */
{ /** read raw pbmfile **/
byte_width= width / 8;
if (width % 8 != 0)
byte_width++;
}
else /** assume ppm raw **/
{
byte_width= width * 3; /* we have RGB, i.e. three bytes for each pixel */
}
/*
* Now read a raster of Width * Height pixels, proceeding through the image in normal English reading order,
* i.e., starting from top left then moving right
*/
/* we allocate only one line */
image_row= malloc(byte_width);
if ( image_row )
{
#if defined(_WIN32) && !defined(__CYGWIN__) /* this is really braindead stuff for MSVC */
i= _setmode( _fileno(stdin), _O_BINARY);
if (i == -1)
fprintf(stderr,"%s: ERROR - Cannot set binary mode for STDIN\n");
#endif
for (y= 0; y= width ) break;
#ifdef DEBUG
printf("(row %04d, %04d): \n",y,x);
#endif
}
} /* end for */
} /* end if magic_found 4 */
else
{ /* assume PPM */
x= byte_x/3; /* we have 3 bytes per pixel */
#ifdef DEBUG
printf("(row %04d, col %04d) byte %04d: \n",y,x,byte_x,colormax);
#endif
}
/* update bounding box */
if ( x < x_min ) x_min= x;
if ( x > x_max ) x_max= x;
if ( y < y_min ) y_min= y;
if ( y > y_max ) y_max= y;
#ifdef DEBUG
printf("ymin,height:(%04d,%04d) xmin,width:(%04d,%04d)\n",
y_min,y_max,x_min,x_max);
#endif
break;
} /* if there are pixels not white */
} /* end for byte_x */
if ( byte_x != byte_width )
{ /* there was a pixel with no background color */
tmpcolumnbytep= image_row+byte_width-1;
/* inspect this line from the right */
for (byte_x= byte_width-1;
byte_x >= 0;
byte_x--,tmpcolumnbytep--)
{
if ( *tmpcolumnbytep != colormax ) /* there are pixels not white */
{
if ( magic_found == 4 )
{
for (i= 0; i<8 ; i++)
{
if ( *tmpcolumnbytep & bitval[i] )
{
x= byte_x*8+i;
if (x >= width) break;
#ifdef DEBUG
printf("(%04d,%04d): \n",y,x);
#endif
}
} /* end for */
} /* end if magic_found 4 */
else
{ /* assume PPM */
x= byte_x/3; /* we have 3 bytes per pixel */
}
/* update bounding box */
if ( x < x_min ) x_min= x;
if ( x > x_max ) x_max= x;
if ( y < y_min ) y_min= y;
if ( y > y_max ) y_max= y;
#ifdef DEBUG
printf("ymin,height:(%04d,%04d) xmin,width:(%04d,%04d)\n",
y_min,y_max,x_min,x_max);
#endif
break;
} /* if there are pixels not white */
} /* end for byte_x */
} /* if line contained not only background color */
} /* end for y */
#ifdef DEBUG_BOX
fprintf(stderr,"(%04d,%04d), (%04d,%04d)\n", x_min,height-y_max,x_max,height-y_min);
#endif
/* distance from the left edge to the leftmost point */
hllx= (x_min*pt_dpi_dbl)/resolution;
/* distance from the bottom edge to the bottommost point */
hlly= ((minus_one(height)-y_max)*pt_dpi_dbl)/resolution;
/* distance from the left edge to the righmost point */
hurx= (plus_one(x_max)*pt_dpi_dbl)/resolution;
/* distance from the bottom edge to the uppermost point */
hury= ((height-y_min)*pt_dpi_dbl)/resolution;
if ( !tight )
{
/* distance from the left edge to the leftmost point */
llx= minus_one((unsigned int) ((unsigned long) x_min*72UL)/resolution);
/* distance from the bottom edge to the bottommost point */
lly= minus_one((unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution);
/* distance from the left edge to the righmost point */
urx= plus_one((unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution);
/* distance from the bottom edge to the uppermost point */
ury= plus_one((unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution);
/* also loosen hires BBox by default precision */
if (hllx-round_precision >= 0.0)
hllx-= round_precision;
if (hlly-round_precision >= 0.0)
hlly-= round_precision;
hurx+= round_precision;
hury+= round_precision;
}
else /* tight bounding box */
{
/* distance from the left edge to the leftmost point */
llx= (unsigned int) ((unsigned long) x_min*72UL)/resolution;
/* distance from the bottom edge to the bottommost point */
lly= (unsigned int) ((unsigned long) (minus_one(height)-y_max)*72UL)/resolution;
/* distance from the left edge to the righmost point */
urx= (unsigned int) ((unsigned long) plus_one(x_max)*72UL)/resolution;
/* round up if we got a remainder */
if ( (((unsigned long) plus_one(x_max)*72UL) % resolution) != 0 )
urx= plus_one(urx);
/* distance from the bottom edge to the uppermost point */
ury= (unsigned int) ((unsigned long) (height-y_min)*72UL)/resolution;
if ( (((unsigned long) (height-y_min)*72UL) % resolution) != 0 )
ury= plus_one(ury);
}
/* skip the rest of the file if any data is still present */
while ( !feof(inputfile) )
{
fgets(inputline, 1024, inputfile);
}
/* give out Bounding Box */
printf("%%%%BoundingBox: %d %d %d %d\n", llx, lly, urx, ury);
printf("%%%%HiResBoundingBox: %f %f %f %f\n", hllx, hlly, hurx, hury);
}
else
fprintf(stderr,"%s: ERROR -- not enough memory to read in one row of the picture\n",prgname);
fclose(inputfile);
free(image_row);
}
int
main(int argc, char **argv)
{
int i;
char *filename= NULL;
unsigned int resolution= 72; /* use 72 dpi as default resolution */
unsigned char tight= 1;
for (i= 1; i