bmeps + dvips add-on
It depends on your installation
(modified or unmodified dvips)
how to use bitmap graphics support.
Preparing LaTeX sources
In the header section of your TeX source write
\DeclareGraphicsRule{.png}{eps}{.bb}{}
\DeclareGraphicsRule{.jpg}{eps}{.bb}{}
\DeclareGraphicsRule{.jpeg}{eps}{.bb}{}
This advises LaTeX to treat PNG/JPEG graphics as EPS. Bounding box
information is retrieved from files having the suffix .bb.
The bmeps program can be used to create .bb-files, i.e.
bmeps -b file1.png file1.bb
creates the bounding box for graphics file file1.png and stores
the bounding box data into file1.bb.
You can use shell scripts like the following to create bounding box files
for all PNG files in a given directory:
#! /bin/csh
foreach png (*.png)
set j = $png:r
set bb = ${j}.bb
bmeps -b ${png} ${bb}
end
New dvips command line options
Options can be given on command line via
-I <conversion-options>
where conversion-options is a string containing the following characters:
- PS level
Use 1, 2 or 3 to select the PS level 1, 2 or 3.
- Color or grayscale printer
Use c if you have a color printer or g for conversion to
grayscale. Color printing requires PS level 2 or higher.
- Encoding algorithms
Use f to get flate encoding (requires PS level 3), r
to get run-length-encoding (requires PS level 2), 8 to
get ASCII85-encoding instead ASCII-Hex-encoding (requires PS level 2) or
h to use ASCII-Hex-encoding.
Flate encoding, run-length-encoding and one from ASCII85- or ASCII-Hex-encoding
can be used combined.
- DSC comments
Use x to ask for DSC comments.
- Draft mode
Use d to turn draft mode on. Bitmap images are not printed, only
the place is marked.
- Alpha channel use
To convert an alpha channel into an EPS level 3 masked
bitmap use the a option. By use of o you can
specify the alpha channel expresses opacity (default), t
specifies transparency. Normally only pixels with 0 opacity
are masked, all others are drawn. The alternative behaviour is
to draw only pixels with full opacity and mask all others, this
can be reached by option l.
Option m advises the program to mix foreground and background
color for a pixel depending on its alpha value.
You can specify a background color like 128,255,128 for light
green. The color specification must appar after the a option.
Normally this background color is used only if there is no
background color chunk in the file. Option s gives this
command line background color higher priority than the background
color from chunk.
If no command line options are given dvips consults the environment variable
EPSOUTPUT.
Option examples
- -I 2g8r
is suitable for most Level 2 printers (or at least for my printer).
- -I 3c8rf
keeps colors and provides a good compression rate. Usefull for large documents
to be post-processed by ps2pdf.
- -I d
prints a draft. Images are not really inserted, placeholders are
used instead. This is a fast way to get a preview.
- -I 3c8rfa
converts the alpha channel to an image mask. The alpha channel value
expresses opacity. All pixel with opacity > 0 are drawn.
Pixels with zero opacity are masked out.
- -I 3c8rfal
converts the alpha channel to an image mask. The alpha channel value
expresses opacity. All pixel with full opacity are drawn, all
other pixels are masked out.
- -I 3c8rfat
converts the alpha channel to an image mask. The alpha channel value
expresses transparency. Pixel with full transparency (0xFF) are masked
out, all other pixels are drawn.
- -I 3c8rfatl
converts the alpha channel to an image mask. The alpha channel value
expresses transparency. Pixel with transparency > 0
are msked out.
- -I 3c8rfm128,255,128
mixes the picture against a background (R,G,B)=(128,255,128).
If the image file contains a background color chunk the background
color is obtained from that chunk.
- -I 3c8rfms128,255,128
mixes the picture against a background (R,G,B)=(128,255,128).
Background color chunks in the image file are ignored.
- -I 3c8rfams128,255,128
The combination of mixing and masking.
Option defaults
Be default dvips is configured for PS level 2,
grayscale printing and uses run-length-encoding in combination
whit ASCII-85-encoding.
If you did not install the modified dvips you can add
the following line in your LaTeX source's preamble:
\DeclareGraphicsRule{.png}{eps}{.bb}{`bmeps -p2 -g -er8 #1}
\DeclareGraphicsRule{.jpg}{eps}{.bb}{`bmeps -p2 -g -er8 #1}
\DeclareGraphicsRule{.jpeg}{eps}{.bb}{`bmeps -p2 -g -er8 #1}
This advises the dvixxx drivers to run
bmeps -p2 -g -er8 <inputfile>
for all PNG/JPEG pictures to create EPS output.
- -p2 advises bmeps to issue PS level 2.
PS level 1 can be adjusted by -p1, PS level 3 by -p3.
- -g converts colored pictures to grayscale.
-c instead would keep the colors, this requires
PS level 2 or higher.
- -er8 sets up the encoding mechanisms run-length (r)
and ASCII-85 instead of ASCII-Hex (8). Both encoding algorithms
are available only for PS level 2 and higher.
For PS level 3 flate encoding (f) is available.
- -s must be specified if DSC comments are needed.
Without this option bmeps does not issue DSC comments
(except BoundingBox).
- -d can be used for draft printing, no picture conversion
is done, only placeholders are printed.
- -a<alpha-channel-options> can be specified
to use the alpha channel support. There are options
o to tell the program the alpha channel contains opacity
or t if it contains transparency.
By default only pixels with 0 opacity are masked. Option
l toggles this, only pixels with full opacity are drawn.
Option m advises the program to mix foreground and background
color for a pixel depending on its alpha value.
You can specify a background color like 128,255,128 for light
green. Normally this background color is used only if there is no
background color chunk in the file. Option s gives this
command line background color higher priority than the background
color from chunk.
Alpha channel support is available only if the bmeps library
was configured for alpha channel support.
Note: If you need different PS output from the same
LaTeX source (i.e. colored and flated output for conversion to PDF
and grayscaled run-length and ASCII85 output for a printer) you should
not specifiy options to bmeps. In this case you should provide options
via the EPSOUTPUT environment variable
as shown in the next section
when running dvips.
The graphics rule in this case looks like:
\DeclareGraphicsRule{.png}{eps}{.bb}{`bmeps #1}
Configuring defaults
If you do not want to specifiy EPS output configuration on
command line each time you use bmeps or the
modified dvips you can set defaults in the
EPSOUTPUT environment variable.
The contents of this variable is the same as the argument
to the -I option for the modified dvips
as explained above.
Examples:
Use
setenv EPSOUTPUT 2gr8
in your .cshrc file if your login shell is a C-Shell.
Use
EPSOUTPUT=2gr8
export EPSOUTPUT
in your .profile file if your login shell is a Bourne-shell.
On W*-systems use
set EPSOUTPUT=2gr8
in your autoexec.bat file.
Examples
The EXAMPLES subdirectory contains Postscript files
derived from the same example.tex
file using different options.
The image stefan_255_rgba.png was obtained from the
"Miscallenous Transparent PNGs Using Image Tags" page
on the libpng home page.
Image | | LaTeX source |
Some levels of gray in this image are produced by specifying
a black foreground, a white background and an alpha channel value
for mixing.
|
|
\documentclass[titlepage,12pt]{article}
\usepackage{a4}
\usepackage{geometry}
\usepackage[T1]{fontenc}
\usepackage{times}
\usepackage[latin1]{inputenc}
\parindent0cm
\usepackage{longtable}
\usepackage{varioref}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{hyperref}
\usepackage[dvips]{color}
%
% The pagecolor instruction in the line below was used
% to produce the bg...ps files.
%
% \pagecolor{cyan}
% \DeclareGraphicsRule{.png}{eps}{.bb}{`bmeps #1}
\DeclareGraphicsRule{.png}{eps}{.bb}{}
\geometry{body={17cm,22cm},top=1cm,left=2.5cm}
\makeindex
\begin{document}
\begin{sloppy}
\section{Example}
The options \texttt{1g} were used to create this file.
\begin{figure}
\begin{center}
\caption{Bird}
\includegraphics[width=4cm]{stefan_255_rgba.png}
\end{center}
\end{figure}
\end{sloppy}
\end{document}
|
The hyperlinks in this section point to the PS output file. Additionally
we have screenshots showing the PS output in the gv program.
First we show some simple usage examples:
Now we show how to deal with the alpha channel.
The line
\pagecolor{cyan}
in the TeX source file was activated to establish a page background color.
- The bg3c8rf.ps file
was produced using 3c8rf.
The alpha channel in the PNG image is unused.
- The bg3c8rfa.ps file
was produced using 3c8rfa.
The alpha channel is converted into an image mask.
All pixels having opacity > 0 are drawn in the color specified
by the PNG file, pixels with 0 opacity are skipped.
The alpha channel is obtained separately and used only for image
mask creation, not to mix pixel colors. This produces black
regions if alpha channel values are used to mix black foreground
and white background to gray.
- The bg3c8rfam.ps file
was produced using 3c8rfam.
Each pixel color is calculated using foreground color, opacity
and background color. Foreground color and opacity are specified
in the PNG file. If the PNG file contains a background color chunk
this color is used, otherwise the background color is white.
Here we have the gray ranges as expected.
- The bg3c8rfams0_255_255.ps
file was produced using 3c8rfams0,255,255.
Each pixel color is calculated using foreground color and opacity
from the PNG file and the specified background color cyan (RGB=0,255,255).
To create a draft file using placeholders for bitmap images only
one can use the d option, a result is shown in
d.ps.
Dirk Krause d.krause@e-technik.fh-schmalkalden.de 2002/11/11
http://www.e-technik.fh-schmalkalden.de/personen/dhp/krause/pages/software/bmeps/usage.html