1Pnmtojpeg User Manual(0) Pnmtojpeg User Manual(0)
2
3
4
6 pnmtojpeg - convert PNM image to a JFIF ("JPEG") image
7
8
10 pnmtojpeg [-exif=filespec] [-quality=n] [{-grayscale|-greyscale}]
11 [-density=nxn[dpi,dpcm]] [-optimize|-optimise] [-rgb] [-progressive]
12 [-comment=text] [-dct={int|fast|float}] [-arithmetic] [-restart=n]
13 [-smooth=n] [-maxmemory=n] [-verbose] [-baseline] [-qtables=filespec]
14 [-qslots=n[,...]] [-sample=HxV[,...]] [-scans=filespec]
15 [-tracelevel=N]
16
17 filename
18
19 Minimum unique abbreviation of option is acceptable. You may use dou‐
20 ble hyphens instead of single hyphen to denote options. You may use
21 white space in place of the equals sign to separate an option name from
22 its value.
23
24
25
27 This program is part of Netpbm(1).
28
29 pnmtojpeg converts the named PBM, PGM, or PPM image file, or the stan‐
30 dard input if no file is named, to a JFIF file on the standard output.
31
32 pnmtojpeg uses the Independent JPEG Group's JPEG library to create the
33 output file. See http://www.ijg.org ⟨http://www.ijg.org⟩ for infor‐
34 mation on the library.
35
36 "JFIF" is the correct name for the image format commonly known as
37 "JPEG." Strictly speaking, JPEG is a method of compression. The image
38 format using JPEG compression that is by far the most common is JFIF.
39 There is also a subformat of TIFF that uses JPEG compression.
40
41 EXIF is an image format that is a subformat of JFIF (to wit, a JFIF
42 file that contains an EXIF header as an APP1 marker). pnmtojpeg cre‐
43 ates an EXIF image when you specify the -exif option.
44
45
47 The basic options are:
48
49
50
51 -exif=filespec
52 This option specifies that the output image is to be EXIF (a
53 subformat of JFIF), i.e. it will have an EXIF header as a JFIF
54 APP1 marker. The contents of that marker are the contents of
55 the specified file. The special value - means to read the EXIF
56 header contents from standard input. It is invalid to specify
57 standard input for both the EXIF header and the input image.
58
59 The EXIF file starts with a two byte field which is the length
60 of the file, including the length field, in pure binary, most
61 significant byte first. The special value of zero for the
62 length field means there is to be no EXIF header, i.e. the same
63 as no -exif option. This is useful for when you convert a file
64 from JFIF to PNM using jpegtopnm, then transform it, then con‐
65 vert it back to JFIF with pnmtojpeg, and you don't know whether
66 or not it includes an EXIF header. jpegtopnm creates an EXIF
67 file containing nothing but two bytes of zero when the input
68 JFIF file has no EXIF header. Thus, you can transfer any EXIF
69 header from the input JFIF to the output JFIF without worrying
70 about whether an EXIF header actually exists.
71
72 The contents of the EXIF file after the length field are the
73 exact byte for byte contents of the APP1 marker, not counting
74 the length field, that constitutes the EXIF header.
75
76
77 -quality=n
78 Scale quantization tables to adjust image quality. n is 0
79 (worst) to 100 (best); default is 75. Below about 25 can pro‐
80 duce images some interpreters won't be able to interpret. See
81 below for more info.
82
83
84 -grayscale
85
86 -greyscale
87
88 -rgb These options determine the color space used in the JFIF output.
89 -grayscale (or -greyscale) means to create a gray scale JFIF,
90 converting from color PPM input if necessary. -rgb means to
91 create an RGB JFIF, and the program fails if the input is not
92 PPM.
93
94 If you specify neither, The output file is in YCbCr format if
95 the input is PPM, and grayscale format if the input is PBM or
96 PGM.
97
98 YCbCr format (a color is represented by an intensity value and
99 two chrominance values) usually compresses much better than RGB
100 (a color is represented by one red, one green, and one blue
101 value). RGB is rare. But you may be able to convert between
102 JFIF and PPM faster with RGB, since it's the same color space
103 PPM uses.
104
105 The testimg.ppm file that comes with Netpbm is 2.3 times larger
106 with the -rgb option than with the YCbCr default, and in one
107 experiment pnmtojpeg took 16% more CPU time to convert it. The
108 extra CPU time probably indicates that processing of all the
109 extra compressed data consumed all the CPU time saved by not
110 having to convert the RGB inputs to YCbCr.
111
112 Grayscale format takes up a lot less space and takes less time
113 to create and process than the color formats, even if the image
114 contains nothing but black, white, and gray.
115
116 The -rgb option was added in Netpbm 10.11 in October 2002.
117
118
119 -density=density
120 This option determines the density (aka resolution) information
121 recorded in the JFIF output image. It does not affect the
122 raster in any way; it just tells whoever reads the JFIF how to
123 interpret the raster.
124
125 The density value takes the form xxy followed by an optional
126 unit specifier of dpi or dpcm. Examples: 1x1, 3x2, 300x300dpi,
127 100x200dpcm. The first number is the horizontal density; the
128 2nd number is the vertical density. Each may be any integer
129 from 1 to 65535. The unit specifier is dpi for dots per inch or
130 dpcm for dots per centimeter. If you don't specify the units,
131 the density information goes into the JFIF explicitly stating
132 "density unspecified" (also interpreted as "unknown"). This may
133 seem pointless, but note that even without specifying the units,
134 the density numbers tell the aspect ratio of the pixels. E.g.
135 1x1 tells you the pixels are square. 3x2 tells you the pixels
136 are vertical rectangles.
137
138 Note that if you specify different horizontal and vertical den‐
139 sities, the resulting JFIF image is not a true representation of
140 the input PNM image, because pnmtojpeg converts the raster
141 pixel-for-pixel and the pixels of a PNM image are defined to be
142 square. Thus, if you start with a square PNM image and specify
143 -density=3x2, the resulting JFIF image is a horizontally
144 squashed version of the original. However, it is common to use
145 an input image which is a slight variation on PNM rather than
146 true PNM such that the pixels are not square. In that case, the
147 appropriate -density option yields a faithful reproduction of
148 the input pseudo-PNM image.
149
150 The default is 1x1 in unspecified units.
151
152 Before Netpbm 10.15 (April 2003), this option did not exist and
153 the pnmtojpeg always created a JFIF with a density of 1x1 in
154 unspecified units.
155
156
157 -optimize
158 Perform optimization of entropy encoding parameters. Without
159 this, pnmtojpeg uses default encoding parameters. -optimize
160 usually makes the JFIF file a little smaller, but pnmtojpeg runs
161 somewhat slower and needs much more memory. Image quality and
162 speed of decompression are unaffected by -optimize.
163
164
165 -progressive
166 Create a progressive JPEG file (see below).
167
168 -comment=text
169 Include a comment marker in the JFIF output, with comment text
170 text.
171
172 Without this option, there are no comment markers in the output.
173
174
175
176 The -quality option lets you trade off compressed file size against
177 quality of the reconstructed image: the higher the quality setting, the
178 larger the JFIF file, and the closer the output image will be to the
179 original input. Normally you want to use the lowest quality setting
180 (smallest file) that decompresses into something visually indistin‐
181 guishable from the original image. For this purpose the quality set‐
182 ting should be between 50 and 95 for reasonable results; the default of
183 75 is often about right. If you see defects at -quality=75, then go up
184 5 or 10 counts at a time until you are happy with the output image.
185 (The optimal setting will vary from one image to another.)
186
187 -quality=100 generates a quantization table of all 1's, minimizing loss
188 in the quantization step (but there is still information loss in sub‐
189 sampling, as well as roundoff error). This setting is mainly of inter‐
190 est for experimental purposes. Quality values above about 95 are not
191 recommended for normal use; the compressed file size goes up dramati‐
192 cally for hardly any gain in output image quality.
193
194 In the other direction, quality values below 50 will produce very small
195 files of low image quality. Settings around 5 to 10 might be useful in
196 preparing an index of a large image library, for example. Try -qual‐
197 ity=2 (or so) for some amusing Cubist effects. (Note: quality values
198 below about 25 generate 2-byte quantization tables, which are consid‐
199 ered optional in the JFIF standard. pnmtojpeg emits a warning message
200 when you give such a quality value, because some other JFIF programs
201 may be unable to decode the resulting file. Use -baseline if you need
202 to ensure compatibility at low quality values.)
203
204 The -progressive option creates a "progressive JPEG" file. In this
205 type of JFIF file, the data is stored in multiple scans of increasing
206 quality. If the file is being transmitted over a slow communications
207 link, the decoder can use the first scan to display a low-quality image
208 very quickly, and can then improve the display with each subsequent
209 scan. The final image is exactly equivalent to a standard JFIF file of
210 the same quality setting, and the total file size is about the same --
211 often a little smaller.
212
213 Caution: progressive JPEG is not yet widely implemented, so many
214 decoders will be unable to view a progressive JPEG file at all.
215
216 If you're trying to control the quality/file size tradeoff, you might
217 consider the JPEG2000 format instead. See pamtojpeg2k(1).
218
219 Options for advanced users:
220
221
222
223 -dct=int
224 Use integer DCT method (default).
225
226
227 -dct=fast
228 Use fast integer DCT (less accurate).
229
230
231 -dct=float
232 Use floating-point DCT method. The float method is very
233 slightly more accurate than the int method, but is much slower
234 unless your machine has very fast floating-point hardware. Also
235 note that results of the floating-point method may vary slightly
236 across machines, while the integer methods should give the same
237 results everywhere. The fast integer method is much less accu‐
238 rate than the other two.
239
240
241 -arithmetic
242 Use arithmetic coding. Default is Huffman encoding. Arithmetic
243 coding tends to get you a smaller result.
244
245 You may need patent licenses to use this option. According to
246 the JPEG FAQ ⟨http://www.faqs.org/faqs/jpeg-faq⟩ , This method
247 is covered by patents owned by IBM, AT&T, and Mitsubishi.
248
249 The author of the FAQ recommends against using arithmetic coding
250 (and therefore this option) because the space savings is not
251 great enough to justify the legal hassles.
252
253 Most JPEG libraries, including any distributed by the Indepen‐
254 dent JPEG Group since about 1998 are not capable of arithmetic
255 encoding. pnmtojpeg uses a JPEG library (either bound to it
256 when the pnmtojpeg executable was built or accessed on your sys‐
257 tem at run time) to do the JPEG encoding. If pnmtojpeg termi‐
258 nates with the message, "Sorry, there are legal restrictions on
259 arithmetic coding" or "Sorry, arithmetic coding not supported,"
260 this is the problem.
261
262
263 -restart=n
264 Emit a JPEG restart marker every n MCU rows, or every n MCU
265 blocks if you append B to the number. -restart 0 (the default)
266 means no restart markers.
267
268
269 -smooth=n
270 Smooth the input image to eliminate dithering noise. n, ranging
271 from 1 to 100, indicates the strength of smoothing. 0 (the
272 default) means no smoothing.
273
274
275 -maxmemory=n
276 Set a limit for amount of memory to use in processing large
277 images. Value is in thousands of bytes, or millions of bytes if
278 you append M to the number. For example, -max=4m selects
279 4,000,000 bytes. If pnmtojpeg needs more space, it will use
280 temporary files.
281
282
283 -verbose
284 Print to the Standard Error file messages about the conversion
285 process. This can be helpful in debugging problems.
286
287
288 The -restart option tells pnmtojpeg to insert extra markers that allow
289 a JPEG decoder to resynchronize after a transmission error. Without
290 restart markers, any damage to a compressed file will usually ruin the
291 image from the point of the error to the end of the image; with restart
292 markers, the damage is usually confined to the portion of the image up
293 to the next restart marker. Of course, the restart markers occupy
294 extra space. We recommend -restart=1 for images that will be transmit‐
295 ted across unreliable networks such as Usenet.
296
297 The -smooth option filters the input to eliminate fine-scale noise.
298 This is often useful when converting dithered images to JFIF: a moder‐
299 ate smoothing factor of 10 to 50 gets rid of dithering patterns in the
300 input file, resulting in a smaller JFIF file and a better-looking
301 image. Too large a smoothing factor will visibly blur the image, how‐
302 ever.
303
304 Options for wizards:
305
306
307
308 -baseline
309 Force baseline-compatible quantization tables to be generated.
310 This clamps quantization values to 8 bits even at low quality
311 settings. (This switch is poorly named, since it does not
312 ensure that the output is actually baseline JPEG. For example,
313 you can use -baseline and -progressive together.)
314
315
316 -qtables=filespec
317 Use the quantization tables given in the specified text file.
318
319
320 -qslots=n[,...]
321 Select which quantization table to use for each color component.
322
323
324 -sample=HxV[,...]
325 Set JPEG sampling factors for each color component.
326
327
328 -scans=filespec
329 Use the scan script given in the specified text file. See below
330 for information on scan scripts.
331
332
333 -tracelevel=N
334 This sets the level of debug tracing the program outputs as it
335 runs. 0 means none, and is the default. This level primarily
336 controls tracing of the JPEG library, and you can get some
337 pretty interesting information about the compression process.
338
339
340
341 The "wizard" options are intended for experimentation with JPEG. If
342 you don't know what you are doing, don't use them. These switches are
343 documented further in the file wizard.doc that comes with the Indepen‐
344 dent JPEG Group's JPEG library.
345
346
348 This example compresses the PPM file foo.ppm with a quality factor of
349 60 and saves the output as foo.jpg:
350
351 pnmtojpeg -quality=60 foo.ppm > foo.jpg
352
353 Here's a more typical example. It converts from BMP to JFIF:
354
355 cat foo.bmp | bmptoppm | pnmtojpeg > foo.jpg
356
357
359 When you compress with JPEG, you lose information -- i.e. the resulting
360 image has somewhat lower quality than the original. This is a charac‐
361 teristic of JPEG itself, not any particular program. So if you do the
362 usual Netpbm thing and convert from JFIF to PNM, manipulate, then con‐
363 vert back to JFIF, you will lose quality. The more you do it, the more
364 you lose. Drawings (charts, cartoons, line drawings, and such with few
365 colors and sharp edges) suffer the most.
366
367 To avoid this, you can use a compressed image format other than JPEG.
368 PNG and JPEG2000 are good choices, and Netpbm contains converters for
369 those.
370
371 If you need to use JFIF on a drawing, you should experiment with pnmto‐
372 jpeg's -quality and -smooth options to get a satisfactory conversion.
373 -smooth 10 or so is often helpful.
374
375 Because of the loss, you should do all the manipulation you have to do
376 on the image in some other format and convert to JFIF as the last step.
377 And if you can keep a copy in the original format, so much the better.
378
379 The -optimize option to pnmtojpeg is worth using when you are making a
380 "final" version for posting or archiving. It's also a win when you are
381 using low quality settings to make very small JFIF files; the percent‐
382 age improvement is often a lot more than it is on larger files. (At
383 present, -optimize mode is automatically in effect when you generate a
384 progressive JPEG file).
385
386 You can do flipping and rotating transformations losslessly with the
387 program jpegtran, which is packaged with the Independent Jpeg Group's
388 JPEG library. jpegtran exercises its intimate knowledge of the way
389 JPEG works to do the transformation without ever actually decompressing
390 the image.
391
392
393
394
395 Another program, cjpeg, is similar. cjpeg is
396 maintained by the Independent JPEG Group and packaged with the JPEG
397 library which pnmtojpeg uses for all its JPEG work. Because of that,
398 you may expect it to exploit more current JPEG features. Also, since
399 you have to have the library to run pnmtojpeg, but not vice versa,
400 cjpeg may be more commonly available.
401
402 On the other hand, cjpeg does not use the NetPBM libraries to process
403 its input, as all the NetPBM tools such as pnmtojpeg do. This means it
404 is less likely to be consistent with all the other programs that deal
405 with the NetPBM formats. Also, the command syntax of pnmtojpeg is con‐
406 sistent with that of the other Netpbm tools, unlike cjpeg.
407
408
410 Use the -scan option to specify a scan script. Or use the -progressive
411 option to specify a particular built-in scan script.
412
413 Just what a scan script is, and the basic format of the scan script
414 file, is covered in the wizard.doc file that comes with the Independent
415 JPEG Group's JPEG library. Scan scripts are same for pnmtojpeg as the
416 are for cjpeg.
417
418 This section contains additional information that isn't, but probably
419 should be, in that document.
420
421 First, there are many restrictions on what is a valid scan script. The
422 JPEG library, and thus pnmtojpeg, checks thoroughly for any lack of
423 compliance with these restrictions, but does little to tell you how the
424 script fails to comply. The messages are very general and sometimes
425 untrue.
426
427 To start with, the entries for the DC coefficient must come before any
428 entries for the AC coefficients. The DC coefficient is Coefficient 0;
429 all the other coefficients are AC coefficients. So in an entry for the
430 DC coefficient, the two numbers after the colon must be 0 and 0. In an
431 entry for AC coefficients, the first number after the colon must not be
432 0.
433
434 In a DC entry, the color components must be in increasing order. E.g.
435 "0,2,1" before the colon is wrong. So is "0,0,0".
436
437 In an entry for an AC coefficient, you must specify only one color com‐
438 ponent. I.e. there can be only one number before the colon.
439
440 In the first entry for a particular coefficient for a particular color
441 component, the "Ah" value must be zero, but the Al value can be any
442 valid bit number. In subsequent entries, Ah must be the Al value from
443 the previous entry (for that coefficient for that color component), and
444 the Al value must be one less than the Ah value.
445
446 The script must ultimately specify at least some of the DC coefficient
447 for every color component. Otherwise, you get the error message
448 "Script does not transmit all the data." You need not specify all of
449 the bits of the DC coefficient, or any of the AC coefficients.
450
451 There is a standard option in building the JPEG library to omit scan
452 script capability. If for some reason your library was built with this
453 option, you get the message "Requested feature was omitted at compile
454 time."
455
456
458 JPEGMEM
459 If this environment variable is set, its value is the default
460 memory limit. The value is specified as described for the
461 -maxmemory option. An explicit -maxmemory option overrides any
462 JPEGMEM.
463
464
465
466
468 jpegtopnm(1), pnm(1), cjpeg man page, djpeg man page, jpegtran man
469 page, rdjpgcom man page, wrjpgcom man page
470
471 Wallace, Gregory K. "The JPEG Still Picture Compression Standard",
472 Communications of the ACM, April 1991 (vol. 34, no. 4), pp. 30-44.
473
474
475
477 pnmtojpeg and this manual were derived in large part from cjpeg, by the
478 Independent JPEG Group. The program is otherwise by Bryan Henderson on
479 March 07, 2000.
480
482 This manual page was generated by the Netpbm tool 'makeman' from HTML
483 source. The master documentation is at
484
485 http://netpbm.sourceforge.net/doc/pnmtojpeg.html
486
487netpbm documentation 23 April 2007 Pnmtojpeg User Manual(0)