1-*- coding: UTF-8 -*-
2
3README for sam2p
4by pts@fazekas.hu
5at Sun Dec 30 19:30:17 CET 2001 -- Fri Mar 22 19:25:03 CET 2002
6Sat Apr 27 00:39:12 CEST 2002
7Wed Jul  3 01:20:40 CEST 2002
8Wed Feb  5 19:46:51 CET 2003
9grammatical corrections by Steve Turner at Mon Jan 10 00:53:46 CET 2005
10
11This is the README file for sam2p, a raster to PostScript/PDF image
12conversion program. This file contains a 5-minute turbo tutorial for new and
13impatient users (search for the phrase `Turbo tutorial' in your text editor).
14As of now, this README file is the only, and definitive, documentation of sam2p.
15
16sam2p is a UNIX command line utility written in C++ (C++98) that converts many
17raster (bitmap) image formats into Adobe PostScript or PDF files and several
18other formats. The images are not vectorized. sam2p gives full control to
19the user to specify standards-compliance, compression, and bit depths. In
20some cases sam2p can compress an image 100 times smaller than the PostScript
21output of many other common image converters. sam2p provides ZIP, RLE and
22LZW (de)compression filters even on Level1 PostScript devices.
23
24Send donations to the author of sam2p:
25https://flattr.com/submit/auto?user_id=pts&url=https://github.com/pts/sam2p
26
27Do you need sam2p?
28
29-- If you have a raster image (e.g. PNG, JPEG), and you need EPS or PDF output,
30   then sam2p is probably very useful for you, because it can generate small
31   EPS and PDF files quickly, outperforming many other
32   tools (such as ImageMagick's convert) in speed and output file size. For
33   EPS output files, the compatibility of sam2p is also better that of other
34   tools.
35-- If you use any of pdftex, pdflatex, luatex, lualatex, xetex or xelatex,
36   and you have your raster images as PNG and JPEG files, then you don't need
37   sam2p or any other raster image converter, because \includegraphics works
38   on PNG and JPEG files directly.
39-- If you want to make your JPEG files smaller, there are much better tools
40   than sam2p for that.
41-- If you want to make your PNG files smaller, you can use sam2p to convert
42   PNG to PNG, but with other tools (such as pngout, advpng and zopflipng)
43   you can get a better compression ratio at a cost of slower compression
44   speed.
45-- If you want to make your PDF files smaller, use pdfsizeopt
46   (https://github.com/pts/pdfsizeopt). pdfsizeopt uses sam2p and other
47   tools (such as jbig2) under the hood to make the raster images embedded
48   in the PDF files smaller.
49
50How small is the EPS output of sam2p?
51
52-- A testimonial from Grant Ingram, UK: Anyway this is just a quick note to say
53   thanks for writing the sam2p utility which I am using to create EPS figures
54   of photographs for my thesis -- it works very well producing image sizes
55   that are some 3% of the ones produced by ImageMagick.
56
57-- A testimonial from Tom Schneider, US:
58
59     -rw-------   1 toms     delila     88628 Mar  3 17:38 prototype-small.eps
60     -rw-------   1 toms     delila   7979299 Feb 24 12:25 prototype.eps
61
62   Good GRIEF you have written a nice program!!!!  The file is 90 fold
63   smaller than the one from ImageMagick's convert.
64
65   That image that was 90x smaller had been bugging me because it was so
66   large that xdvi would strongly hesitate while I passed by the page.
67   Now it just has a minor delay, thanks to you.
68
69-- Results are not always that impressive. See the section
70   {sam2p vs convert in 2017} for more details.
71
72Benefits of sam2p:
73
74-- sam2p produces much smaller output.
75-- sam2p gives the user complete control over the data layout of the output
76   image. This includes Compression, SampleFormat and TransferEncoding.
77-- sam2p is fast.
78-- sam2p doesn't depend on external libraries. (But it does depend on external
79   programs for _reading_ JPEG, TIFF and PNG files.)
80-- sam2p supports the mainstream image formats of today without compromise.
81   sam2p has many file format fine-tuning features that are missing from
82   most other converter utilities. For example:
83   TIFF ZIP compression, TIFF LZW compression, TIFF
84   JPEG compression, transparent PNG files, BMP RLE-4 and RLE-8
85   compression, etc.
86-- sam2p supports all levels (versions) of the PostScript language and
87   output images have the smallest file size allowed by the LanguageLevel.
88-- PostScript ZIP, RLE and LZW compression is provided for _all_
89   LanguageLevels (!), even for PSL1 (which appeared in 1984). You can print
90   your ZIP-compressed images onto your ancient printer of the 1980s.
91-- sam2p supports all versions of PDF, and as with PostScript,
92   output images have the smallest file size allowed by the version.
93-- Output images of sam2p are always compliant to the standard selected by
94   the user.
95-- Output images of sam2p are real-world compatible, i.e the author has
96   tested them with many common image processing programs, for example:
97   Ghostscript, pdfTeX, xpdf, Acrobat Reader, The GIMP, ImageMagick, xv,
98   Acrobat Distiller, QuarkXPress, InDesign. The author has also tested
99   PostScript files on HP and OkiData printers.
100-- sam2p converts every pixel faithfully, preserving all the 24 RGB bits
101   intact. There is no quality or information loss unless you ask for it.
102-- sam2p uses only a minimal number of libraries. You don't have to install
103   33Mb of ballast software to use sam2p. Image libraries (libtiff etc.) are
104   _not_ used, the math library is not used, libstdc++ is not used, zlib is
105   not used.
106
107Long-term limitations of sam2p:
108
109-- Only DeviceRGB color space, with the Indexed, Gray and RGB image types.
110-- Indexed images are limited to a maximum of 256 colors.
111-- Alpha channel and transparency supported only for Indexed images: only
112   one color may be transparent.
113-- The entire input image is read into memory. During operation both the
114   input and the output images may be held in memory.
115
116Many thanks to Steve Turner for reviewing and making corrections to this
117document.
118
119Status
120~~~~~~
121sam2p is production-ready software. It is available from:
122
123	https://github.com/pts/sam2p
124
125The documentation is incomplete, but -- together with the examples -- it is
126quite useful. Please have a look at the home page to find articles and more
127documentation (the PDF docs are much more eye-pleasing than this README).
128The source code contains valuable comments, but they may be hard to find
129unless you're deeply into developing sam2p.
130
131The author is developing sam2p in his free time. (He is studying and
132working in non-free time.)
133
134The imaging model is complete. Image output routines are stable and
135adequate. Reasonable defaults are provided for all command line options.
136sam2p can usually find the best SampleFormat automatically. There is
137an educated (but not perfect) default guess for the Compression.
138
139See subsection {OutputRule combinations} about all planned formats.
140
141Turbo tutorial
142~~~~~~~~~~~~~~
143Quick compilation instructions:
144
1451. Run: make
146   It also runs ./configure with the right defaults for you.
1472. Copy the `sam2p' executable to your $PATH, or invoke it as `./sam2p'.
148
149Quick try:
150
151-- ./sam2p examples/pts2.pbm try.eps
152-- ./sam2p examples/pts2.pbm try.pdf
153-- ./sam2p examples/pts2.pbm try.ps
154-- ./sam2p examples/pts2.pbm try.png
155-- ./sam2p examples/pts2.pbm try.tiff
156-- ./sam2p examples/pts2.pbm try.xpm
157-- ./sam2p examples/pts2.pbm try.bmp
158-- ./sam2p examples/pts2.pbm try.jpg
159
160A really short User's guide
161"""""""""""""""""""""""""""
162To convert an image, call:
163
164	./sam2p <INPUT.IMG> <OUTPUT.IMG>
165	Example: ./sam2p examples/pts2.pbm try.eps
166
167To print an image as a full PostScript page, call:
168
169	./sam2p [MARGIN-SPECS] <INPUT.IMG> ps: - | lpr
170	Example: ./sam2p -m:1cm examples/pts2.pbm ps: - | lpr
171
172To convert an image to be included as EPS (Encapsulated PostScript) into
173(La)TeX documents, call:
174
175	./sam2p <INPUT.IMG> <OUTPUT.eps>
176	Example: ./sam2p examples/pts2.pbm test.eps
177	In file.tex: \usepackage{graphicx} ... \includegraphics{test}
178
179To convert an image to be included as PDF into pdf(La)TeX documents, call:
180
181	./sam2p <INPUT.IMG> <OUTPUT.pdf>
182	Example: ./sam2p examples/pts2.pbm test.pdf
183	In file.tex: \usepackage{graphicx} ... \includegraphics{test}
184
185If you have a large image file (possibly originating from dumb software),
186you can reduce the image size and keep the same filename. (Please note that
187some meta-information may be lost using this method.) This operation is
188_DANGEROUS_ if you don't have a backup, because due to a software or
189hardware problem, sam2p might clobber time image file so the actual image
190gets lost. To overwrite a file in-place, call:
191
192	./sam2p <INPUT-OUTPUT.IMG> --
193	Example: ./sam2p test.tiff --
194
195You may specify a compression method (or supply other command line options)
196to make a file even smaller, call:
197
198	./sam2p [OPTIONS] <INPUT.IMG> <OUTPUT.IMG>
199	Example: ./sam2p -c:zip test.tiff test2.tiff
200
201See the detailed documentation of available command-line options elsewhere
202in this document. You may also read section {FAQ} for more information.
203
204Too see a list about the supported input and output image file formats, call:
205
206	./sam2p
207
208Example output:
209
210	This is sam2p v0.39.
211	Available Loaders: JAI PNG JPEG TIFF PNM BMP GIF LBM XPM PCX TGA.
212	Available Appliers: XWD Meta Empty BMP PNG TIFF6 TIFF6-JAI JPEG-JAI JPEG PNM GIF89a XPM PSL1C PSL23+PDF PDF-JAI PSL2-JAI l1fa85g P-TrOpBb.
213	Usage: [...]
214
215The list of ``Available Loaders'' lists the input image file formats. All
216except for JAI are self-explanatory. JAI is JPEG-as-is, it means reading a
217JPEG file and writing back the exactly same image into an other JPEG variant,
218without quality loss.
219
220From the list of ``Available Appliers'' one can derive the supported output
221image file formats. XWD, BMP, PNG, TIFF6, JPEG, PNM, GIF89a and XPM are
222self-explanatory. TIFF6-JAI, JPEG-JAI, PDF-JAI and PSL2-JAI are JPEG
223variants into which JAI files (see above) can be saved. While the names of
224the remaining appliers may be quite cryptic to the beginner user; most of
225those appliers provide sam2p's excellent support for writing PS, EPS and
226PDF files.
227
228sam2p operation modes
229~~~~~~~~~~~~~~~~~~~~~
230sam2p is a command line utility (i.e, without a graphical user
231interface), so it can be used by composing a command line with the
232appropriate options and parameters, and launching it. See sections ``Turbo
233tutorial'' and ``One-liner mode'' for more details.
234
235sam2p is not interactive, it doesn't ask questions; thus it is completely
236suitable for batch processing and automation. sam2p doesn't log errors, but
237its STDERR can be redirected to a log file quite easily.
238
239There are three modes sam2p can operate in:
240
241-- one-liner mode: (since sam2p 0.37)
242   the user, perhaps, has to type a long command line, specifying the input
243   and the output file name, output file format, compression options, etc.
244   Most of the functionality of sam2p is available in a quite intuitive way
245   in one-liner mode. Users of the `convert' utility from ImageMagick and
246   `tiff2ps' and `tiffcp' will find that one-liner mode of sam2p is very
247   similar to them. This mode is recommended for impatient users.
248
249   Due to the nature of sam2p development, some new functionality of job mode
250   might be missing from one-liner mode. Please report this as a bug.
251
252-- job mode: the user has to write a ``job'' file (recommended extension:
253   .job), which specifies all conversion parameters, including the input and
254   output file name. The name of the job file must be passed to sam2p. This
255   mode is recommended for expert users who want to retain full control of
256   all aspects of the final output. All functionality is available in job
257   mode. This is especially useful in repetative but time separated jobs.
258
259-- GUI mode: This is completely experimental, and will be very probably
260   dropped in the near future. Try executing sam2p.tk (TCL/Tk is required).
261   Please don't use GUI mode, use one-liner mode instead! The flexability
262   of a one-liner (or job) mode is nearly imposible to encompas in a GUI.
263   No more documentation is provided for GUI mode.
264
265   There might be a Micro$oft Windoze version of sam2p available in the near
266   future, but very probably you won't get real GUI with radio boxes, lists
267   and file selection dialogs. You'll have to start sam2p from the DOS
268   prompt...
269
270One-liner mode
271~~~~~~~~~~~~~~
272This section contains a reference-style summary for the one-liner mode.
273The author knows that this section is quite incomprehensible, and a bit old.
274He is planning to completely rewrite it to be readable for the novice user.
275
276The order of the arguments and options is significant.
277
278Input file extension is discarded. The file format is recognised by its
279magic number.
280
281Output file extension gives a hint for /FileFormat:
282
283.ps    :\
284 .eps  :  \                        where PS: implies scale to fit page
285 .epsi :   >  PSL1 PSLC PSL2 PSL3                     and
286 .epsf :  /                             EPS: implies no scale changes
287 [E]PS::/                               also see Q9 in FAQs below
288.pdf   : \  PDF1.0 PDF1.2 (and)
289  PDF: : /    PDFB1.0 PDFB1.2
290.gif   : GIF89a
291.pnm   : PNM (for use with transparency)
292.pbm   : PNM /SampleFormat/Gray1
293.pgm   : PNM /SampleFormat/Gray8
294.ppm   : PNM /SampleForamt/Rgb8
295.pam   : PAM
296.pip   : PIP
297.empty : Empty
298.meta  : Meta
299.jpeg  : JPEG
300 .jpg  :  "
301.tiff  : TIFF
302 .tif  :  "
303.png   : PNG
304.xpm   : XPM
305.bmp   : BMP /Compression/RLE
306.rle   : BMP /Compression/RLE
307
308Options (case insensitive):
309
310-- --tmpremove {true|false} : remove temporary files after completion.
311      Set to false for debugging.  Default: true.
312-- -j -j:job   : display in-memory .job file
313-- -j:warn     : be verbose and display warnings about impossible combinations in
314                 the .job file
315-- -j:quiet    : print only error and fatal error messages, suppress
316                 warnings, notices etc. Must be put at the beginning of the
317                 command line to suppress initial banners, too. For example,
318                 `sam2p -j:quiet in.gif out.eps'.
319-- -s:Indexed1:Indexed4:Indexed8: Try /SampleFormats in this order, and try
320                 all others after these. Can be specified separately
321                 (e.g `-s Indexed1 -s Indexed2:Indexed8')
322-- -s:Indexed1:Indexed4:Indexed8:stop: Try only these /SampleFormats in
323                 this order. Can be specified separately
324                 (e.g `-s Indexed1:Indexed2 -s Indexed8:stop')
325-- -s:Indexed1:Indexed4:Indexed8:stopq: Try only these /SampleFormats in
326                 this order, be quiet (no warnings on failures). Can be
327                 specified separately (e.g `-s Indexed1:Indexed2 -s Indexed8:stop')
328-- -s:tr         equivalent to `-s Transparent:Opaque:Mask:Transparent2:Transparent4:Transparent8'
329-- -l:...      : /LoadHints(...)
330-- disabled: -a: /LoadHints(asis) extra /Compression/JAI; load JPEG files (and others as-is)
331
332-- -1  -ps:1 PSL1:         : [tiff2ps] hint /FileFormat/PSL1 among /PSL*
333-- -1c -ps:1c -ps:c PSLC:  : [pts] hint /FileFormat/PSLC among /PSL*
334-- -2  -ps:2 PSL2: EPS2:   : [tiff2ps,imagemagick] default hint /FileFormat/PSL2 among /PSL*
335-- -3  -ps:3 PSL3:         : [pts] hint /FileFormat/PSL3 among /PSL*
336-- -pdf:b0 PDFB1.0:        : [pts] hint /FileFormat/PDFB1.0 among /PDF* (PDF 1.0 with inline image)
337-- -pdf:b2 PDFB1.2:        : [pts] default hint /FileFormat/PDFB1.2 among /PDF* (PDF 1.2 with inline image; default because image processors usually keep inline images intact, so they wouldn't want to inefficiently recompress our image)
338-- -pdf:0 PDF1.0:          : [pts] hint /FileFormat/PDF1.0 among /PDF* (PDF 1.0 with XObject image)
339-- -pdf:2 PDF1.2:          : [pts] hint /FileFormat/PDF1.2 among /PDF* (PDF 1.2 with XObject image)
340--  EPS: EPSF:             : [pts] hint /FileFormat/PSL2 or
341                                        /FileFormat/PSL3 (for /Compression/ZIP)
342--  PDF:                   : [pts] hint /FileFormat/PDFB1.0 or
343                                        /FileFormat/PDFB1.2 (for /Compression/ZIP)
344--  PS:                    : [pts] hint /Scale/RotateOK /FileFormat/PSL2 or
345                                        /FileFormat/PSL3 (for /Compression/ZIP)
346--  PS2:                   : [imagemagick] hint /Scale/RotateOK
347                                                /FileFormat/PSL2. Deprecated, please use PS:.
348
349-- -e:0 -e:none            : /Scale/None
350-- -e -e:1 -e:scale        : /Scale/OK
351-- -e:rot -e:rotate        : /Scale/RotateOK
352
353-- GIF: GIF89a: : [imagemagick,pts] /FileFormat/GIF89a
354-- JPEG: JPG:   : [imagemagick,pts] /FileFormat/JPEG
355-- TIFF: TIF:   : [imagemagick,pts] /FileFormat/TIFF
356-- PNG:         : [imagemagick] /FileFormat/PNG
357-- XPM:         : [imagemagick] /FileFormat/XPM
358-- BMP:         : [imagemagick] /FileFormat/BMP
359-- Empty:       : [pts] /FileFormat/Empty
360-- Meta:        : [pts] /FileFormat/Meta
361-- PIP:         : [pts] /FileFormat/PIP
362-- PAM:         : [pts] /FileFormat/PAM
363-- PNM:         : [imagemagick] /FileFormat/PNM (for use with transparency)
364-- PBM:         : [imagemagick] /FileFormat/PNM /SampleFormat/Gray1
365-- PGM:         : [imagemagick] /FileFormat/PNM /SampleFormat/Gray8
366-- PPM:         : [imagemagick] /FileFormat/PNM /SampleFormat/Rgb8
367
368-- -t:bin             : [pts] hint /TransferEncoding/Binary (default unless /PS*)
369-- -t:hex             : [pts] hint /TransferEncoding/Hex (default for /PSL1 /PSLC)
370-- -t:a85             : [pts] hint /TransferEncoding/A85 (default for /PSL2 /PSL3)
371-- -t:ascii           : [pts] hint /TransferEncoding/ASCII
372-- -t:lsb1 -f:lsb2msb : [pts,tiffcp] hint /TransferEncoding/LSBfirst
373-- -t:msb1 -f:msb2lsb : [pts,tiffcp] hint /TransferEncoding/MSBfirst
374
375-- -c:none                 : [pts,tiffcp] non-default hint /Compression/None
376-- -c:lzw                  : [pts,tiffcp] hint /Compression/LZW
377-- -c:lzw:(1..99)          : [pts] hint /Compression/LZW /Predictor ...
378-- -c:zip                  : [pts,tiffcp] hint /Compression/ZIP
379-- -c:zip:(1..99)          : [pts] hint /Compression/ZIP /Predictor ...
380-- -c:zip:(1..99):(-1..9)  : [pts] hint /Compression/ZIP /Predictor ... /Effort ...
381-- -c:(rle|packbits)       : [pts,tiffcp] hint /Compression/RLE
382-- -c:(rle|packbits):(0..) : [pts] hint /Compression/RLE /RecordSize ...
383-- -c:fax                  : [pts] hint /Compression/Fax
384-- -c:fax:(-1..)           : [pts] hint /Compression/Fax /K ...
385-- -c:dct                  : [pts] hint /Compression/DCT /DCT<<>>
386-- -c:dct:...              : [pts] hint /Compression/DCT /DCT<<...>>
387-- -c:jpeg                 : [pts,tiffcp] hint /Compression/JAI, /Compression/IJG
388-- -c:jpeg:(0..100)        : [pts] hint /Compression/JAI, /Compression/IJG /Quality ...
389-- -c:ijgi                 : [pts,tiffcp] hint /Compression/IJG
390-- -c:ijg:(0..100)         : [pts] hint /Compression/IJG /Quality ...
391-- -c:g4                   : [pts] equivalent to -c:fax:-1
392-- -c:g3 -c:g3:1d          : [pts] equivalent to -c:fax:0, -c:fax
393-- -c:g3:2d                : [pts] equivalent to -c:fax:-2
394-- -c:jai                  : [pts] hint /Compression/JAI
395
396-- -m:dpi:(dimen)      : set /ImageDPI to `dimen'
397-- -m:(dimen) \        : set all margins (/TopMargin,/BottomMargin, /LeftMargin, /RightMargin) to `dimen'
398   -m:all:(dimen) \    :                  /LeftMargin, /RightMargin) to `dimen'
399   -m:a:(dimen)        :
400-- -m:horiz:(dimen) \  : set /LeftMargin and /RightMargin to `dimen'
401   -m:h:(dimen) \      :
402   -m:x:(dimen)        :
403-- -m:vert:(dimen) \   : set /TopMargin and /BottomMargin to `dimen'
404   -m:v:(dimen) \      :
405   -m:y:(dimen)        :
406-- -m:left:(dimen) \   : set /LeftMargin to `dimen'
407   -m:l:(dimen)        :
408-- -m:right:(dimen) \  : set /RightMargin to `dimen'
409   -m:r:(dimen)        :
410-- -m:top:(dimen) \    : set /TopMargin to `dimen'
411   -m:t:(dimen) \      :
412   -m:up:(dimen) \     :
413   -m:u:(dimen)        :
414-- -m:bottom:(dimen) \ : set /BottomMargin to `dimen'
415    -m:b:(dimen) \     :
416    -m:down:(dimen) \  :
417    -m:d:(dimen)       :
418
419-- --                  : if given as last arg, then   OutputFile:=InputFile
420-- --                  : if given earlier than last arg, then    treat other args as filenames
421-- -transparent:(rgb) Change the all pixels having the specified RGB color
422   to transparent. Previously transparent pixels are not changed. See FAQ
423   answer A44 for an exampe.
424
425Default and fallback compression types for each file format:
426
427-- PSL1 PSLC                  : /RLE
428-- PSL2 PDFB1.0 PDF1.0        : /JAI /RLE
429-- PSL3 PDFB1.2 PDF1.2        : /JAI /ZIP
430-- GIF89a                     : /LZW
431-- XPM PNM PAM PIP Empty Meta : )/None)
432-- JPEG                       : /JAI /IJG
433-- TIFF                       : /JAI /LZW? /RLE
434-- PNG                        : /ZIP
435-- BMP                        : /RLE
436
437Overview of job mode
438~~~~~~~~~~~~~~~~~~~~
439In the ``job mode'' sam2p doesn't accept any command line options. It must be
440controlled from the ``job'' files. In ''job mode'' sam2p expects a single command
441line argument: the name of the Job file (file format described in section
442{Jobs}). sam2p runs that single job, prints debug, info, notice, warning and
443error messages (etc.), and creates a single output file: a PS or a PDF. For
444multiple jobs and/or multiple output files, one has to run sam2p multiple
445times.
446
447The details about the output file format (including standards-compliance,
448compression and transfer encoding) are specified in the Job file and other
449files. Thus, in order to make use of the (basic and) advanced
450features of sam2p in job mode, you have to:
451
4521. Understand the basic concepts (i.e read through this manual, and have a
453   look at the examples).
4542. Prepare the input raster (bitmap) graphics file in one of the supported
455   input formats (see section {Supported input formats}).
4563. Decide the name of the output file.
4574. Decide some or all details of the output format.
4585. Create a Job file that describes those details.
4596. Invoke the program `sam2p' with the name of the Job file as a single
460   command-line argument (or `-' if the Job file is fed on STDIN).
4617. Read warning and error messages (printed to STDOUT and STDERR), and retry
462   if necessary.
463
464Revision history, changes
465~~~~~~~~~~~~~~~~~~~~~~~~~
466See in the file debian/changelog.
467
468Known bugs and issues
469~~~~~~~~~~~~~~~~~~~~~
470Please see pending bugs on https://github.com/pts/sam2p/issues .
471Feel free to report any issue there if you encounter one! Your
472bug reports and contributions are very welcome.
473
474All of these old bugs had a follow-up elsewhere, or they don't need one:
475https://code.google.com/archive/p/sam2p/issues .
476
477If you are interested in fixed or closed bugs, please see them on
478https://github.com/pts/sam2p/issues?q=is%3Aissue%20is%3Aclosed .
479
480Requirements
481~~~~~~~~~~~~
482External software required for running sam2p:
483
484-- operting system: any of:
485   -- Linux
486   -- Mac OS X
487   -- Windows (any 32-bit Windows system released since 1995 will do;
488      for older systems, install Wordpad to get MSVCRT.DLL)
489   -- FreeBSD
490   -- any UNIX system with a fairly standard BSD or POSIX C library (C++
491      libraries are not required),
492-- optionally: the libjpeg `cjpeg' utility for /Compression/IJG
493-- optionally: the libjpeg `djpeg' utility for reading JPEG files
494-- optionally: tif22pnm (uses libtiff) for reading TIFF files
495-- optionally: png22pnm (uses libpng) for reading PNG files
496
497Installation on Linux from package
498~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
499If you use Debian, Ubuntu or some other .deb-based distribution on an i386
500(x86) or amd64 (x86_64) system, download the latest .deb package from:
501
502    https://github.com/pts/sam2p/releases
503
504Install it like this:
505
506    $ sudo dpkg -i sam2p_0.49.3-1_i386.deb
507
508The executable in the .deb file doesn't have any library dependencies, it
509works on any version of Debian and Ubuntu.
510
511sam2p used to be included in Debian and Ubuntu for all architectures, but it
512isn't anymore as of 2017-07-12 (it disappeared in 2016-01-22, see
513https://tanguy.ortolo.eu/blog/article143/removing-sam2p-from-debian .)
514
515If you need PNG input support, download the latest png22pnm.exe from:
516
517    https://github.com/pts/tif22pnm/releases
518
519Then put it to the same directory where sam2p.exe is.
520
521If you need PNG input support, download the latest png22pnm.xstatic
522executable from:
523
524    https://github.com/pts/tif22pnm/releases
525
526Then put it to your $PATH as tif22pnm, something like this:
527
528    $ chmod 755 tif22pnm.xstatic
529    $ sudo mv tif22pnm.xstatic /usr/local/bin/tif22pnm
530
531Alternatively, tif22pnm may be available as a package on your Linux
532distribution.
533
534Using it on Linux without installation
535~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
536If you use any Linux on an i386 (x86) or amd64 (x86_64) system, download the
537latest sam2p.xstatic executable from:
538
539    https://github.com/pts/sam2p/releases
540
541Run it like this:
542
543    $ mv sam2p.xstatic sam2p
544    $ chmod 755 sam2p
545    $ ./sam2p
546
547The executable doesn't have any library dependencies, it works on any Linux
548system.
549
550If you need PNG input support, download the latest png22pnm.xstatic
551executable from:
552
553    https://github.com/pts/tif22pnm/releases
554
555Then put it to your $PATH as tif22pnm, something like this:
556
557    $ chmod 755 tif22pnm.xstatic
558    $ sudo mv tif22pnm.xstatic /usr/local/bin/tif22pnm
559
560Using it on FreeBSD without installation
561~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
562FreeBSD has a Linux subsystem, which is able to run sam2p. After activating
563it, follow the instructions in the section {Using it on Linux without
564installation}.
565
566Using it on Windows without installation
567~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
568Download the latest sam2p.exe from:
569
570    https://github.com/pts/sam2p/releases
571
572Then copy sam2p.exe to the current directory, or to somewhere on your $PATH,
573and run it as `sam2p' (without the quotes).
574
575sam2p.exe has only standard Windows DLL dependencies, it works on any
576Windows systems (i386 and amd64). If MSVCRT.DLL is missing, install Wordpad.
577
578If you need PNG input support, download the latest png22pnm.exe from:
579
580    https://github.com/pts/tif22pnm/releases
581
582Then put it to the same directory where sam2p.exe is.
583
584Compilation on UNIX
585~~~~~~~~~~~~~~~~~~~
586For Win32 compilation, see later.
587
588Software required for UNIX compilation:
589
590-- a UNIX system
591-- a working, GNU-compatible C++ compiler (preferably GNU G++ >=2.91. Known
592   working compilers: g++-2.91 g++-2.95 g++-3.0 g++-3.1 g++-3.2)
593-- GNU Make (`make -v' should print `GNU Make')
594-- Perl >=5.004 (no external Perl modules are required)
595-- a Bourne-compatible shell (preferably GNU Bash >=2.0)
596-- the following libraries are _not_ required: libjpeg, libtiff, libpng,
597   libungif, PDFlib, zlib, libm, libstdc++
598-- optionally: GNU autoconf >=2.53 (version number is important, see
599   AC_C_CONST)
600
601Compilation:
602
603	# compile and install required programs
604	autoconf  # optional, for experts only
605	export CC=gcc-3.2 CXX=g++-3.2  # optional, for experts only
606	./configure --enable-gif --enable-lzw
607	make
608	# the stand-alone utility `./sam2p' is now built
609	make install  # optional, may not work
610
611If installation doesn't work, please copy the file `sam2p' to somewhere in
612your $PATH, for example /usr/local/bin. Please also copy the README to a
613directory like /usr/share/doc/sam2p. There is no man page -- the
614documentation is the readme.
615
616Testing:
617
618	./sam2p
619	./sam2p examples/ptsbanner_zip.job
620	./sam2p examples/pts2.pbm try.eps
621	gs test.ps
622	# try other examples: examples/*.job
623
624On Debian systems, you'll need GNU Make, Perl, GNU Bash and any of the
625following packages for compilation:
626
627	apt-get install libc6-dev gcc-2.95 g++-2.95
628	apt-get install libc6-dev gcc-3.0 g++-3.0
629	apt-get install libc6-dev gcc-3.1 g++-3.1
630	apt-get install libc6-dev gcc-3.2 g++-3.2
631	apt-get install libc6-dev gcc-3.3 g++-3.3
632	apt-get install libc6-dev gcc-3.4 g++-3.4
633
634Please also run any of the following before ./configure:
635
636	export CC=gcc-2.95 CXX=g++-2.95
637	export CC=gcc-3.0 CXX=g++-3.0 # or g++-3.1 etc.
638
639Optionally, you may install any of
640
641	apt-get install gccchecker
642	apt-get install autoconf
643
644sam2p has been tested with a wide variety of GNU C++ compilers, including
645g++-2.91, g++-2.95, g++-3.0, g++-3.1, g++-3.2, i386-uclibc-g++-2.95,
646checkerg++-2.95. The program must be compilable _without_ _warnings_ with
647any of g++-2.91, g++-2.95, g++-3.0, g++-3.1, g++-3.2. If there is a
648compilation error, send a brief e-mail to the author immediately!
649
650Portability
651~~~~~~~~~~~
652sam2p is quite portable on UNIX systems. It runs on:
653
654	Debian GNU/Linux Slink  2.2.13 glibc-2.0.7 (development platform)
655	Debian GNU/Linux Potato 2.2.18 glibc-2.1.3
656	Debian GNU/Linux Sid    2.4.17 glibc-2.2.5
657	Digital OSF1 V4.0 1229 alpha
658        Slackware 8.0/8.1       2.4.5  libc-2.2.3  gcc-2.95.3
659	SunOS 5.7 Generic_106541-17 sun4u sparc SUNW,Ultra-2 gcc-2.95.2
660	SunOS 5.8 Generic_108528-12 sun4u sparc gcc-3.0.4
661
662Also it runs on Win32 in command line (sam2p.exe) and GUI mode (vcsam2p.exe).
663Command line mode is stable and it is recommended on this platform.
664
665It should work on any Linux or BSD system without modification. Porting to
666other Unices should be quite easy. The author welcomes portability patches.
667
668Porting to non-UNIX systems may be hard. Reasons:
669
670-- Those systems might not have GNU Make, Perl or a Bourne-compatible shell
671   installed. So the Makefile supplied won't work, and many man hours of extra
672   work would be necessary.
673-- sam2p uses the popen(3) library call to communicate with external
674   processes. This call might not be available on non-UNIX systems.
675-- sam2p expects that the $PATH contains the external binaries. Some systems
676   tend to have empty or misconfigured $PATH. On some systems, `gs' is
677   called `gswin32c.exe' etc.
678
679sam2p 0.38 has been compiled and run successfully on:
680
681-- Linux 2.2.8 Debian Slink, g++-2.91
682-- Linux 2.4.18-ac3 Debian SID, g++-2.95, g++-3.0, g++-3.1, g++-3.2
683   Executable size: 318kB.
684-- Linux 2.4.2 Debian Potato, gcc version 2.95.2 20000220 (Debian GNU/Linux)
685   No warnings.
686   Compilation took 0:47, executable size: 330kB.
687-- Linux 2.2.16-3 Red Hat Linux release 6.2 (Zoot), gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
688   No warnings.
689   Compilation took 0:44, executable size: 324kB.
690-- OSF1 V4.0 564 alpha, gcc version 2.7.2.2
691   (tons of: warning: cast discards `const' from pointer target type,
692    tons of: warning: the meaning of `\x' varies with -traditional
693    tons of: warning: cast increases required alignment of target type)
694   Compilation took 5 minutes, executable size: 550kB.
695-- SunOS 5.7 Generic_106541-19 sun4u sparc SUNW,Ultra-2, gcc version 3.1
696   (some: warning: cast from `char*' to `int*' increases required alignment of target type)
697   Compilation took 2:50, executable size: 437kB.
698-- SunOS 5.8 Generic_108528-15 sun4u sparc, gcc version 3.1.1
699   (some: warning: cast from `char*' to `int*' increases required alignment of target type)
700   Compilation took 1:26, executable size: 437kB.
701-- Slackware 8.0/8.1, kernel 2.4.5, libc.6.so (libc-2.2.3)  gcc-2.95.3
702
703sam2p 0.42 has been compiled and run successfully on:
704
705-- Windows 98, Visual C++ 6.0
706-- Windows 98, MSYS, MingGW, G++ 3.2
707
708Win32 compilation instructions for command-line mode
709~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
710(These instructions are outdated.)
711
712To compile sam2p.exe, the Win32 equivalent of the UNIX utility sam2p, you
713have to install these build dependencies first:
714
715-- MinGW and MSYS, available from http://www.mingw.org
716
717-- Perl 5.004 or newer (only perl.exe and perl5*.dll are required), available
718   from http://www.perl.com. Note that this will be a long download and a
719   bloated install, but after that, just copy perl.exe and the single
720   perl5*.dll to your C:\WINDOWS directory, and uninstall the rest.
721
722To build sam2p:
723
7241. Install all the build dependencies.
725
7262. Open the MSYS terminal window from the start menu.
727
7283. Run `explorer .' to figure out what is the current working directory.
729   Let's call this directory the MSYS home.
730
7314. Download the sam2p sources (.tar.gz) into the MSYS home from:
732
733       https://github.com/pts/sam2p/releases
734
7355. Unpack the sources. Run:
736
737       tar xzvf sam2p-latest.tar.gz
738       tar xvf sam2p-latest.tar.gz # if the previous one doesn't work
739
7406. Run `cd sam2p-*.*' to enter the sam2p source directory. It should contain
741   a newer version of this README and the file sam2p_main.cpp.
742
7437. Run `perl -edie' to check whether Perl is correctly installed. It should
744   print a line beginning with `Died '. If no such line appears (or you get
745   a `command not found' error message), go and install Perl first. Run
746   `echo $PATH' to find out where MSYS is searching for perl.exe. Copy
747   perl.exe to one of those directories.
748
7498. Run
750
751	./configure --enable-gif --enable-lzw
752	make
753
7549. The file sam2p.exe is now created in the current directory. Use it. You
755   may copy it to another directory right now:
756
757	cp sam2p.exe 'C:\Program Files'
758
75910. You should invoke sam2p.exe from the command line (COMMAND.COM or
760    CMD.EXE) with the _appropriate_ arguments, described elsewhere in
761    this document. Don't put it into the Start menu, it won't work.
762    (a window will flash in and disappear, showing an error message that you
763    haven't supplied the right arguments).
764
76511. The file bts2.tth is also created. It is an important file, because it
766    is required for the GUI compilation.
767
76812. Don't forget to install tif22pnm.exe to load TIFF files, djpeg.exe to
769    load JPEG files, cjpeg.exe to save JPEG files, and png22pnm.exe to load
770    PNG files. The installation instructions for these programs are not
771    given here.
772
773Win32 compilation instructions for GUI mode
774~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
775(These instructions are outdated.)
776
777vcsam2p.exe is a preliminary, alpha-stage attempt to provide a Win32 GUI for
778sam2p.exe. Currently it can load and display images, but not cannot save
779them. vcsam2p.exe is not ready for production use.  Feel free to enhance the
780code. Just remember to semd me copies.
781
782You'll need Visual Studio 6.0 installed.
783
7841. Download the sam2p sources (.tar.gz) from:
785
786       https://github.com/pts/sam2p/releases
787
7882. Download untarka.exe to be able to unpack the sources:
789
790       http://.../untarka.exe
791
7923. Unpack the sources. Run:
793
794       untarka.exe sam2p-latest.tar.gz
795
796   A directory sam2p-*.* will be created, containing a newer version of this
797   README and the file config-vc6.h
798
7994. You'll need bts2.tth. You can get an old, possibly outdated and buggy
800   version directly:
801
802	http://.../bts2.tth
803
804   Or, you may compile sam2p under Linux (or Win32 command-line), and copy
805   the generated bts2.tth from there.
806
807   Copy bts2.tth to the same directory as config-vc6.h
808
8095. Start the Visual C++ 6.0 environment.
810
8116. File / Open Workspace / File type: Projects
812                           Filename: vcsam2p.dsp
813   Build / Set Active Configuration: vcsam2p - Win32 Release
814   Build / Build vcsam2p.exe
815   Build / Execute vcsam2p.exe
816
8177. Don't forget to install tif22pnm.exe to load TIFF files, djpeg.exe to
818   load JPEG files, cjpeg.exe to save JPEG files, and png22pnm.exe to load
819   PNG files. The installation instructions for these programs are not
820   given here.
821
822Please report and fix bugs in vcsam2p.exe
823
824Copyright
825~~~~~~~~~
826sam2p is written and owned by Szabó Péter <pts@fazekas.hu>. sam2p contains
827code from various people.
828
829sam2p may be used, modified and redistributed only under the terms of the
830GNU General Public License, found in the file COPYING in the distribution,
831or at
832
833	http://www.fsf.org/licenses/gpl.html
834
835Supported input formats
836~~~~~~~~~~~~~~~~~~~~~~~
837-- PNM, PBM, PGM, PPM (preferred formats for non-transparent images)
838-- PNM+PGM, PNM+PBM. The input is a concatenation of a PNM and a P[GB]M
839   file with the same dimensions. The second P[GB]M contains the alpha
840   channel.
841-- XPM (preferred formats for indexed images with transparency)
842-- BMP
843-- GIF, with transparency
844-- LBM (IFF ILBM), with transparency
845-- TGA (Targa)
846-- baseline JPEG JFIF (limited by /Compression/JAI)
847-- PCX
848-- JPEG, is supported with libjpeg/djpeg
849-- TIFF, is supported with the author's tif22pnm, with transparency; also
850   works in a limited way with tifftopnm (Debian package libtiff-tools)
851-- PNG, is supported with the author's png22pnm, with transparency
852   (part of the tif22pnm sources); also works in a limited way with
853    libpng/pngtopnm (Debian package graphics/pnmtopng); with transparency
854-- PS, EPS, PDF: Ghostscript is needed (`gs' or `gswin32c.exe'), see also FAQ
855   question Q39.
856
857Note that only the major features of these file formats are supported. sam2p
858is able to load most of these files, but not all of them.
859
860Important, but unsupported input formats:
861
862-- XBM
863-- XWD
864-- Utah RLE
865
866Input image model
867~~~~~~~~~~~~~~~~~
868A (sampled, raster, bitmap) image is a rectangular array of pixels (dots)
869plus some metadata. Each pixel is represented by an unsigned integer which
870is BPC (BitsPerComponent) and CPP (ComponentsPerPixel) wide. The image
871coordinate system (X,Y) is defined as: upper left corner is (0,0), upper
872right corner is (Width-1,0), lower right corner is (Width-1,Height-1).
873(Note that this is the natural, traditional top->down, left->right system,
874and it is different from PostScript and PDF!).
875
876Some pixels of the image may be without color: they're transparent. A
877transparent pixel is not painted, so whatever was left under it on the
878paper, remains visible. (On the other hand, a colored pixel overrides the
879pixel below unconditionally. E.g a white pixel overrides a black pixel, a
880half-gray pixel, and also another white pixel; but a transparent pixel
881leaves the original one visible.). Notions referring to transparent pixels
882are: transparency, opacity, transparent, opaque, alpha channel, matte
883channel.
884
885Images are read from image files on disk. The file format is autodetected
886(see section {Supported input formats}), and it can also be specified in the
887Job file (NOT implemented yet). Not all file formats are able to specify all
888pixel data and metadata, so additional hints (such as the transparent color
889or the name of the image author) can be specified in Job files.
890
891Sample formats
892~~~~~~~~~~~~~~
893The image pixels could be packed to bytes according to several sample
894formats. Each output file (both EPS and PDF) has its own SampleFormat
895(notation: capitals).
896
897A color is either transparent or it is an opaque RGB triplet (8*3 bits).
898
899The number of colors is the number of colors actually _used_. So unused
900palette entries, and e.g unused #555555 in gray-4 are not counted.
901
902If PSLC is required, but the printer is only PSL1, then the color image will
903be printed grayscale.
904
905When _choosing_ the output format, sam2p doesn't degrade image quality. For
906example, if an image has only two colors: #000001 and #ffffff, sam2p won't
907allow the gray-1 sample format, but with #000000 and #ffffff, it will. The
908user is expected to have an image editor in which she can adjust image
909colors precisely (such as in the Dialogs/(Indexed palette) dialog of The
910GIMP).
911
912Supported Sample Formats:
913
914Name:
915	Fast compatibility
916	Slow compatibility
917	Criteria for the image
918	-- Comment(...)
919
920transparent: (specialisation of mask)
921	all
922	-
923	the whole image is transparent
924	-- implemented with empty image body
925opaque: (specialisation of mask and indexed-1)
926	all
927	-
928	the whole image contains the same, opaque color
929	-- implemented with `setrgbcolor', `fill'
930mask: (specialisation of transparent-2)
931	all
932	-
933	a transparent and a non-transparent color (any may be missing)
934	-- display a Warning if the whole image is transparent or opaque,
935	   because transparent or opaque would be a better choice
936	-- implemented with a single call to `imagemask'
937indexed-1:
938	all
939	-
940	exactly 2 non-transparent colors or 1 non-transparent color
941	-- display a Warning if only 1 non-transparent color, because
942	   opaque would be a better choice
943	-- display a Notice if colors are in black (#000000) and white
944	   (#ffffff), beacuse gray-1 would be a better choice
945	-- implemented with a `setrgbcolor', `fill', and a single call to
946	   `imagemask'
947indexed-2:
948	PSL2, PDF1.0??
949	PSLC
950	3 or 4 non-transparent colors or 1..2 non-transparent colors
951	-- display a Warning if only 1..2 non-transparent colors, because
952	   opaque or indexed-1 would be a better choice
953	-- display a Notice if colors are in (#000000, #555555, #aaaaaa,
954	   #ffffff), beacuse gray-2 would be a better choice
955	-- implemented with the /Indexed color space or colorimage +
956	   manual palette lookup
957	-- users with a PSL1 printer without PSLC should use transparent-*
958indexed-4:
959	PSL2, PDF1.0??
960	PSLC
961	5..16 non-transparent colors or 1..4 non-transparent colors
962	-- display a Warning if only 1..4 non-transparent colors, because
963	   opaque, indexed-1 or indexed-2 would be a better choice
964	-- display a Warning if all components are #00 or #ff,
965	   because rgb-1 would be a better choice (3 bits over 4 bits)
966	-- display a Notice if colors are in (#000000, #111111, ...,
967	   #ffffff), beacuse gray-4 would be a better choice
968	-- implemented with the /Indexed color space or colorimage +
969	   manual palette lookup
970	-- users with a PSL1 printer without PSLC should use transparent-*
971indexed-8:
972	PSL2, PDF1.0??
973	PSLC
974	17..256 non-transparent colors or 1..16 non-transparent colors
975	-- display a Warning if only 1..16 non-transparent colors, because
976	   opaque, indexed-1, indexed-2, indexed-4 would be a better
977	   choice
978	-- display a Warning if all components are #00, #55, #aa or #ff,
979	   because rgb-2 would be a better choice (6 bits over 8 bits)
980	-- display a Notice if all colors are gray, beacuse gray-8 would be
981	   a better choice
982	-- implemented with the /Indexed color space or colorimage +
983	   manual palette lookup
984	-- users with a PSL1 printer without PSLC should use transparent-*
985transparent-2:
986	all
987	-
988	0..1 transparent and 1..3 non-transparent colors
989	-- display a Notice that color separation was done (which can
990	   decrease speed and compression)
991	-- display a Warning if no transparent color, because `indexed-2'
992	   would be a better choice
993	-- display a Warning if only 1 non-transparent color, because `mask'
994	   would be a better choice
995	-- implemented with multiple calls to `setrgbcolor', `imagemask'
996transparent-4:
997	all
998	-
999	a transparent and 1..15 non-transparent colors
1000	-- display a Notice that color separation was done (which can
1001	   seriously decrease speed and compression)
1002	-- display a Warning if only 1..3 non-transparent colors, because
1003	   `mask' or `transparent-2' would be a better choice
1004	-- implemented with multiple calls to `setrgbcolor', `imagemask'
1005transparent-8:
1006	all
1007	-
1008	a transparent and 1..255 non-transparent colors
1009	-- display a Warning that color separation was done (which can
1010	   seriously decrease speed and compression)
1011	-- display a Warning if only 1..15 non-transparent colors, because
1012	   `mask', `transparent-2' or `transparent-4' would be a better
1013	   choice
1014	-- implemented with multiple calls to `setrgbcolor', `imagemask'
1015gray-1:
1016	all
1017	-
1018	colors are in black (#000000) and white (#ffffff)
1019	-- display a Warning if only 1 color, because opaque would be a
1020	   better choice
1021	-- implemented with the multiple-argument `image'
1022gray-2:
1023	all
1024	-
1025	colors are in (#000000, #555555, #aaaaaa, #ffffff)
1026	-- display a Warning if only 1..2 colors, because opaque,
1027	   indexed-1, or gray-1 would be a better choice
1028	-- implemented with the multiple-argument `image'
1029gray-4:
1030	all
1031	-
1032	colors are in (#000000, #111111, ..., #ffffff)
1033	-- display a Warning if only 1..4 colors, because opaque,
1034	   indexed-1, gray-1, indexed-2 or gray-2 would be a better choice
1035	-- implemented with the multiple-argument `image'
1036gray-8:
1037	all
1038	-
1039	colors must be gray
1040	-- display a Warning if only 1..16 colors, because opaque,
1041	   indexed-1, gray-1, indexed-2, gray-2, indexed-4 or gray-4
1042	   would be a better choice
1043	-- implemented with the multiple-argument `image'
1044rgb-1:
1045	PSLC, PDF1.0
1046	-
1047	color components must be #00 or #ff (8 colors max)
1048	-- display a Warning if all colors are gray
1049	-- display a Warning if only 1..4 colors, because opaque,
1050	   indexed-1, indexed-2 (or gray-*) would be a better choice
1051	-- implemented with `colorimage'
1052rgb-2:
1053	PSLC, PDF1.0
1054	-
1055	color components must be #00, #55, #aa or #ff (64 colors max)
1056	-- display a Warning if all colors are gray
1057	-- display a Warning if only 1..16 colors, because opaque,
1058	   indexed-1, indexed-2 or indexed-4 (or gray-*) would be a better choice
1059	   choice (this includes the case when color components are in
1060	   #00, #ff)
1061	-- implemented with `colorimage'
1062rgb-4:
1063	PSLC, PDF1.0
1064	-
1065	color components must be #00, #11, ... #ff (4096 colors max)
1066	-- display a Warning if all colors are gray
1067	-- display a Warning if only 1..256 colors, because opaque,
1068	   indexed-1, indexed-2, indexed-4 or indexed-8 (or gray-*) would be a better
1069	   choice (this includes the case when color components are in
1070	   #00, #55, #aa, #ff)
1071	-- implemented with `colorimage'
1072rgb-8:
1073	PSLC, PDF1.0
1074	-
1075	no transparency
1076	-- display a Warning if all colors are gray
1077	-- display a Warning if only 1..256 colors, because opaque,
1078	   indexed-1, indexed-2, indexed-4 or indexed-8 (or gray-*) would be a better
1079	   choice
1080	-- display a Warning if all color components are in
1081	   #00, #11, ... #ff, because rgb-4 would be a better choice
1082	-- implemented with `colorimage'
1083
1084The following directed (acyclic) graph represents that some formats should
1085be tried earlier than others to avoid most Warning and Notice messages. The
1086graph was created according to the descriptions above.
1087
1088	EarlierFormat LaterFormat
1089
1090	transparent mask
1091	opaque mask
1092	opaque indexed-1
1093	indexed-1 indexed-2
1094	indexed-2 indexed-4
1095	indexed-4 indexed-8
1096	gray-1 gray-2
1097	gray-2 gray-4
1098	gray-4 gray-8
1099	rgb-1 rgb-2
1100	rgb-2 rgb-4
1101	rgb-4 rgb-8
1102	gray-1 indexed-1
1103	gray-2 indexed-2
1104	gray-4 indexed-4
1105	gray-8 indexed-8
1106	rgb-1 indexed-4
1107	rgb-2 indexed-8
1108	mask transparent-2
1109	transparent-2 transparent-4
1110	transparent-4 transparent-8
1111	opaque gray-1
1112	indexed-1 gray-2
1113	indexed-2 gray-4
1114	indexed-4 gray-8
1115	opaque rgb-1
1116	gray-1 rgb-1
1117	gray-2 rgb-2
1118	gray-4 rgb-4
1119	gray-8 rgb-8
1120	indexed-2 rgb-1
1121	indexed-4 rgb-2
1122	indexed-8 rgb-4
1123	indexed-8 rgb-8
1124
1125Every directed acyclic graph (DAG) has a topological ordering on its nodes.
1126Such an ordering can be computed by the UNIX (Version 7 AT&T UNIX) utility
1127tsort(1). Its output on the author's machine:
1128
1129	opaque
1130	transparent
1131	gray-1
1132	indexed-1
1133	mask
1134	transparent-2
1135	gray-2
1136	indexed-2
1137	transparent-4
1138	rgb-1
1139	gray-4
1140	indexed-4
1141	transparent-8
1142	rgb-2
1143	gray-8
1144	indexed-8
1145	rgb-4
1146	rgb-8
1147
1148This ordering should be taken into account when someone develops her
1149Rule Profile. Rules having SampleFormats listed earlier should be earlier in
1150the Rule Profile to avoid Warning and Notice messages.
1151
1152The availability (and also Warnings and Notices) of a Sample Format for a
1153particular image can be easily decided after answering the following
1154characteristic questions:
1155
1156-- Is transparency _used_?
1157-- How many _used_ non-transparent colors are there? (257 if >=257)
1158-- Is there a non-gray color?
1159-- How many bits are required (maximum) for each component?
1160
1161Output rules
1162~~~~~~~~~~~~
1163Every detail of the output file format is precisely determined by the Output
1164Rule. The Output Rule may be specified in the Job file, or is
1165automatically chosen from several pre-defined output rules in the Output
1166Profile (see section {Output profiles} elsewhere in this document).
1167
1168Output rule entries:
1169
1170-- FileFormat: enum (see section {Standards} for detailed information), no
1171   default
1172   /PSL1      -- PostScript Level1
1173   /PSLC      -- PostScript Level1 with the CMYK and `colorimage' extension
1174   /PSL2      -- PostScript Level2 (default)
1175   /PSL3      -- PostScript Level3
1176   /PDFB1.0   -- PDF version 1.0, BI inline image, see 4.8.6 in PDFRef.pdf
1177   /PDFB1.2   -- PDF version 1.2, BI inline image, see 4.8.6 in PDFRef.pdf
1178   /PDF1.0    -- PDF version 1.0, XObject image, see 4.8.4 in PDFRef.pdf
1179   /PDF1.2    -- PDF version 1.2, XObject image, see 4.8.4 in PDFRef.pdf
1180   /GIF89a
1181   /Empty
1182   /Meta
1183   /PNM
1184   /PAM
1185   /PIP
1186   /TIFF
1187   /JPEG
1188   /PNG
1189   /XPM
1190
1191-- SampleFormat: enum, no default, see section {Sample formats}
1192   /Opaque
1193   /Transparent
1194   /Gray1
1195   /Indexed1
1196   /Mask
1197   /Transparent2
1198   /Gray2
1199   /Indexed2
1200   /Transparent4
1201   /Rgb1
1202   /Gray4
1203   /Indexed4
1204   /Transparent8
1205   /Rgb2
1206   /Gray8
1207   /Indexed8
1208   /Rgb4
1209   /Rgb8
1210   /Asis       -- accept contents of the JAI file
1211   /Bbox       -- no image, only bounding box information
1212-- WarningOK: boolean; this Output Rule is enabled iff WarningOK is true or
1213   SampleFormat causes no warnings, default: true
1214-- TransferEncoding: enum, no default
1215   /Binary -- Binary (RawBits, see pbm(5), pgm(5), ppm(5)) (Binary integers
1216   are stored in any byte order allowed by /FileFormat)
1217   /ASCII -- ASCII (text, chars: 9,10,13,32..126), used with transparent and opaque
1218   /Hex /AHx -- Hex ((PSL1), PDF1.0, PSL2 ASCIIHexEncode filter)
1219   /A85 -- A85 (PSL2 PDF1.0, ASCII85Encode filter)
1220   /MSBfirst -- Binary data with integers stored in MSB first byte order.
1221     If 0x41424344 is represented as "ABCD", the byte order is called: big
1222     endian, MSB, MSB first (preferred), most significant byte first, most
1223     significant bit first, MSB-to-LSB, network byte order, m68k byte order.
1224     QuarkXPress 3 can read only TIFF files with MSB-to-LSB byte order.
1225   /LSBfirst -- Binary data with integers stored in LSB first byte order.
1226     If 0x41424344 is represented as "DCBA", the byte order is called:
1227     little endian, LSB, LSB first (preferred), least significant byte
1228     first, least significant bit first, LSB-to-MSB, VAX byte order, PC
1229     (i386) byte order.
1230-- Compression: enum
1231   /None -- None (default)
1232   /LZW -- LZW (PSL2 PDF1.0 LZWEncode filter EarlyChange=true, UnitLength=8
1233     LowBitFirst=false)
1234   /ZIP /Flate /Fl -- ZIP (PSL3 PDF1.2 FlateEncode filter without options)
1235   /RLE /RunLength /RunLengthEncoded /RL /PackBits -- RLE (PSL2 PDF1.0
1236     RunLengthEncode filter, similar to TIFF PackBits)
1237   /Fax /CCITTFax /CCF -- Fax (PSL2 PDF1.0 CCITTFaxEncode filter,
1238     Uncompressed=true!, K=-1,0,1, EndOfLine=false, EncodedByteAlign=false,
1239     Columns=..., Rows=0, EndOfBlock=true, BlackIs1=false,
1240     DamagedRowsBeforeError=0)
1241   /DCT -- DCT (PSL2 PDF1.0 DCTEncode, options in JPEG
1242     stream)
1243   /IJG /JPEG /JPG /JFIF -- IJG (PSL2 PDF1.0 DCTEncode, options in JPEG
1244     stream; the IJG libjpeg library is used for compression, respecting the
1245     quality value 0..100). This requires /SampleFormat/Rgb8 or
1246     /SampleFormat/Gray8. This doesn't work with /SampleFormat/Asis.
1247   /JAI -- JAI (PSL2 PDF1.0 DCTEncode, options in JPEG stream; JPEG-as-is: the
1248     input file must be a JPEG file -- its contents are transferred
1249     unmodified into the /DCTDecode JPEG stream). This requires
1250     /SampleFormat/Asis, and doesn't work with any other /SampleFormats
1251-- Predictor: enum (see later), default: 25, numbering same as PSL1 filter.
1252   1 -- no predictor. (default) Must be this unless Compression is /LZW or
1253        /Flate
1254   2 -- TIFF predictor 2 (horizontal differencing)
1255   10 -- PNG predictor, None function
1256   11 -- PNG predictor, Sub function
1257   12 -- PNG predictor, Up function
1258   13 -- PNG predictor, Average function
1259   14 -- PNG predictor, Paeth function
1260   15 -- PNG predcitor, individually chosen for each line (absolute minimum)
1261         This is the same as what libpng uses by default when creating PNG.
1262   25 -- Pick 15 or 1 based on the SampleFormat: use 15 for Gray8 and Rgb8,
1263         and use 1 (no predictor) for everything else. This is the default.
1264   45 -- PNG predcitor, individually chosen for each line (unsigned minimum)
1265         Don't use this, it is quite inefficient.
1266   55 -- PNG predcitor, individually chosen for each line (signed minimum)
1267         Don't use this, it is quite inefficient.
1268
1269-- Transparent: color. Default: null. Specify a color forced to be
1270   transparent. Old transparency, if exists, is blacked!
1271-- Hints: dict
1272   see below
1273
1274The Hints member of the Output Rule contains a dict with the following
1275elements:
1276
1277-- TopMargin           : dimen; desired vertical gap between the top line of the page
1278                           and the top line of the raster. Default: 0. Ignored unless for PS
1279                           and PDF output. See docs about `dimen' elsewhere in this document.
1280-- BottomMargin        : dimen; desired vertical gap between the bottom line of the
1281                           raster and the bottom line of the page. Default: 0. Ignored unless
1282                           for PS and PDF output. See docs about `dimen' elsewhere in this document.
1283-- LeftMargin          : dimen; desired horizontal gap between the left line of the page and
1284                           the left line of the raster. Default: 0. Ignored unless for PS and PDF
1285                           output. See docs about `dimen' elsewhere in this document.
1286-- RightMargin         : dimen; desired horizontal gap between the right line of the raster and
1287                           the right line of the page. Default: 0. Ignored unless for PS and PDF
1288                           output. See docs about `dimen' elsewhere in this document.
1289-- ImageDPI            : positive number; resolution of bitmap image in dots per inch.
1290                           Default: 72, which means no scaling.
1291-- Scale               : enum /None -- don't scale (zoom, magnify) the image (default)
1292                              /OK -- scale PS image to fit page (x factor == y factor)
1293                              /RotateOK -- scale and/or rotate PS image to fit page (x factor == y factor)
1294-- EncoderBPL          : int >=1 (bits per scanline, <= rlen)
1295-- EncoderCoumns       : int >=1 (pixels per scanline)
1296-- EncoderRows         : int >=1
1297-- EncoderColors       : int >=1
1298-- PredictorColumns    : uint; also used if compression is /Fax (reasonable default)
1299-- PredictorColors     : 1..3; number of color _components_ (reasonable default)
1300-- PredictorBPC        : 1, 2, 4, 8 (reasonable default), /BitsPerComponent entry in PS and PDF
1301-- Effort              : -1..9, must be -1 unless Compression is /ZIP (-1 means 5, default)
1302-- RecordSize          : uint, default: 0. Compression must be /RLE
1303-- K                   : int, default:  0 (-2..infty). Compression must be /Fax.
1304                                       -1 means G4 1d encoding,
1305                                        0 meangs G3 1D encoding,
1306                                       -2 means G3 2D encoding with  arbitrary height, positive value
1307                                       means G3 2D encoding with that height.
1308-- Quality             : 0..100, used by IJG libjpeg when compression is /IJG. default: 75
1309-- ColorTransform      : 0..2. For IJG, this _must_ be 0 for Gray and 1 for RGB, so its value
1310                           is ignored. For DCT, its value is respected: use 0 or 1 only.  See DCTEncode
1311                           in subsubsection 3.13.3 in PLRM.pdf, and for a better documentation: see the
1312                           sources and docs of libjpeg.
1313-- TransferCPL         : number of data characters per line. Must be positive when TransferEncoding is
1314                           /Hex or /A85, and must be zero otherwise.  Default: 78
1315-- DCT                 : dict, default: <<>>. Additional parameters for the /DCTEncode filter
1316-- Comment             : string, default: empty
1317-- Title               : string, default: empty
1318-- Subject             : string, default: empty
1319-- Author              : string, default: empty
1320-- Creator             : string, default: empty
1321-- Producer            : string, default: empty
1322-- Created             : string, default: now
1323-- Produced            : string: default: now
1324
1325Metric units
1326""""""""""""
1327Certain parameters have type `dimen'. This is a metric dimension, measured
1328in any of the following real-word distance metric units:
1329
1330--  1 bp = 1 bp (big point)
1331--  1 in = 72 bp (inch)
1332--  1 pt = 72/72.27 bp (point)
1333--  1 pc = 12*72/72.27 bp (pica)
1334--  1 dd = 1238/1157*72/72.27 bp (didot point) [about 1.06601110141206 bp]
1335--  1 cc = 12*1238/1157*72/72.27 bp (cicero)
1336--  1 sp = 72/72.27/65536 bp (scaled point)
1337--  1 cm = 72/2.54 bp (centimeter)
1338--  1 mm = 7.2/2.54 bp (millimeter)
1339
1340Note: If it helps: American typesetters use 72 points per US inch,
1341thus  10 pt text will yield 72 chars per normal line of US Letter
1342      (like an IBM Selectric)
1343      12 pt text will yield 65 chars per normal line of US Letter
1344     (US normal typewritter).
1345
1346Each image pixel is assumed to be 1 bp wide and 1 bp tall. A dimen is an
1347integer or real number, followed by optional whitespace and an optional unit
1348(any of `bp', `in', `pt', `pc', `dd', `cc', `sp', `cm', `mm'). The default
1349unit is `bp', i.e a bare number is a dimen measured in `bp'. The following
1350dimens are all one inch long: `72', `72bp', `72 bp', `1in', `1 in',
1351`2.54cm', `25.4mm', `72.27pt', `6pc', `4736286.72sp'.
1352
1353Note: MiniPS and TeX use the same units.
1354
1355OutputRule combinations
1356~~~~~~~~~~~~~~~~~~~~~~~
1357In the final version of sam2p, the following combinations will be supported:
1358
1359LZW >=2 Binary|Hex|A85 >=PSL2|>=PDF1.0 Mask|Gray*|RGB*|Indexed*
1360LZW >=2 Binary|Hex|A85 >=PSL2|>=PDF1.0 Transparent+
1361ZIP >=2 Binary|Hex|A85 >=PSL3|>=PDF1.2 Mask|Gray*|RGB*|Indexed*
1362ZIP >=2 Binary|Hex|A85 >=PSL3|>=PDF1.2 Transparent+
1363None|ZIP|LZW|RLE|Fax|DCT|IJG 1 Binary|Hex|A85 >=PSL2|>=PDF1.0 Mask|Gray*|RGB*|Indexed*
1364None|ZIP|LZW|RLE|Fax|DCT|IJG 1 Binary|Hex|A85 >=PSL2|>=PDF1.0 Transparent+
1365None 1 ASCII >=PSL1|>=PDF1.0 Opaque
1366None 1 ASCII >=PSL1|>=PDF1.0 Transparent
1367ZIP  1 Binary|Hex|A85 >=PSL1 Gray*|RGB*|Indexed*
1368ZIP  1 Binary|Hex|A85 >=PSL1 Mask|Gray1|Indexed1
1369ZIP  1 Binary|Hex|A85 >=PSL1 Transparent+
1370None 1 Binary|Hex|A85 >=PSL1 Gray*|RGB*|Indexed*
1371None 1 Binary|Hex|A85 >=PSL1 Mask|Gray1|Indexed1
1372None 1 Binary|Hex|A85 >=PSL1 Transparent+
1373RLE  1 Binary|Hex|A85 >=PSL1 Gray*|RGB*|Indexed*
1374RLE  1 Binary|Hex|A85 >=PSL1 Mask|Gray1|Indexed1
1375RLE  1 Binary|Hex|A85 >=PSL1 Transparent+
1376JAI  1 Binary|Hex|A85 >=PSL2|>=PDF1.0 Asis
1377
1378TTM files
1379~~~~~~~~~
1380TTM stands for Template Toy Macro.
1381
1382A TTM file is a dirty hack for generating templates with auto-calculated
1383lengths and offsets. Currently they are used for generating PDF output files
1384(/FileFormat/PDFB10 etc.). The syntax
1385of a TTM file is MiniPS (i.e a minimalistic PostScript, similar to .job
1386files). The TTM file must contain a single MiniPS array.
1387
1388The elements of the array are called chunks. Each chunk causes some bytes
1389to be appended to the output file. Data is appended in the order the
1390chunks are listed in the TTM file, but the data calculation order may be
1391different. This way it is possible to write (calc) the length of a chunk
1392not written (filled in) yet. The very first chunk has number zero.
1393different. This way it is possible to write the length of a chunk not
1394written yet. The very first chunk has number zero.
1395
1396The chunk types:
1397
1398-- string: backtick-sequences will be substituted (e.g ``w' to the width of
1399   the image, in pixels) by writeTemplate(). The result is appended to the
1400   output file.
1401-- positive integer: The offset (zero-based byte-position of the very first
1402   character of chunk 0) of the specified chunk will be appended to
1403   the output file. Only chunks already appearead may be specified this
1404   way. If the specified chunk is an array, then printf("%10u") will be
1405   called to print the number (this is useful for making PDF xref tables),
1406   otherwise printf("%u") will be called.
1407-- negative integer: The length (measured in bytes, after substitutions)
1408   of the specified chunk will be appended to the output file, using
1409   printf("%u"). Only chunks already calculated may be specified this way.
1410-- zero: error
1411-- array: the array is interpreted as a standalone TTM subfile, and the rules
1412   are applied recursively. This subfile contains sub-chunks, and the
1413   subchunks may be arrays themselves.
1414-- other MiniPS types: error
1415
1416The chunks are calculated in the following order: first the array chunks are
1417calculated (recursively) in order of appearance, followed by the non-array
1418chunks in order of appearance.
1419
1420A TTM file can have up to 64 top-level chunks.
1421
1422Example:
1423
1424	[ 1              %0
1425	  [ (pts) ]      %1.0
1426	  -1             %2
1427	]
1428
1429The output file will be: `3pts0000000001' since chunk 1 has length 3 and
1430offset 1.
1431
1432Example job file
1433~~~~~~~~~~~~~~~~
1434	<<%sam2p job
1435	% This is file (named test0.job).
1436	/InputFile  (test0.pbm)
1437	/OutputFile (test0.pdf)
1438	/Profile [
1439	  % This in-line profile is preferred over the defaults
1440	  << /FileFormat/PDF10 /SampleFormat/Gray1 /TransferEncoding/Binary
1441	     /Compression/Fax /Hints<</K 99>> >>
1442	  (pdf10.jib) run  % elements found in external file
1443	]
1444	>>
1445
1446See the directory examples/*.job in the sam2p sources.
1447
1448sam2p vs convert in 2017
1449~~~~~~~~~~~~~~~~~~~~~~~~
1450Several test runs were done on 2017-07-12 with the latest sam2p and the
1451convert tool in ImageMagick 6.7.7-10 to compare the performance of both
1452output file size and processing speed.
1453
1454Conclusions:
1455
1456-- Don't use convert for EPS output, because with `eps3:' it produces
1457   an output file with non-ASCII characters, which is incompatible with many
1458   systems, and with `eps:' it produces huge output files. Use e.g. sam2p
1459   instead.
1460-- For PDF output and JPEG or PNG input, the latest version of both convert
1461   and sam2p are fast enough and produce an output of reasonable size.
1462-- For PDF output and some PNG input (especially if the image has at most
1463   16 colors), sam2p can be faster and produce much smaller output than
1464   convert. (This was not compared here.)
1465
1466Raw performance data:
1467
1468-- A run on a 4048x3036 landscape photo JPEG, file size 3009251 bytes:
1469
1470   $ time jpegtran -optimize -copy none <beach.jpg >beach.opt.jpg
1471   0.14s user 0.02s system 99% cpu 0.170 total
1472   output file size: 2955545 bytes
1473   (jpegtran removes some unnecessary markes from the JPEG)
1474
1475   $ time sam2p beach.jpg beach.jpg.sam2p.pdf
1476   0.00s user 0.01s system 90% cpu 0.011 total
1477   output file size: 3009793 bytes
1478   $ time convert beach.jpg beach.jpg.convert.pdf
1479   0.39s user 0.07s system 138% cpu 0.333 total
1480   output file size: 2983807 bytes
1481   (convert is a bit smarter removing unnecessary markers from the JPEG)
1482   $ time convert beach.opt.jpg beach.opt.jpg.convert.pdf
1483   0.41s user 0.17s system 136% cpu 0.419 total
1484   output file size: 2965683 bytes
1485   $ time sam2p beach.opt.jpg beach.opt.jpg.sam2p.pdf
1486   0.00s user 0.01s system 90% cpu 0.014 total
1487   output file size: 2956087 bytes
1488   (now, without the unnecessary markers, the output of sam2p is smaller)
1489
1490   $ time sam2p beach.jpg beach.jpg.sam2p.eps
1491   0.02s user 0.01s system 96% cpu 0.035 total
1492   output file size: 3809826 bytes
1493   $ time convert beach.jpg eps3:beach.jpg.convert.eps
1494   0.27s user 0.04s system 86% cpu 0.359 total
1495   output file size: 2979366 bytes
1496   (the file is small, because convert doesn't apply /ASCII85Decode,
1497    thus breaks the embedding of the EPS on some systems)
1498   $ time sam2p -t:bin beach.opt.jpg beach.opt.jpg.sam2p_n.eps
1499   0.00s user 0.00s system 84% cpu 0.006 total
1500   output file size: 2955974 bytes
1501   (that's very close to the input JPEG file size, better than convert)
1502
1503-- A run on a 4048x3036 landscape photo PNG, file size 11508728 bytes:
1504
1505   $ time sam2p beach.png beach.png.sam2p.pdf
1506   4.07s user 0.15s system 99% cpu 4.223 total
1507   output file size: 12471057 bytes
1508   $ time convert beach.png beach.png.convert.pdf
1509   2.01s user 0.13s system 106% cpu 2.015 total
1510   output file size: 18095807 bytes
1511   (convert is faster, but its output PDF is much larger)
1512
1513   $ time sam2p beach.png beach.png.sam2p.eps
1514   2.63s user 0.18s system 99% cpu 2.812 total
1515   output file size: 15734187 bytes
1516   $ time convert beach.png eps3:beach.png.convert.eps
1517   1.87s user 0.06s system 99% cpu 1.933 total
1518   output file size: 18079080 bytes
1519   (the file is larger, but it's still not fair to compere,
1520    because convert doesn't apply /ASCII85Decode,
1521    thus breaks the embedding of the EPS on some systems)
1522   (convert is faster because sam2p is slow to read PNG files)
1523   $ time sam2p -t:bin beach.png beach.png.sam2p_n.eps
1524   2.52s user 0.24s system 99% cpu 2.761 total
1525   output file size: 12428098 bytes
1526   (that's the fair comparison of sizes)
1527
1528Some comments:
1529
1530-- Converting JPEG to PDF or EPS is fast for both sam2p and convert, because
1531   JPEG decoding and encoding is not done. sam2p is even faster, because
1532   it doesn't do lossless optimizations.
1533-- When converting JPEG, convert removes some JPEG markers and does some
1534   lossless optimizations (similar but less
1535   than what `jpegtran -optimize -copy none' removes), thus the output of
1536   convert is smaller than sam2p. However, if we run the jpegtran command
1537   first, then the output of sam2p becomes smaller.
1538-- When creating EPS files with convert, `eps3:' should be specified as
1539   the output format, because `eps:' would create much larger files, mostly
1540   because of worse compression algorithms and hex-encoding.
1541-- Older versions of convert created much larger EPS files, mostly because
1542   they included an uncompressed image preview.
1543-- With the `eps3:' output format of convert, the EPS file will contain
1544   non-ASCII characters, which is incompatible with some systems, and
1545   it cannot be fixed with a command-line flag. sam2p applies /ASCII85Decode
1546   (-t:a85) by default, producing an ASCII output file. Thus convert doesn't
1547   have a good option: with `eps:' output files are huge; with `eps3:'
1548   output files are incompatible with some systems.
1549-- convert is generally slower than sam2p, except when reading PNG files
1550   (for which sam2p is about 1.5 times slower). convert used to be much
1551   slowen that it is now.
1552-- sam2p has fewer dependencies and the total binary size is smaller than of
1553   convert. This can make startup time faster, and it can make it easy to
1554   install to systems without sam2p packaged.
1555-- sam2p is smart and fast, and it produces small output with images with a
1556   few colors only (2..16). (It doesn't matter if these colors are encoded
1557   as a palette or RGB.) There were no such images in this test run.
1558-- sam2p gives control to the user to fine-tune compression and other
1559   settings for EPS and PDF, and convert doesn't. The defaults of sam2p are
1560   tuned for the general use case though.
1561
1562FAQ
1563~~~
1564Q1. Should I care about /LoadHints (,asis,) when loading JPEG files?
1565
1566A1. No, sam2p guesses it by magic (in both job mode and one-liner mode).
1567    However, you may want to set it manually in job mode:
1568
1569	/LoadHints () % use djpeg
1570	/LoadHints (,asis,) % don't use djpeg
1571	% nothing: automatic guess, based on /Compression/JAI
1572
1573Q2. How do I convert a JPEG file to PostScript Level2 EPS?
1574
1575A2. In one-liner mode, just run:
1576
1577	./sam2p <INPUT.jpg> <OUTPUT.eps>
1578	Example: ./sam2p try.jpg try.eps
1579
1580    In one-liner mode, if you have both the djpeg and cjpeg utilities
1581    (budled with libjpeg from IJG (Independent JPEG Group)), _and_ you want
1582    to adjust quality vs size of the output, just run:
1583
1584	./sam2p -c:jpeg:<QUALITY> <INPUT.jpg> <OUTPUT.eps>
1585	Example: ./sam2p -c:jpeg:60 try.jpg try.eps
1586
1587    In job mode, just run sam2p with the following .job file:
1588
1589	<<%sam2p-job;
1590	% conversion is possible without external utilities cjpeg and djpeg
1591	% No quality loss, just verbatim adata copying.
1592	/InputFile  (INPUT.jpg)
1593	/OutputFile (OUTPUT.eps)
1594	/Profile [
1595	  << /FileFormat/PSL2 /SampleFormat/Asis /TransferEncoding/A85
1596	     /Compression/JAI >>
1597	] >>
1598
1599    Alternatively, to adjust quality vs size, use the following .job file:
1600
1601	<<%sam2p-job;
1602	% external utilities cjpeg and djpeg are required
1603	% This uses a JPEG decompression (djpeg), plus lossy JPEG compression
1604	% (cjpeg), so there might be quality loss!
1605	/InputFile  (INPUT.jpg)
1606	/OutputFile (OUTPUT.eps)
1607	/Profile [
1608	  << /FileFormat/PSL2 /SampleFormat/Rgb8 /TransferEncoding/A85
1609	     /Compression/IJG /Hints <<
1610	       /Quality 40 % 0..100 (should be at least around 30)
1611	  >> >>
1612	] >>
1613
1614Q3. How do I convert a GIF file to PostScript Level2 EPS?
1615
1616A3. Check that sam2p has been compiled with GIF support: run sam2p, and
1617    examine its console output. It should contain a line:
1618
1619	Available Loaders: ... GIF ...
1620
1621    If GIF doesn't appear in the line, please recompile sam2p with:
1622
1623	make clean
1624	./configure --enable-gif --enable-lzw
1625	make
1626	cp sam2p /usr/local/bin
1627
1628    After that, run sam2p again, and check for the line above again.
1629
1630    In one-liner mode, just run:
1631
1632	./sam2p <INPUT.gif> <OUTPUT.eps>
1633	Example: ./sam2p try.gif try.eps
1634
1635    In job mode, if the GIF file doesn't have transparent pixels, run sam2p
1636    with the following .job file:
1637
1638	<<%sam2p-job;
1639	/InputFile  (INPUT.gif)
1640	/OutputFile (OUTPUT.eps)
1641	/Profile [
1642	  << /FileFormat/PSL2 /SampleFormat/Indexed8 /TransferEncoding/A85
1643	     /Compression/None >>
1644	] >>
1645
1646    If the GIF file has transparent pixels, run sam2p with the following .job
1647    file:
1648
1649	<<%sam2p-job;
1650	/InputFile  (INPUT.gif)
1651	/OutputFile (OUTPUT.eps)
1652	/Profile [
1653	  << /FileFormat/PSL2 /SampleFormat/Transparent8 /TransferEncoding/A85
1654	     /Compression/None >>
1655	] >>
1656
1657Q4. How do I covert a JPEG file to a TIFF/JPEG output file?
1658
1659A4. A TIFF/JPEG file is a TIFF file (_not_ a JPEG file!), in which the image
1660    data is compressed with JPEG (DCTEncode compression). The Compression
1661    TIFF tag value is 7. (There is also Compression==6, which corresponds to
1662    the old, obsolete JPEG format defined in the old TIFF6.0 spec.)
1663
1664    In one-liner mode, autodetection is magical. Just run:
1665
1666	./sam2p <INPUT.jpg> <OUTPUT.tiff>
1667	Example: ./sam2p try.jpg try.tiff
1668
1669    In job mode, run sam2p with the following .job file:
1670
1671	<<%sam2p-job;
1672	/InputFile  (INPUT.jpg)
1673	/OutputFile (OUTPUT.tiff)
1674	%/LoadHints (asis) % default for /Compression/JAI
1675	/Profile [
1676	  << /FileFormat/TIFF /SampleFormat/Asis /TransferEncoding/Binary
1677	     /Compression/JAI >>
1678	] >>
1679
1680    See also {FAQ question Q5} for compatibility notes.
1681
1682Q5. The TIFF/JPEG file generated by sam2p is invalid! I cannot read it with
1683    any programs.
1684
1685A5. No, it isn't invalid, but most of the programs (including those found in
1686    libtiff) cannot deal with TIFF files with JPEG compression.
1687
1688    Compatibility notes:
1689
1690    -- tif22pnm 0.03 (from the author of sam2p) can read TIFF/JPEG files
1691       perfectly. That's because it calls the TIFFRGBAImageGet() function
1692       of libtiff, which works.
1693
1694    -- sam2p 0.37 can read TIFF/JPEG files, beacuse it calls tif22pnm to do
1695       the job. Sam2p can write TIFF/JPEG files as well.
1696
1697    -- GIMP 1.0.2: error message: `Unknown photometric number 6'. GIMP TIFF
1698       import filter cannot deal with the YCbCr color space (which is the
1699       most common and de facto standard color space in non-grayscale JPEG
1700       files). It works, however, with grayscale JPEGs.
1701
1702    -- tifftopnm from libtiff-tools 3.4beta037-5.1: `unknown photometric:
1703       6'. Ditto. (Unfortunately tifftopnm doesn't call TIFFRGBAImageGet(),
1704       it just tries to re-implement an obsolete version of the function.)
1705
1706    -- `tiffcp -c jpeg' from libtiff-tools 3.4beta037-5.1 creates a
1707       perfectly legal TIFF/JPEG file.
1708
1709    -- tiffcp from libtiff-tools 3.4beta037-5.1 cannot load a file created
1710       by itself (`tiffcp -c jpeg')! There is no problem with grayscale
1711       images, but color images have one component removed.
1712
1713    -- xv 3.10a: Ditto.
1714
1715    -- display from ImageMagick 4.04: strange error message about libraries:
1716       `JPEGLib: Wrong JPEG library version: library is 61, caller expects 62.'
1717
1718    Simple conclusion:
1719
1720    -- Use sam2p or `tiffcp -c jpeg' to create a TIFF/JPEG. (Be aware that
1721       `tiffcp -c jpeg' cannot read a TIFF/JPEG: it can only create one.)
1722    -- Use tif22pnm to load or decode a TIFF/JPEG.
1723    -- In your own C programs, call the TIFFRGBAImageGet() function to read
1724       TIFF image data.
1725    -- Don't use anything else if you want to avoid compatibility problems.
1726
1727Q6. Does sam2p support transparency and alpha channels?
1728
1729A6. sam2p supports only bilevel transparency (i.e a pixel is either fully
1730    opaque or fully transparent), and only with indexed images. Transparency
1731    is supported when loading indexed PNG, TIFF, PNM, GIF, LBM and XPM files.
1732    A PNM file with transparency is a regular PBM/PGM/PPM file with a
1733    PBM image appended to it as the alpha channel (black pixel is
1734    transparent).
1735
1736    For transparent output, the user has to specify /Transparent, /Mask,
1737    /Transparent2, /Transparent4 or /Transparent8 as /SampleFormat. This
1738    works with:
1739
1740    -- /FileFormat/PSL1+    /SampleFormat/Transparent
1741    -- /FileFormat/PDF1.0+  /SampleFormat/Transparent
1742    -- /FileFormat/PDFB1.0+ /SampleFormat/Transparent
1743    -- /FileFormat/PSL1+    /SampleFormat/Mask
1744    -- /FileFormat/PDF1.0+  /SampleFormat/Mask
1745    -- /FileFormat/PDFB1.0+ /SampleFormat/Mask
1746    -- /FileFormat/GIF89a   /SampleFormat/Mask
1747    -- /FileFormat/PNM      /SampleFormat/Mask
1748    -- /FileFormat/TIFF     /SampleFormat/Mask
1749    -- /FileFormat/PNG      /SampleFormat/Mask
1750    -- /FileFormat/XPM      /SampleFormat/Mask
1751    -- /FileFormat/PSL1+    /SampleFromat/Transparent+
1752    -- /FileFormat/GIF89a   /SampleFormat/Transparent+
1753    -- /FileFormat/PNM      /SampleFormat/Transparent+
1754    -- /FileFormat/TIFF     /SampleFormat/Transparent+
1755    -- /FileFormat/PNG      /SampleFormat/Transparent+
1756    -- /FileFormat/XPM      /SampleFormat/Transparent+
1757
1758Q7. How large is a pixel of PostScript and PDF files generated by sam2p in
1759    real-world metric units (inches or centimeters)?
1760
1761A7. 72 big points == 1 inch == 2.54 centimeters
1762
1763    1 pixel == 1 big point
1764
1765Q8. I have an image with transparent pixels. What happens if I convert it to
1766    /Rgb* or /Gray*?
1767
1768A8. Either of the following will happen:
1769
1770    -- You get an error message, sam2p refuses to ignore transparency.
1771       Please use /SampleFormat/Transparent+, or call an image manipulation
1772       program to remove transparency from the image before feeding it to
1773       sam2p.
1774    -- Transparency information will be lost, and the color of formerly
1775       transparent pixels will be undefined. This would be a bug in sam2p,
1776       you should report it.
1777
1778    However, if you loaded a GIF file, and
1779    transformed it to /Gray8 or /Rgb8, the original palette entry (RGB
1780    triplet) is faithfully preserved.
1781
1782Q9. How do I generate a PostScript page ready for immediate printing with
1783    margins and the image properly scaled to fit the page?
1784    How do I create a PostScript file that will automatically scale the
1785    image to the maximum when printed?
1786
1787
1788A9. To print an image as a full PostScript page, call:
1789
1790	./sam2p [MARGIN-SPECS] <INPUT.IMG> ps: - | lpr
1791	Example: ./sam2p -m:1cm examples/pts2.pbm ps: - | lpr
1792
1793    To create a PostScript file for printing, call:
1794
1795	./sam2p [MARGIN-SPECS] <INPUT.IMG> [ps:] <OUTPUT.ps>
1796	Example: ./sam2p -m:1cm examples/pts2.pbm try.ps
1797
1798    The `-m' option above is sets all four margins to `1 cm'. You can
1799    set the margins individually:
1800
1801	Example: ./sam2p -m:left:7mm -m:right:1cm -m:top:0.5in \
1802          -m:bottom:18bp examples/pts2.pbm try.ps
1803
1804    As you can see in this example, you may specify dimensions in various
1805    metric units, see subsection {Metric units}.
1806
1807    You are strongly encouraged to print raster images with sam2p. Be aware
1808    that The GIMP 1.2 printing plugin has several weird contrast setting
1809    problems (even for /Gray1 images); white pixels will be gray etc. Other
1810    utilities may add unnecessary text banners or scale the image
1811    inappropriately.
1812
1813    In one-liner mode, sam2p guesses from the file extension and the selector
1814    (`ps:') whether the desired output file format is PostScript (fit single
1815    page) or Encapsulated PostScript (leave size as-is, suitable for
1816    inclusion into TeX documents).
1817
1818    In job mode, without /Scale/OK and /Scale/RotateOK in /Hints,
1819    sam2p outputs EPS (Encapsulated PostScript) with /FileFormat/PSL*. EPS
1820    files should be included as figures into other documents (such as TeX
1821    and InDesign), not printed alone. If you just want to print a sampled
1822    image alone, please use your favourite graphics manipulation program
1823    instead of sam2p.
1824
1825    In job mode, create a .job file for the EPS file, and add /Hints. For
1826    example:
1827
1828     <<%sam2p-job;
1829     /InputFile  (test.in)
1830     /OutputFile (test.ps)
1831     /Profile [
1832       << /FileFormat/PSL2 /SampleFormat/Rgb8 /TransferEncoding/A85
1833          /Compression/None /Predictor 1
1834          /Hints << /Scale/OK % or /Scale/RotateOK
1835                    /LeftMargin 12 % measured as number/72 inches
1836                    /Rightargin 12 % measured as number/72 inches
1837                    /TopMargin 12 % measured as number/72 inches
1838                    /BottomMargin 12 % measured as number/72 inches
1839                 >>
1840       >>
1841      ]
1842     >>
1843
1844Q10. Do the EPS files created by sam2p conform to some specifications?
1845
1846     The EPS output of sam2p conforms to the following Adobe specifications:
1847
1848	5001.DSC_Spec.pdf
1849	5002.EPSF_Spec.pdf
1850
1851     DSC and ADSC are: Adobe Document Structuring Conventions. They are
1852     comments with lines beginning with `%!' and `%%' in PS and EPS files.
1853
1854     An excerpt:
1855
1856	The following example illustrates the proper use of DSC comments in a
1857	typical page description that an application might produce when including an
1858	EPS file. For an EPS file that is represented as
1859
1860	%!PS-Adobe-3.0 EPSF-3.0
1861	%%BoundingBox: 4 4 608 407
1862	%%Title: (ARTWORK.EPS)
1863	%%CreationDate: (10/17/89) (5:04 PM)
1864	%%EndComments
1865	...PostScript code for illustration..
1866	showpage
1867	%%EOF
1868
1869     DSC comments discussion:
1870
1871	%!PS-Adobe-3.0 EPSF-3.0 (mandatory)
1872	%%BoundingBox: ... ... ... ... (mandatory)
1873
1874  	%%Extensions: CMYK (optional, for /PSLC)
1875	%%LanguageLevel: 2 (optional, for /PSL2)
1876	%%LanguageLevel: 3 (optional, for /PSL3)
1877	%%Creation (strongly recommended)
1878	%%Title (strongly recommended)
1879	%%CreationDate (strongly recommended)
1880	%%Trailer (optional)
1881	%%EOF (optional)
1882	%%DocumentData: Clean7Bit (optional)
1883	%%DocumentData: Binary (optional)
1884
1885Q11. I get the error message `sam2p: Error: applyProfile: invalid
1886     combination, no applicable OutputRule'. Help!
1887
1888A11. This error message means you have requested an invalid combination of
1889     FileFormat, SampleFormat, Compression etc. parameters. If you use
1890     one-liner mode, and you're sure that you've specified your will
1891     correctly in the command line, please report this error message as a
1892     sam2p bug (also specify -j in the command line). If you use job mode,
1893     please read on.
1894
1895     Example 1:
1896       /Compression/Fax is not allowed in /PSL1.
1897
1898     Solution 1:
1899       specify /FileFormat/PSL2 /Compression/Fax.
1900
1901     Example 2:
1902       /Compression/IJG requires /SampleFormat/Gray8 or /SampleFormat/Rgb8.
1903       Please have a look at the messages `sam2p: Warning: check_rule: ...'
1904       to get more specific information. After that, correct your request.
1905
1906     Solution 2:
1907       specify /Compression/IJG /SampleFormat/Rgb8.
1908
1909     Another cause for this message is that your request cannot be applied
1910     to the image you've specified. In this case, there is no relevant
1911     `sam2p: Warning: check_rule: ...' message.
1912
1913     Example 1:
1914       you've requested /SampleFormat/Indexed4,
1915       but the input image has more than 16 colors.
1916
1917     Solution 1:
1918       specify /SampleFormat/Rgb8.
1919
1920     Example 2:
1921       you've requested /SampleFormat/Indexed4,
1922       but the input image has transparency.
1923
1924     Solution 2:
1925       specify /SampleFormat/Transparent8.
1926
1927     It is possible, but very unlikely that this error message is caused by
1928     a bug in sam2p.
1929
1930Q12. Can I use /Compression/Fax when bits-per-pixel > 1 ?
1931
1932A12. With /FileFormat/PS* and /FileFormat/PDF*, you can (but you shouldn't,
1933     because of the possibly poor compression ratio). With /FileFormat/TIFF,
1934     you're not allowed to, because the TIFF specification forbids it.
1935     Example one-liners:
1936
1937	sam2p -s:Indexed8 -c:fax test.gif test.pdf   # OK
1938	sam2p -s:Indexed8 -c:fax test.gif test.eps   # OK
1939	sam2p -s:Indexed8 -c:fax test.gif test.tiff  # forbidden
1940
1941Q13. Bad luck?
1942
1943A13. Not for me.
1944
1945Q14. Can I use negative margins (i.e /TopMargin -20) to crop the output
1946     image?
1947
1948A14. No. Margins are ignored by sam2p unless /FileFormat is /PSL* or /PDF*.
1949     Even with these formats, the image is only moved, not cropped. Please
1950     use an image manipulation program (e.g The GIMP) to crop your images
1951     before feeding them to sam2p.
1952
1953Q15. When I try to print the PostScript output of sam2p, the edge of the
1954     image is missing (white).
1955
1956A15. Many printers cannot print to the edge of the paper (so that region is
1957     left white). Please increase the margins to a safe value, for example:
1958
1959	./sam2p -m:7mm test.ppm test.ps
1960	lpr test.ps
1961
1962     See also {FAQ question Q9} for more information about margins.
1963
1964Q16. How do I report a bug in sam2p?
1965
1966A16. Please send an e-mail to the author (pts@fazekas.hu, see more in
1967     section {Copyright}) describing the problem. Don't forget to:
1968
1969     -- download the latest version of sam2p, and try it with the same image
1970     -- describe what sam2p does (incorrectly)
1971     -- describe what sam2p should do if there was no bug
1972     -- run sam2p without arguments, and attach its output (STDOUT) to the
1973        bug report
1974     -- attach the exact command line with which you call sam2p to the bug
1975        report
1976     -- if you spot the bug in one-liner mode, specify the `-j' option in
1977        the command line, and attach the messages printed by sam2p (both
1978        STDOUT and STDERR) to the bug report
1979     -- if you spot the bug in job mode, attach the .job file you are using
1980        to the bug report
1981     -- attach the input image file to the bug report. Try to attach a file
1982        as small as possible.
1983     -- if sam2p runs successfully (i.e it prints `Success.'), and it
1984        creates an output image, but you think that the output image is
1985        incorrect, attach the output image to your bug report
1986     -- if you have a similar input image, for which sam2p works fine,
1987        attach it to the bug report
1988
1989Q17. How long does the LZW patent held by Unisys last?
1990
1991A17. mcb@cloanto.com (author of http://lzw.info) wrote:
1992
1993     Thank you for your interest and mail. I must stress that the "exact"
1994     answers you may be looking for may come only from lawyers and courts,
1995     and I am none of these. If you consider the IBM, the BT and Unisys US
1996     patents, then the last of the three would be the Unisys one, expiring,
1997     as the article I think mentions, on June 19, 2003, 24:00. There cannot
1998     be other (new) patents on LZW, as far as I know. Please let me know if
1999     you find different information.
2000
2001Q18. I want to create an RGB PostScript image, but sam2p creates a Gray one,
2002     or it gives me an error message.
2003     For example: `./sam2p -1 -s:rgb1 examples/ptsbanner.gif test.eps'.
2004
2005A18. /PSL1 doesn't support RGB images. There are two solutions:
2006
2007     -- Use /PSLC or /PSL2 or /PSL3 instead or drop the '-1'
2008        alltogether. Examples:
2009
2010	./sam2p -1c -s:rgb1 examples/ptsbanner.gif test.eps  # /PSLC
2011	./sam2p -2  -s:rgb1 examples/ptsbanner.gif test.eps  # /PSL2
2012	./sam2p     -s:rgb1 examples/ptsbanner.gif test.eps  # /PSL2 or /PSL3
2013
2014     -- Use /Mask or /Transparent+. Note that you'll very probably get poor
2015        compression ratio.
2016
2017	./sam2p -1 -s:tr:stop examples/ptsbanner.gif test.eps  # /PSL1
2018
2019     You can get more (and more useful) error messages from sam2p if you
2020     specify the `-j:warn' option. You may also try specifying
2021     `-s:rgb1:stop' instead of `-s:rgb1' to force sam2p try /SampleFormat/Rgb1
2022     only.
2023
2024Q19. sam2p doesn't allow me to use /Compression /Fax. For example:
2025     `./sam2p -c fax examples/ptsbanner.gif test.eps'. The same command
2026     works fine without `-c fax'.
2027
2028A19. /Compression/Fax is intended to be used with images with 1 bit per
2029     pixel. However, in PostScript and PDF, you can use it for any image
2030     data, but compression ratio will be very poor for other than /Gray1,
2031     /Indexed1 or /Mask, of course. You can force sam2p to use /Fax by
2032     specifying the desired SampleFormat in option `-s'. Examples:
2033
2034	sam2p -s:Indexed8 -c:fax test.gif test.pdf   # OK
2035	sam2p -s:Indexed8 -c:fax test.gif test.eps   # OK
2036	sam2p -s:Indexed8 -c:fax test.gif test.tiff  # forbidden by TIFF std
2037
2038     See {FAQ question Q12} for more information.
2039
2040Q20. Can sam2p convert images with transparency to PDF?
2041
2042A20. Only if the image has at most 1 non-transprent color
2043     (/SampleFormat/Mask). See {FAQ question Q6} for details.
2044
2045     Although PDF-1.3 supports transparency masks for arbitrary PDF images,
2046     sam2p 0.39 doesn't. That's because the author of sam2p hasn't
2047     implemented it yet.
2048
2049Q21. I get the error message `sam2p: Warning: buildProfile: ignoring, no
2050     handlers for OutputRule'. Help!
2051
2052A21. This means that sam2p doesn't know how to do the conversion you've
2053     requested (and it even doesn't know whether the request is erroneous or
2054     not). This might be because your request is bad (it is impossible to
2055     be fulfilled), or your request is good, but sam2p doesn't know how to
2056     deal with it. If you think that the latter is the case, please report
2057     this message as a bug.
2058
2059     See {FAQ question Q11} for more information.
2060
2061Q22. How do I compile with G++ 3.2?
2062
2063A22. See the answer in section {Compilation and installation}. Don't forget
2064
2065	export CC=gcc-3.2 CXX=g++-3.2
2066
2067Q23. How do I do a `make dist' without running configure again?
2068
2069A23. Just issue
2070
2071	make MAKE_DIST=1 dist
2072
2073Q24. I cannot open a JPEG file in the Win32 version.
2074
2075A24. Make sure you have djpeg.exe on your PATH. Simply copy it to your
2076     C:\WINDOWS directory.
2077
2078Q25. I cannot open a TIFF file in the Win32 version.
2079
2080A25. Make sure you have tif22pnm.exe on your PATH. Simply copy it to your
2081     C:\WINDOWS directory.
2082
2083Q26. I cannot open a PNG file in the Win32 version.
2084
2085A26. Make sure you have png22pnm.exe on your PATH. Simply copy it to your
2086     C:\WINDOWS directory.
2087
2088Q27. What is tif22pnm?
2089
2090A27. tif22pnm is a TIFF -> PNM converter written by the author of sam2p. It
2091     can load more TIFF files correctly than tifftopnm, ImageMagick convert,
2092     xv and The GIMP. The TIFF loader code is based on GIMP 1.3, but has
2093     many bugfixes and improvements. sam2p uses tif22pnm to load TIFF files.
2094     You can download tif22pnm from
2095
2096        https://github.com/pts/tif22pnm
2097
2098Q28. What is png22pnm?
2099
2100A28. png22pnm is a PNG -> PNM converter compiled by the author of sam2p. It
2101     is based on the excellent pngtopnm utility, but doesn't depend on the
2102     NetPBM library (only libpng). sam2p uses png22pnm (or, as a fallback:
2103     pngtopm) to load PNG files. png22pnm is part of the tif22pnm package,
2104     so you can download it from
2105
2106         https://github.com/pts/tif22pnm
2107
2108Q29. Can sam2p convert a transparent GIF to PDF?
2109
2110A29. The PDF-1.3 file format supports transparent images, but sam2p doesn't.
2111     However, if the image contains at most two colors (including the
2112     transparent pixel), sam2p can create a working PDF-1.2 file; use
2113     Ghostscript to view it, because Acrobat Reader 5.0 is buggy. However,
2114     sam2p supports generating transparent EPS, GIF, PNG, PNM, XPM and TIFF
2115     files up to 256 colors.
2116
2117Q30. How do I build my own sam2p debian package?
2118
2119A30. Please download the newest sources (.tar.gz) from
2120
2121	https://github.com/pts/sam2p
2122
2123     As root, run
2124
2125	apt-get update
2126	apt-get install debmake fakeroot dpkg
2127	apt-get install make g++ gcc perl sed
2128
2129     As normal user, run (in the directory containing sam2p_main.cpp):
2130
2131	debian/rules clean
2132	rm -f build*
2133	debian/rules build
2134	fakeroot debian/rules binary
2135	ls -l ../sam2p_*.deb
2136
2137     As root, substitute X and Y, and run:
2138
2139	dpkg -i sam2p_X_Y.deb
2140
2141     Please also install the tif22pnm and png22pnm packages from the author
2142     of sam2p (and the Debian standard libjpeg-progs package), available as
2143     Debian source from:
2144
2145	https://github.com/pts/tif22pnm
2146
2147Q31. Why not use libjpeg/libtiff/libpng/zlib or any other library with
2148     sam2p?
2149
2150A31. -- library and .h incompatibilities (the binary would be less portable
2151        across Linux systems)
2152     -- to avoid forced dependencies
2153     -- checkergcc wouldn't work
2154
2155Q32. How do I specify the page size when printing a .ps file (-m and -e
2156     command line options)?
2157
2158A32. You cannot. (Use -m to specify the margins.) The page size is
2159     autodetected by your printer when the page is
2160     printed. So you can print the same .ps file on different printers, and the
2161     margins will be all right on all of them.
2162
2163     If you really have to specify the page size, edit the .ps file and
2164     insert the `a4 ' or `letter ' command after the last line of the
2165     first block of lines starting with %%. You may also use something like
2166     `1 dict dup /PageSize [ 595 842 ] put setpagedevice ' to exactly specify
2167     the page width and height in 1/72 inches.
2168
2169     For example, change the PostScript file
2170
2171       %!PS-Adobe-3.0
2172       %%Pages: 1
2173       %%DocumentData: Clean7Bit
2174       %%LanguageLevel: 1
2175       %%EndComments
2176       %%Page: 1 1
2177       save
2178       ... % many lines omitted
2179       %%Trailer
2180       %%EOF
2181
2182     to
2183
2184       %!PS-Adobe-3.0
2185       %%Pages: 1
2186       %%DocumentData: Clean7Bit
2187       %%LanguageLevel: 1
2188       %%EndComments
2189       %%Page: 1 1
2190       1 dict dup /PageSize [ 595 842 ] put setpagedevice
2191       save
2192       ... % many lines omitted
2193       %%Trailer
2194       %%EOF
2195
2196     Please note that PostScript is a programming language, so your changes
2197     might be undone by instructions later in the file. You might find the
2198     a2ping.pl utility (written by the author of sam2p) useful:
2199
2200       a2ping.pl -v --papersize=a4 in.ps out.ps
2201
2202Q33. How do I control ZIP compression ratio?
2203
2204A33. Use
2205
2206	sam2p -c:zip:1:0 in.img out.png  # uncompressed ZIP carrier
2207	sam2p -c:zip:1:1 in.img out.png  # normal compression
2208	sam2p -c:zip:1:9 in.img out.png  # maximum compression
2209
2210Q34. ImageMagick convert creates smaller PNGs. Why?
2211
2212A34. I don't know the real reason.  Probably because ImageMagick uses libpng,
2213     which is smarter than sam2p.
2214
2215     You are probably trying to convert a JPEG or other true color photo to
2216     PNG. Try one of the following compression options:
2217
2218	sam2p -c:zip:12:7   # 464727 bytes
2219	sam2p -c:zip:12:8   # 454271 bytes
2220	sam2p -c:zip:12:9   # 447525 bytes
2221	sam2p -c:zip:13:9   # 488748 bytes
2222	sam2p -c:zip:14:9   # 454182 bytes
2223	sam2p -c:zip:15:9   # 453080 bytes
2224	convert -quality ?  # 454438 bytes
2225
2226Q35. Can sam2p convert large JPEGs to smaller ones (with loss of
2227     quality and resolution)?
2228
2229A35. sam2p cannot resize or scale images. So the pixel width and height of
2230     the input and output image cannot be changed. If you need that (for
2231     example you want to create thumbnails), use the famous convert(1)
2232     utility of ImageMagick. For example:
2233
2234	convert -scale 444   -quality 50 in.jpg out.jpg  # specify out width
2235	convert -scale x444  -quality 50 in.jpg out.jpg  # specify out height
2236	convert -scale "10%" -quality 50 in.jpg out.jpg  # specify scale ratio
2237
2238     However, it is possible to specify the quality of the JPEG output of
2239     sam2p. The quality of 0 means ugly output with small file size, and the
2240     quality of 100 means nice output with big file sizes. You can specify
2241     intermediate integer quality values (50 and 75 are recommended). Be
2242     prepared that qualties above 30 (or so) may not work on all JPEG viewers.
2243     For example:
2244
2245	 sam2p -c ijg:10 large_input.jpg small_output.jpg
2246
2247     sam2p uses the cjpeg(1) and djpeg(1) utilities from libjpeg to write
2248     and read JPEG files, respectively. If you need more control over your
2249     JPEG output, then forget sam2p, and please consult the documentation of
2250     those utilities.
2251
2252Q36. Can sam2p convert JPEG to GIF?
2253
2254A36. Yes, it can, but usually not directly. GIF allows a maximum of 256
2255     different
2256     colors in an image. A typical RGB JPEG image contains many more colors,
2257     so it has to be quantized down to 256 colors first. For example, if the
2258     console output of ``sam2p in.jpg out.gif'' contains ``applyProfile:
2259     invalid combination, no applicable OutputRule'', then in.jpg must be
2260     quantized first:
2261
2262	convert in.jpg out1.gif  # does the quantization automatically
2263	sam2p out1.gif out2.gif  # compresses the output image further
2264
2265     From out1.gif and out2.gif keep the one with the smaller file size. It
2266     is common that convert(1) creates huge GIF files because LZW compression
2267     is disabled inside it. sam2p should be compiled with LZW compression
2268     and GIF input/output enabled. To check this, run sam2p, and
2269     examine its console output. It should contain a line:
2270
2271	Available Appliers: ... GIF89a+LZW ...
2272
2273     If GIF89a+LZW doesn't appear in the line, please recompile sam2p with:
2274
2275	make clean
2276	./configure --enable-gif --enable-lzw
2277	make
2278	cp sam2p /usr/local/bin
2279
2280     , and try again.
2281
2282Q37. I need to transform GIF images of 15 colors to BMPs of 256 colors not
2283     compressed. sam2p converts it to BMP 16 colors...
2284
2285A37. Use
2286
2287	sam2p -c none -s rgb8 in.gif out.bmp
2288
2289     If you get an error message `Error: applyProfile: invalid combination,
2290     no applicable OutputRule', it very probably means that your GIF is
2291     transparent. Remove the transparent color within an image editor first.
2292
2293Q38. Can sam2p _load_ PDF or EPS files?
2294
2295A38. Yes, if you have Ghostscript installed, and your input EPS file is not
2296     too exotic. This has been tested on Linux only. If you experience
2297     problems loading EPS files, but no problems loading PDF files, please
2298     run a2ping.pl written by the author of sam2p to make your EPS file more
2299     compatible.
2300
2301Q39. Can sam2p load an EPS or PDF file with an arbitrary resoultion?
2302
2303A39. Yes. For example use one of
2304
2305	sam2p -l:gs=-r216 in.eps out.png
2306	sam2p -l:gs=-r216 in.pdf out.png
2307
2308     to have resoultion 216 DPI (image scaled 3 times to both directions).
2309     Without scaling, 72 DPI is the default.
2310
2311Q40. Can sam2p emit a multi-page PDF or a multi-page PS?
2312
2313A40. No, it can't. Emitting a multi-page document would need a fundamental
2314     change of the sam2p architecture. (Should the 2nd page be compressed with
2315     a different method? What if the 2nd contains too many colors? Should we
2316     keep all previous pages in memory?)
2317
2318     I think another program should be written that is able to concatenate
2319     EPS/PS or PDF files. I've already written a PDF-merger called pdfconcat,
2320     available from https://raw.githubusercontent.com/pts/pdfconcat/master/pdfconcat.c
2321     . An EPS-merger would be even easier. But I don't have time to
2322     implement these features directly into sam2p soon.
2323
2324Q41. Can sam2p read a multi-page TIFF?
2325
2326A41. sam2p reads only the first page.
2327
2328     The auxilary utility tif22pnm could be patched so it extracts other
2329     pages, and a new command line option can be added to sam2p that passes
2330     the required page number to tif22pnm. But I don't have time to
2331     implement these features soon.
2332
2333     By the way, multi-page TIFFs can be created with the following command:
2334
2335	tiffcp -c g4 d1.tiff d2.tiff d3.tiff output.tiff
2336
2337Q42. Can sam2p convert a multi-page TIFF to a multi-page PDF?
2338
2339A42. No. There are two main problems: See also Q40 and Q41.
2340
2341Q43. How do I convert a TIFF image to a 1-bit black-and-white PDF? Should I
2342     use `sam2p -c:fax test.tif test.pdf'?
2343
2344A43. The above will ensure that fax compression is used. What you need for
2345     ensuring that the output is 1-bit black-and-white is:
2346
2347        sam2p -s:gray1:stop test.tif test.pdf
2348
2349     You can also specify a compression algorithm (I recommend -c:zip):
2350
2351        sam2p -c:fax -s:gray1:stop test.tif test.pdf
2352        sam2p -c:lzw -s:gray1:stop test.tif test.pdf
2353        sam2p -c:zip -s:gray1:stop test.tif test.pdf
2354
2355     If you get the error message
2356
2357        sam2p: Error: applyProfile: invalid combination, no applicable OutputRule
2358
2359     then your input test.tif is not really black-and-white. Open it in an
2360     image editing program and ensure that the colors are #000000 and
2361     #ffffff only.
2362
2363     > The tiff is black and white, bilevel - I just want to avoid the
2364     > test.pdf from using 8bpp by default (like it does in imagemagick)
2365
2366     The default for sam2p is not 8bpp. To see what the default is, run sam2p
2367     with the `-j' option and check `OutputRule #1' on the console output.
2368     What you are interested in is the /SampleFormat field.
2369
2370Q43. Acrobat Reader (5.0 and 6.0) cannot read the PDFs converted from a JPEG
2371     with sam2p. I get the message: `There was an error processing a page.
2372     Expected `EI' while parsing an image.'.
2373     (The same problem happens with Ghostscript 6.50 with a different error
2374     message. xpdf-1.0 reports: bad DCT trailer.)
2375
2376A43. Very probably the JPEG stream of your original input image file is
2377     rejected by the PDF viewers. (In fact, Ghostscript 7.x doesn't
2378     complain.) sam2p doesn't do strict JPEG validation when converting JPEG
2379     to PDF -- it just blindly assumes that the JPEG file is correct. To
2380     ensure this, you have to re-encode the JPEG.
2381
2382     Instead of this:
2383
2384       sam2p bad.jpeg bad.pdf
2385
2386     do this:
2387
2388       sam2p -c ijg:50 bad.jpeg good.pdf  # much slower!
2389
2390     or this:
2391
2392       <bad.jpeg djpeg | cjpeg -quality 50 | sam2p - good.pdf
2393
2394     or this:
2395
2396	djpeg <bad.jpeg >temp.pnm
2397	cjpeg -quality 50 <temp.pnm >temp.jpeg
2398	sam2p temp.jpeg good.pdf
2399
2400     The real reason why Acrobat Reader rejects the JPEG is unknown to me.
2401     I also don't know of any baseline JPEG compliance testing software.
2402     (But if you re-encode with djpeg and cjpeg, it becomes compliant.)
2403
2404     (thanks to Thomas Kraemer for reporting the problem)
2405
2406Q44. How do I create an 1x1 transparent GIF and PNG?
2407
2408A44. Do
2409
2410	echo "P1 1 1 0" >one.pbm
2411	sam2p -transparent:ffffff one.pbm one.gif
2412	sam2p -transparent:ffffff one.pbm one.png
2413
2414Q45. Is it possible to specify a resolution other than 72 DPI, so that the
2415     dimensions of the resulting PDF are accurate for print-resolution images?
2416
2417A45. Yes, it is. Use `-m:dpi:144' to have the output EPS or PDF scaled to
2418     double size, or use `-m:dpi:<real>' to have it scaled by a factor of
2419     <real>/72, or 72/-<real>, if <real> is negative.
2420
2421     If you know that your input image resolution is <res> DPI, and you want
2422     to sam2p to create an EPS or PDF keeping the image resolution, you
2423     should use `-m:dpi:-<res>'.
2424
2425     Note that this works only for EPS and PDF output. For all other
2426     FileFormat{}s, `-m:dpi:' is ignored. The `-m:dpi:' option doesn't scale
2427     the values specified for the other `-m:...' options.
2428
2429     Some image file formats such as PNG an JPEG can contain resolution
2430     information. sam2p ignores this and assumes that the input image
2431     resolution is 72 DPI). It would be possible to improve sam2p to use
2432     this information, but it would be too much work.
2433
2434     To proper way of scaling an image, however, is
2435     using your DTP or word processor program to resize it properly. For
2436     example, after running `sam2p foo.png foo.pdf', in LaTeX, use
2437
2438        % \usepackage{graphicx}
2439        \includegraphics[height=10cm]{foo}
2440
2441Q46. Is it legal to use LZW compression?
2442
2443A46. I think so. Also look at Q17.
2444
2445Q47. Help! I cannot compile it on SunOS/Solaris. I get
2446
2447     /usr/include/sys/wait.h:90: type specifier omitted for parameter
2448     /usr/include/sys/wait.h:90: parse error before `*'
2449
2450A47. Until someone adds a test to ./configure, try adding the line
2451
2452       #define siginfo_t void
2453
2454     to the end of config2.h, just before running `make'.
2455
2456Q48. Should I run sam2p over all my EPS (or PDF) files, to see if they
2457     would become smaller?
2458
2459A48. No! This is a bad idea in general, because you lose information, since
2460     the EPS output of sam2p is always rasterized, so it is not scalable
2461     anymore.
2462
2463     But you may run sam2p over all those EPS files which contain raster
2464     graphics. But please be aware that sam2p re-renders everything at 72
2465     DPI (can be overridden by `-l:gs=-r<DPI>', and the gs rendering
2466     sometimes adjusts RGB color values slightly (+-2 on in the 0..255
2467     domain), so there might be quality loss during the _reading_ of the
2468     original EPS. There is absolutely no quality loss when sam2p _writes_
2469     the EPS.
2470
2471Q49. Should I run sam2p over all my GIF, TIFF and XPM files, to see if they
2472     would become smaller?
2473
2474A49. Yes, run `sam2p <filename> --' if you have a backup copy of the
2475     original. Otherwise, choose a different filename for output.
2476
2477Q50. Should I run sam2p over all my PNG files, to see if they
2478     would become smaller?
2479
2480A50. You might try it, there will be no quality loss, but the general
2481     experience of the author is that the tools using libpng (e.g. pnmtopng)
2482     produce slightly smaller PNG than sam2p. If you are an image
2483     compression specialist, please help the author to find the reason of
2484     this, and enhance sam2p.
2485
2486Q51. Should I run sam2p over all my JPEG files, to see if they
2487     would become smaller?
2488
2489A51. sam2p doesn't change the file by default. Use the `-c:ijg' option
2490     (possibly with a JPEG quality parameter, e.g. `-c:ijg:50') to make
2491     sam2p re-encode the JPEG. This is a lossy operation, and the size of
2492     the output file depends on quality parameter specified, so it might
2493     actually become larger than the original. Please also note that JPEG
2494     meta-information (such as EXIF tags inserted by digital cameras) gets
2495     completely lost with `-c:ijg'.
2496
2497Q52. How do I use ZIP (Deflate) compression in LanguageLevel 2?
2498
2499A52. Run this:
2500
2501	sam2p -c:zip PSL2: in.image out.eps
2502
2503     This will make sam2p emit the image decoding procedure so the image
2504     will be viewable (veeeery slowly) on LanguageLevel 2 devices, too. It
2505     doesn't affect the rendering speed on LanguageLevel 3 devices.
2506
2507Q53. How do I create a GIF from an image with more than 256 colors?
2508
2509A53. You need the pnmquant utility too from NetPbm. Run this:
2510
2511       sam2p in.image PPM:- | pnmquant 256 | sam2p - out.gif
2512
2513     Or, if you have the convert utility from ImageMagick, run:
2514
2515       sam2p in.image PPM:- | convert - out.gif
2516
2517Q54. What is the maximum image size sam2p supports?
2518
2519A54. As of version 0.45, the following limits apply for input images:
2520
2521     -- Input image height times image width must be <= 2000000000 pixels.
2522        Individual dimensions can be as high as necessary.
2523     -- Input image memory must be <= 1000000000 bytes (1 GiB). The memory is
2524        computed by multiplying image width, image height and BPC. BPC is
2525        number of bytes per pixels. It is 3 for RGB images, 1 for grayscale
2526        and indexed (256-color palette) images. For some temporary
2527        calculations BPC might go up to 3 even if it is smaller than 3 in
2528        the input image, so to be safe, always assume that BPC is 3 in image
2529        memory calculations.
2530     -- For JPEG input or ouput, image width and height must be <= 65535
2531        pixels.
2532        This is an inherent limitation in the JPEG file format.
2533
2534     In earlier versions (0.44 or below) the following additional limits
2535     applied:
2536
2537     -- Image width must be <= 65535 pixels.
2538     -- Image height must be <= 65535 pixels.
2539
2540     sam2p is a fast image conversion tool: it isn't unnecessarily slow on
2541     large images. Its speed is predictable for uncompressed images: it
2542     slows down proportionally to the input image memory (see the
2543     calculation below).
2544
2545Q55. How do I get the smallest PNG output?
2546
2547A55. If your input image is truecolor, please consider a lossy compression
2548     file format (such as JPEG), because the ZIP compression used in PNG is
2549     not particularly well-suited for truecolor images.
2550
2551     If your input image has only a few colors, specify `-c zip:25:9', which
2552     forces the ZIP compression whith a high effort (9) and predictor
2553     autodetection (25). This is considerably slower than not specifying any
2554     `-c' flag at all, and getting `-c zip:25', because the high effort (9)
2555     is slower than the default effort. Please note that `-c zip:25:9'
2556     disables the predictor unless the SampleFormat is Rgb8 or Gray8. (This
2557     is the same what libpng-1.2.15 does by default.) For large images (of
2558     Rgb{1,2,4,8} or Gray{1,2,4,8}), you may want to specify `-c zip:15:9'
2559     to forcibly enable the predictor, being autodetected for each image
2560     row.
2561
2562     Please also note that the free software ``optipng'' and the free-to-use
2563     closed-source software PNGOUT (for Win32, Linux and Mac OS X) can
2564     produce PNGs about 10% smaller than what sam2p produces -- but they are
2565     a 100 times (or even more) slower than sam2p. The tool ``pnmtopng''
2566     (tested with one linked to libpng 1.2.20) does not produce smaller PNGs
2567     than sam2p >= 0.46. For older versionf of sam2p, the output of
2568     ``pnmtopng'' was about 5--10% smaller.
2569
2570     Please also note that the the PNG output of Ghostscript -sDEVICE=pngmono
2571     etc. is not optimal. Convert it with sam2p or the tools mentioned above
2572     to reduce the file size.
2573
2574Q56. How do I get the smallest PDF output?
2575
2576A56. If your input image is truecolor, specify `-c jpeg', possibly tuning it
2577     with a low quality parameter e.g. `-c jpeg:30'.
2578
2579     If your input image has only a few colors, specify `-c zip:25:9' or
2580     `-c zip:15:9', see also Q55.
2581
2582     Please also have a look at Q55. Unfortunately, sam2p doesn't yet
2583     support calling external PNG optimizers and converting their output to
2584     PDF.
2585
2586Q57. Does sam2p convert images to canonical form, i.e. if I have two
2587     source images with identical width, height and RGB8 pixel
2588     representation, and I convert both with sam2p with the same flags,
2589     will the two output image files be byte-by-byte identical?
2590
2591A57. Yes, since version 0.46-2.
2592
2593     The only code code needed for that was sorting the indexed palette.
2594
2595     For blackbox input images which sam2p doesn't decompress (e.g. JPEG
2596     with /Compression/JAI), the output is only guaranteed to be
2597     byte-byte-byte identical, if the input was byte-byte-byte identical.
2598
2599Q58. Can sam2p generate a PDF which is scaled proportionally (i.e. keeping
2600     the aspect ratio) to a specified page size, and centered on the page?
2601
2602A58. No, but the Perl script sam2p_pdf_scale.pl bundled with sam2p can
2603     post-process the file created by sam2p. For example, to scale and
2604     center a PDF on an A4 paper, do:
2605
2606       $ sam2p input.img output.pdf
2607       $ sam2p_pdf_scale.pl 595 842 output.pdf
2608
2609     Please also have a look at the LaTeX package pdfpages.sty for more
2610     options. It can also be used to concatenate multiple PDFs.
2611     Its documentation:
2612     http://www.ctan.org/get/macros/latex/contrib/pdfpages/pdfpages.pdf
2613
2614     Example output.tex file:
2615
2616       \documentclass{article}
2617       \pdfcompresslevel9
2618       \paperwidth 21cm    \pdfpagewidth\paperwidth
2619       \paperheight29.7cm  \pdfpageheight\paperheight
2620       \usepackage{pdfpages}
2621       \begin{document}
2622       \includepdf{output_tmp.pdf}
2623       \end{document}
2624
2625     How to compile the .tex file above:
2626
2627       $ sam2p input.img output_tmp.pdf
2628       $ pdflatex output.tex
2629
2630     Please note that a2ping.pl or pdftk won't work either.
2631
2632Q59. How does sam2p detect the bounding box of PostScript and EPS input?
2633
2634A59. For PostScript input, the paper size specified in the PostScript code
2635     is used, reverting to the system's default paper size if missing.
2636     PostScript input is detected by finding `%!PS-Adobe-' at the beginning
2637     of the file, but `EPSF-' missing from the first line. Paper size can be
2638     specified in the PostScript code using `<</PageSize[...]>> setpagedevice', 'a4', `letter' etc.
2639     The comments `%%BoundingBox:' etc. are ignored.
2640
2641     For EPS input, the `%%ExactBoundingBox:' is used, reverting to
2642     `%%HiResBoundingBox:', reverting to `%%BoundingBox:', reverting to the
2643     system's default paper size. The paper size specified in the PostScript
2644     code is ignored. EPS input is detected by finding `%!PS-Adobe-' at the
2645     beginning of the file and `EPSF-' in the first line. When converting to
2646     PostScript, EPS or PDF, the (in.llx, in.lly) coordinates of the input
2647     bounding box are not preserved: the output file will always have (0, 0)
2648     as its lower left corner and (in.urx-in.llx, in.ury-in.lly) as its
2649     upper right corner.
2650
2651Q60. When compiling sam2p, the ./configure command prints an error:
2652     ``running make Makedep... error configure: error: cannot compute depends''
2653
2654A60. Please download the newest sam2p:
2655
2656         $ git clone https://github.com/pts/sam2p
2657
2658     , and run ./configure again. If it still
2659     fails, please report the issue on https://github.com/pts/sam2p/issues ,
2660     and attach the config.log file generated by ./configure to your report.
2661
2662     Some more detailed analysis: ./configure runs `make Makedep', which
2663     runs `perl -x -S ./ccdep.pl --FAL=assert,no,yes,checker g++', which
2664     runs g++ to analyze the dependencies between .cpp files, and analyzes
2665     the error and warning messages printed by g++. Newer versions of g++
2666     (and clang++, which is typically run instead of g++ on macOS) tend to
2667     print more warnings, which ccdep.pl doesn't understand, and fails.
2668
2669     Work is being done to make ccdep.pl more resilient
2670     (https://github.com/pts/sam2p/issues/5).
2671
2672Standards
2673~~~~~~~~~
2674-- PSL1 is PostScript LanguageLevel1, as defined by Adobe's PostScript
2675   Language Reference Manual.
2676-- PSLC is PSL1 with the CMYK extension (including the `colorimage'
2677   operator). Supersedes PSL1.
2678-- PSL2 is PostScript LanguageLevel2, as defined by Adobe's PostScript
2679   Language Reference Manual. Supersedes PSLC.
2680-- PSL3 is PostScript LanguageLevel3, as defined by Adobe's PostScript
2681   Language Reference Manual (PLRM.pdf). Supersedes PSL2.
2682-- PDF1.0 is PDF version 1.0, as defined by Adobe's PDF Reference.
2683-- PDF1.1 is PDF version 1.1, as defined by Adobe's PDF Reference.
2684   Supersedes PDF1.0.
2685-- PDF1.2 is PDF version 1.2, as defined by Adobe's PDF Reference.
2686   Supersedes PDF1.1.
2687-- PDF1.3 is PDF version 1.3, as defined by Adobe's PDF Reference.
2688   Supersedes PDF1.2.
2689-- PDF1.4 is PDF version 1.4, as defined by Adobe's PDF Reference
2690   (PDFRef.pdf). Supersedes PDF1.3.
2691-- PDF1.5 is PDF version 1.4, as defined by Adobe's PDF Reference
2692   (PDFRef.pdf). Supersedes PDF1.4.
2693-- PBM is Portable Bitmap file format, as defined in NetPBM's pbm(5) UNIX
2694   manual page.
2695-- PGM is Portable Graymap file format, as defined in NetPBM's pgm(5) UNIX
2696   manual page.
2697-- PPM is Portable Pixmap file format, as defined in NetPBM's ppm(5) UNIX
2698   manual page.
2699-- PNM is Portable Anymap file format, as defined in NetPBM's pnm(5) UNIX
2700   manual page. It is the union of PGM, PPM and PPM.
2701-- PAM is the new, Portable ...map file format, as defined in NetPBM's pam(5)
2702   UNIX manual page. We don't support it yet.
2703-- TIFF is ... v6.0.
2704-- JPEG is baseline JPEG JFIF file format as defined by the Joint Picture
2705   Expert Group.
2706-- PNG is Portable Network Graphics file format v1.0, as defined by
2707   RFC 2083.
2708
2709Compatibility notes
2710~~~~~~~~~~~~~~~~~~~
2711by pts@fazekas.hu at Wed Nov 14 12:14:15 CET 2001
2712Fri Mar 22 11:48:36 CET 2002
2713Sat Apr 20 19:57:44 CEST 2002
2714Fri Feb  7 11:15:39 CET 2003
2715
2716-- Ghostscript 6.50 has problems with /FileFormat/PDFB1.0
2717   /SampleFormat/JAI|/IJG/DCT
2718   (Error: /syntaxerror in ID). The problem has been fixed in Ghostscript
2719   7.04. With the buggy Ghostscript use /FileFormat/PDF1.0 instead.
2720-- /FileFormat/PDF[B]1.0 /SampleFormat/Mask|/Indexed1 doesn't
2721   work on Acrobat Reader 5.0 on Linux: a fully opaque, one-color rectangle is
2722   painted. This works fine on gs 6.50 and xpdf 1.0, so Acrobat Reader is
2723   assumed to be buggy.
2724-- The GIMP 1.0 cannot load PlanarConfig Separated TIFF images of type
2725   GrayA. (But can load PlanarConfig Contiguous GrayA.)
2726-- xv cannot display gray TIFF images with transparency.
2727   xv: Sorry, can not handle 2-channel images.
2728-- (lib)tiff FAX compression an PS /CCITTFaxEncode have black and white the
2729   opposite way. So `/CCITTFaxEncode <</BlackIs1 true>>' has to be applied
2730   when creating a TIFF file.
2731-- libtiff 3.5.4 doesn't read or write an indexed image with transparency:
2732   Sorry, can not handle contiguous data with PhotometricInterpretation=1,
2733   and Samples/pixel=2. (Doesn't work with convert or GIMP.)
2734-- libtiff 3.5.4 doesn't read or write a gray with transparency:
2735   Sorry, can not handle contiguous data with PhotometricInterpretation=2,
2736   and Samples/pixel=2. (Doesn't work with convert, works with GIMP.)
2737-- libtiff doesn't read or write TIFFTAG_SUBFILETYPE/FILETYPE_MASK +
2738   TIFFTAG_PHOTOMETRIC/PHOTOMETRIC_MASK. One has to use TIFFTAG_EXTRASAMPLES
2739   instead.
2740-- libtiff (and the TIFF file format) supports only /Predictor 1 and
2741   /Predictor 2, with /Compression/LZW and /Compression/ZIP.
2742-- libtiff supports only bpc=8 and bpc=16 with /Predictor 2
2743-- libtiff and most TIFF-handling utils have buggy support for TIFF/JPEG.
2744   See FAQ answer Q4.
2745-- libtiff supports only files with all components having the same
2746   BitsPerSample.
2747-- acroread 4.0 can display all possible /Predictor values with /Indexed1.
2748-- Ghostscript 5.50 renders (PDF?) images inaccurately: the last bit of
2749   the 8-bit palette sometimes gets wrong.
2750-- Netscape Navigator 4.7 displays transparent PNG images with their bKGD
2751   (or an arbitrary color if bKGD not present) as a solid background. This
2752   is a bug.
2753-- pdftops 0.92 has serious problems displaying images if /Predictor != 1.
2754   The image will be obscured without an error message. Ghostscript 5.50 and
2755   Acrobat Reader 4 do not have such problems.
2756-- Ghostscript 5.50 cannot display a PDF with /ColorSpace[/Indexed/DeviceRGB
2757   ...]. Acrobat Reader 4, Ghostscript 7.04 and pdftops 0.92 can.
2758-- /Decode is not required in PDF.
2759-- GIMP 1.0 completely ignores the PNG tRNS chunk! (Thus it won't recognise
2760   such a transparency in PNG.) Use `pngtopnm -alpha' instead!
2761-- pngtopnm honors the PNG bKGD chunk only if called as `pngtopnm -mix'
2762   (and does mixing)
2763-- convert honors the PNG bKGD chunk (and does mixing)
2764-- display doesn't honor the PNG bKGD chunk, but has `-bg' command line option
2765-- xv honors the PNG bKGD chunk (and does mixing)
2766-- PDF procsets (subsection 8.1 of PDFRef.pdf)
2767   /PDF
2768   /Text
2769   /ImageB Grayscale images or image masks
2770   /ImageC Color images
2771   /ImageI Indexed (color-table) images
2772-- Ghostscript always requires the /Decode entry in image dicts
2773-- /DCTEncode and /DCTDecode supports only BitsPerComponent==8.
2774-- Actually PostScript supports 1,2,4,8,12 BitsPerComponent. PDF1.3 supports
2775   only 1,2,4,8. We support only 1, 2, 4 and 8.
2776-- PostScript also supports the CMYK color space, not just gray and RGB.
2777   (And also the HSB, which can be transformed to RGB in an ugly way.)
2778-- PostScript supports PNG predictors to enhance compression.
2779-- The PLRM 4.10.6 describes a trick with patterns and imagemask to do
2780   transparent images. Unfortunately this doesn't work in Ghostscript 5.50
2781   and xpdf 0.92 (but it works in acroread 4.0), so we don't use it. That's
2782   why we have only two *-transparent-* entries.
2783-- ImageMagick EPSI is an EPS with preview (%%BeginPreview .. %%EndPreview)
2784-- ImageMagick EPSF and EPS are equivalent
2785-- ImageMagick EPS* is incredibly slooow because of the bad design, even for
2786   LanguageLevel 2.
2787-- ImageMagick EPS* cannot display color images without the colorimage
2788   opertor. (We could do some trickery with multiple calls to imagemask.)
2789-- tiff2ps cannot display color images without the colorimage
2790   opertor. (We could do some trickery with multiple calls to imagemask.)
2791-- Timing: 1495 x 935 RGB, gs -sDEVICE=bmp16m -sOutputFile=/dev/null
2792   time gs -q -sDEVICE=ppmraw -sOutputFile=t.ppm $IN.eps </dev/null
2793   ImageMagick 6620 ms user
2794   tiff2ps-readhexstring 2320 ms user
2795   currentfile-colorimage 2120 ms user
2796   readstring-colorimage 2170 ms user
2797   currentfile-/FlateDecode-colorimage 2670 ms user
2798-- There is a NullEncode filter, but NullDecode doesn't exist
2799-- speed conclusions:
2800   1. Use currentfile as data source (LanguageLevel2) if possible.
2801   2. /FlateDecode adds a 25% speed penalty. But it compresses quite well,
2802      so use it!
2803-- PostScript LanguageLevel2 supports the indexed color space:
2804
2805	/colormap colors 3 mul string def
2806	currentfile colormap readhexstring pop pop
2807	[ /Indexed /DeviceRGB colors 1 sub colormap ] setcolorspace
2808
2809-- EPS comments: (ImageMagick)
2810
2811	%%DocumentData: Clean7Bit
2812	%%LanguageLevel: 1
2813
2814-- PSL1/PSL2 supports the following color setting operators: (all operands
2815   are between 0.0 and 1.0)
2816
2817	<num> setgray  currentgray % PSL1, 0.0=black 1.0=white
2818	<hue> <saturation> <brightness> sethsbcolor % PSL1
2819	<red> <green> <blue> setrgbcolor % PSL1
2820	<cyan> <magenta> <yellow> <black> setcmykcolor % PSL2; not in PSL1
2821
2822__END__
2823