usage.txt 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. NOTE: This file was modified by The libjpeg-turbo Project to include only
  2. information relevant to libjpeg-turbo and to wordsmith certain sections.
  3. USAGE instructions for the Independent JPEG Group's JPEG software
  4. =================================================================
  5. This file describes usage of the JPEG conversion programs cjpeg and djpeg,
  6. as well as the utility programs jpegtran, rdjpgcom and wrjpgcom. (See
  7. the other documentation files if you wish to use the JPEG library within
  8. your own programs.)
  9. If you are on a Unix machine you may prefer to read the Unix-style manual
  10. pages in files cjpeg.1, djpeg.1, jpegtran.1, rdjpgcom.1, wrjpgcom.1.
  11. INTRODUCTION
  12. These programs implement JPEG image encoding, decoding, and transcoding.
  13. JPEG (pronounced "jay-peg") is a standardized compression method for
  14. full-color and grayscale images.
  15. GENERAL USAGE
  16. We provide two programs, cjpeg to compress an image file into JPEG format,
  17. and djpeg to decompress a JPEG file back into a conventional image format.
  18. On Unix-like systems, you say:
  19. cjpeg [switches] [imagefile] >jpegfile
  20. or
  21. djpeg [switches] [jpegfile] >imagefile
  22. The programs read the specified input file, or standard input if none is
  23. named. They always write to standard output (with trace/error messages to
  24. standard error). These conventions are handy for piping images between
  25. programs.
  26. On most non-Unix systems, you say:
  27. cjpeg [switches] imagefile jpegfile
  28. or
  29. djpeg [switches] jpegfile imagefile
  30. i.e., both the input and output files are named on the command line. This
  31. style is a little more foolproof, and it loses no functionality if you don't
  32. have pipes. (You can get this style on Unix too, if you prefer, by defining
  33. TWO_FILE_COMMANDLINE when you compile the programs; see install.txt.)
  34. You can also say:
  35. cjpeg [switches] -outfile jpegfile imagefile
  36. or
  37. djpeg [switches] -outfile imagefile jpegfile
  38. This syntax works on all systems, so it is useful for scripts.
  39. The currently supported image file formats are: PPM (PBMPLUS color format),
  40. PGM (PBMPLUS grayscale format), BMP, Targa, and RLE (Utah Raster Toolkit
  41. format). (RLE is supported only if the URT library is available, which it
  42. isn't on most non-Unix systems.) cjpeg recognizes the input image format
  43. automatically, with the exception of some Targa files. You have to tell djpeg
  44. which format to generate.
  45. JPEG files are in the defacto standard JFIF file format. There are other,
  46. less widely used JPEG-based file formats, but we don't support them.
  47. All switch names may be abbreviated; for example, -grayscale may be written
  48. -gray or -gr. Most of the "basic" switches can be abbreviated to as little as
  49. one letter. Upper and lower case are equivalent (-BMP is the same as -bmp).
  50. British spellings are also accepted (e.g., -greyscale), though for brevity
  51. these are not mentioned below.
  52. CJPEG DETAILS
  53. The basic command line switches for cjpeg are:
  54. -quality N[,...] Scale quantization tables to adjust image quality.
  55. Quality is 0 (worst) to 100 (best); default is 75.
  56. (See below for more info.)
  57. -grayscale Create monochrome JPEG file from color input.
  58. Be sure to use this switch when compressing a grayscale
  59. BMP file, because cjpeg isn't bright enough to notice
  60. whether a BMP file uses only shades of gray. By
  61. saying -grayscale, you'll get a smaller JPEG file that
  62. takes less time to process.
  63. -rgb Create RGB JPEG file.
  64. Using this switch suppresses the conversion from RGB
  65. colorspace input to the default YCbCr JPEG colorspace.
  66. -optimize Perform optimization of entropy encoding parameters.
  67. Without this, default encoding parameters are used.
  68. -optimize usually makes the JPEG file a little smaller,
  69. but cjpeg runs somewhat slower and needs much more
  70. memory. Image quality and speed of decompression are
  71. unaffected by -optimize.
  72. -progressive Create progressive JPEG file (see below).
  73. -targa Input file is Targa format. Targa files that contain
  74. an "identification" field will not be automatically
  75. recognized by cjpeg; for such files you must specify
  76. -targa to make cjpeg treat the input as Targa format.
  77. For most Targa files, you won't need this switch.
  78. The -quality switch lets you trade off compressed file size against quality of
  79. the reconstructed image: the higher the quality setting, the larger the JPEG
  80. file, and the closer the output image will be to the original input. Normally
  81. you want to use the lowest quality setting (smallest file) that decompresses
  82. into something visually indistinguishable from the original image. For this
  83. purpose the quality setting should generally be between 50 and 95 (the default
  84. is 75) for photographic images. If you see defects at -quality 75, then go up
  85. 5 or 10 counts at a time until you are happy with the output image. (The
  86. optimal setting will vary from one image to another.)
  87. -quality 100 will generate a quantization table of all 1's, minimizing loss
  88. in the quantization step (but there is still information loss in subsampling,
  89. as well as roundoff error.) For most images, specifying a quality value above
  90. about 95 will increase the size of the compressed file dramatically, and while
  91. the quality gain from these higher quality values is measurable (using metrics
  92. such as PSNR or SSIM), it is rarely perceivable by human vision.
  93. In the other direction, quality values below 50 will produce very small files
  94. of low image quality. Settings around 5 to 10 might be useful in preparing an
  95. index of a large image library, for example. Try -quality 2 (or so) for some
  96. amusing Cubist effects. (Note: quality values below about 25 generate 2-byte
  97. quantization tables, which are considered optional in the JPEG standard.
  98. cjpeg emits a warning message when you give such a quality value, because some
  99. other JPEG programs may be unable to decode the resulting file. Use -baseline
  100. if you need to ensure compatibility at low quality values.)
  101. The -quality option has been extended in this version of cjpeg to support
  102. separate quality settings for luminance and chrominance (or, in general,
  103. separate settings for every quantization table slot.) The principle is the
  104. same as chrominance subsampling: since the human eye is more sensitive to
  105. spatial changes in brightness than spatial changes in color, the chrominance
  106. components can be quantized more than the luminance components without
  107. incurring any visible image quality loss. However, unlike subsampling, this
  108. feature reduces data in the frequency domain instead of the spatial domain,
  109. which allows for more fine-grained control. This option is useful in
  110. quality-sensitive applications, for which the artifacts generated by
  111. subsampling may be unacceptable.
  112. The -quality option accepts a comma-separated list of parameters, which
  113. respectively refer to the quality levels that should be assigned to the
  114. quantization table slots. If there are more q-table slots than parameters,
  115. then the last parameter is replicated. Thus, if only one quality parameter is
  116. given, this is used for both luminance and chrominance (slots 0 and 1,
  117. respectively), preserving the legacy behavior of cjpeg v6b and prior. More (or
  118. customized) quantization tables can be set with the -qtables option and
  119. assigned to components with the -qslots option (see the "wizard" switches
  120. below.)
  121. JPEG files generated with separate luminance and chrominance quality are
  122. fully compliant with standard JPEG decoders.
  123. CAUTION: For this setting to be useful, be sure to pass an argument of
  124. -sample 1x1 to cjpeg to disable chrominance subsampling. Otherwise, the
  125. default subsampling level (2x2, AKA "4:2:0") will be used.
  126. The -progressive switch creates a "progressive JPEG" file. In this type of
  127. JPEG file, the data is stored in multiple scans of increasing quality. If the
  128. file is being transmitted over a slow communications link, the decoder can use
  129. the first scan to display a low-quality image very quickly, and can then
  130. improve the display with each subsequent scan. The final image is exactly
  131. equivalent to a standard JPEG file of the same quality setting, and the total
  132. file size is about the same --- often a little smaller.
  133. Switches for advanced users:
  134. -arithmetic Use arithmetic coding. CAUTION: arithmetic coded JPEG
  135. is not yet widely implemented, so many decoders will
  136. be unable to view an arithmetic coded JPEG file at
  137. all.
  138. -dct int Use integer DCT method (default).
  139. -dct fast Use fast integer DCT (less accurate).
  140. In libjpeg-turbo, the fast method is generally about
  141. 5-15% faster than the int method when using the
  142. x86/x86-64 SIMD extensions (results may vary with other
  143. SIMD implementations, or when using libjpeg-turbo
  144. without SIMD extensions.) For quality levels of 90 and
  145. below, there should be little or no perceptible
  146. difference between the two algorithms. For quality
  147. levels above 90, however, the difference between
  148. the fast and the int methods becomes more pronounced.
  149. With quality=97, for instance, the fast method incurs
  150. generally about a 1-3 dB loss (in PSNR) relative to
  151. the int method, but this can be larger for some images.
  152. Do not use the fast method with quality levels above
  153. 97. The algorithm often degenerates at quality=98 and
  154. above and can actually produce a more lossy image than
  155. if lower quality levels had been used. Also, in
  156. libjpeg-turbo, the fast method is not fully accerated
  157. for quality levels above 97, so it will be slower than
  158. the int method.
  159. -dct float Use floating-point DCT method.
  160. The float method is mainly a legacy feature. It does
  161. not produce significantly more accurate results than
  162. the int method, and it is much slower. The float
  163. method may also give different results on different
  164. machines due to varying roundoff behavior, whereas the
  165. integer methods should give the same results on all
  166. machines.
  167. -restart N Emit a JPEG restart marker every N MCU rows, or every
  168. N MCU blocks if "B" is attached to the number.
  169. -restart 0 (the default) means no restart markers.
  170. -smooth N Smooth the input image to eliminate dithering noise.
  171. N, ranging from 1 to 100, indicates the strength of
  172. smoothing. 0 (the default) means no smoothing.
  173. -maxmemory N Set limit for amount of memory to use in processing
  174. large images. Value is in thousands of bytes, or
  175. millions of bytes if "M" is attached to the number.
  176. For example, -max 4m selects 4000000 bytes. If more
  177. space is needed, temporary files will be used.
  178. -verbose Enable debug printout. More -v's give more printout.
  179. or -debug Also, version information is printed at startup.
  180. The -restart option inserts extra markers that allow a JPEG decoder to
  181. resynchronize after a transmission error. Without restart markers, any damage
  182. to a compressed file will usually ruin the image from the point of the error
  183. to the end of the image; with restart markers, the damage is usually confined
  184. to the portion of the image up to the next restart marker. Of course, the
  185. restart markers occupy extra space. We recommend -restart 1 for images that
  186. will be transmitted across unreliable networks such as Usenet.
  187. The -smooth option filters the input to eliminate fine-scale noise. This is
  188. often useful when converting dithered images to JPEG: a moderate smoothing
  189. factor of 10 to 50 gets rid of dithering patterns in the input file, resulting
  190. in a smaller JPEG file and a better-looking image. Too large a smoothing
  191. factor will visibly blur the image, however.
  192. Switches for wizards:
  193. -baseline Force baseline-compatible quantization tables to be
  194. generated. This clamps quantization values to 8 bits
  195. even at low quality settings. (This switch is poorly
  196. named, since it does not ensure that the output is
  197. actually baseline JPEG. For example, you can use
  198. -baseline and -progressive together.)
  199. -qtables file Use the quantization tables given in the specified
  200. text file.
  201. -qslots N[,...] Select which quantization table to use for each color
  202. component.
  203. -sample HxV[,...] Set JPEG sampling factors for each color component.
  204. -scans file Use the scan script given in the specified text file.
  205. The "wizard" switches are intended for experimentation with JPEG. If you
  206. don't know what you are doing, DON'T USE THEM. These switches are documented
  207. further in the file wizard.txt.
  208. DJPEG DETAILS
  209. The basic command line switches for djpeg are:
  210. -colors N Reduce image to at most N colors. This reduces the
  211. or -quantize N number of colors used in the output image, so that it
  212. can be displayed on a colormapped display or stored in
  213. a colormapped file format. For example, if you have
  214. an 8-bit display, you'd need to reduce to 256 or fewer
  215. colors. (-colors is the recommended name, -quantize
  216. is provided only for backwards compatibility.)
  217. -fast Select recommended processing options for fast, low
  218. quality output. (The default options are chosen for
  219. highest quality output.) Currently, this is equivalent
  220. to "-dct fast -nosmooth -onepass -dither ordered".
  221. -grayscale Force grayscale output even if JPEG file is color.
  222. Useful for viewing on monochrome displays; also,
  223. djpeg runs noticeably faster in this mode.
  224. -rgb Force RGB output even if JPEG file is grayscale.
  225. -scale M/N Scale the output image by a factor M/N. Currently
  226. the scale factor must be M/8, where M is an integer
  227. between 1 and 16 inclusive, or any reduced fraction
  228. thereof (such as 1/2, 3/4, etc. Scaling is handy if
  229. the image is larger than your screen; also, djpeg runs
  230. much faster when scaling down the output.
  231. -bmp Select BMP output format (Windows flavor). 8-bit
  232. colormapped format is emitted if -colors or -grayscale
  233. is specified, or if the JPEG file is grayscale;
  234. otherwise, 24-bit full-color format is emitted.
  235. -gif Select GIF output format. Since GIF does not support
  236. more than 256 colors, -colors 256 is assumed (unless
  237. you specify a smaller number of colors). If you
  238. specify -fast, the default number of colors is 216.
  239. -os2 Select BMP output format (OS/2 1.x flavor). 8-bit
  240. colormapped format is emitted if -colors or -grayscale
  241. is specified, or if the JPEG file is grayscale;
  242. otherwise, 24-bit full-color format is emitted.
  243. -pnm Select PBMPLUS (PPM/PGM) output format (this is the
  244. default format). PGM is emitted if the JPEG file is
  245. grayscale or if -grayscale is specified; otherwise
  246. PPM is emitted.
  247. -rle Select RLE output format. (Requires URT library.)
  248. -targa Select Targa output format. Grayscale format is
  249. emitted if the JPEG file is grayscale or if
  250. -grayscale is specified; otherwise, colormapped format
  251. is emitted if -colors is specified; otherwise, 24-bit
  252. full-color format is emitted.
  253. Switches for advanced users:
  254. -dct int Use integer DCT method (default).
  255. -dct fast Use fast integer DCT (less accurate).
  256. In libjpeg-turbo, the fast method is generally about
  257. 5-15% faster than the int method when using the
  258. x86/x86-64 SIMD extensions (results may vary with other
  259. SIMD implementations, or when using libjpeg-turbo
  260. without SIMD extensions.) If the JPEG image was
  261. compressed using a quality level of 85 or below, then
  262. there should be little or no perceptible difference
  263. between the two algorithms. When decompressing images
  264. that were compressed using quality levels above 85,
  265. however, the difference between the fast and int
  266. methods becomes more pronounced. With images
  267. compressed using quality=97, for instance, the fast
  268. method incurs generally about a 4-6 dB loss (in PSNR)
  269. relative to the int method, but this can be larger for
  270. some images. If you can avoid it, do not use the fast
  271. method when decompressing images that were compressed
  272. using quality levels above 97. The algorithm often
  273. degenerates for such images and can actually produce
  274. a more lossy output image than if the JPEG image had
  275. been compressed using lower quality levels.
  276. -dct float Use floating-point DCT method.
  277. The float method is mainly a legacy feature. It does
  278.   not produce significantly more accurate results than
  279. the int method, and it is much slower. The float
  280. method may also give different results on different
  281. machines due to varying roundoff behavior, whereas the
  282. integer methods should give the same results on all
  283. machines.
  284. -dither fs Use Floyd-Steinberg dithering in color quantization.
  285. -dither ordered Use ordered dithering in color quantization.
  286. -dither none Do not use dithering in color quantization.
  287. By default, Floyd-Steinberg dithering is applied when
  288. quantizing colors; this is slow but usually produces
  289. the best results. Ordered dither is a compromise
  290. between speed and quality; no dithering is fast but
  291. usually looks awful. Note that these switches have
  292. no effect unless color quantization is being done.
  293. Ordered dither is only available in -onepass mode.
  294. -map FILE Quantize to the colors used in the specified image
  295. file. This is useful for producing multiple files
  296. with identical color maps, or for forcing a predefined
  297. set of colors to be used. The FILE must be a GIF
  298. or PPM file. This option overrides -colors and
  299. -onepass.
  300. -nosmooth Use a faster, lower-quality upsampling routine.
  301. -onepass Use one-pass instead of two-pass color quantization.
  302. The one-pass method is faster and needs less memory,
  303. but it produces a lower-quality image. -onepass is
  304. ignored unless you also say -colors N. Also,
  305. the one-pass method is always used for grayscale
  306. output (the two-pass method is no improvement then).
  307. -maxmemory N Set limit for amount of memory to use in processing
  308. large images. Value is in thousands of bytes, or
  309. millions of bytes if "M" is attached to the number.
  310. For example, -max 4m selects 4000000 bytes. If more
  311. space is needed, temporary files will be used.
  312. -verbose Enable debug printout. More -v's give more printout.
  313. or -debug Also, version information is printed at startup.
  314. HINTS FOR CJPEG
  315. Color GIF files are not the ideal input for JPEG; JPEG is really intended for
  316. compressing full-color (24-bit) images. In particular, don't try to convert
  317. cartoons, line drawings, and other images that have only a few distinct
  318. colors. GIF works great on these, JPEG does not. If you want to convert a
  319. GIF to JPEG, you should experiment with cjpeg's -quality and -smooth options
  320. to get a satisfactory conversion. -smooth 10 or so is often helpful.
  321. Avoid running an image through a series of JPEG compression/decompression
  322. cycles. Image quality loss will accumulate; after ten or so cycles the image
  323. may be noticeably worse than it was after one cycle. It's best to use a
  324. lossless format while manipulating an image, then convert to JPEG format when
  325. you are ready to file the image away.
  326. The -optimize option to cjpeg is worth using when you are making a "final"
  327. version for posting or archiving. It's also a win when you are using low
  328. quality settings to make very small JPEG files; the percentage improvement
  329. is often a lot more than it is on larger files. (At present, -optimize
  330. mode is always selected when generating progressive JPEG files.)
  331. Support for GIF input files was removed in cjpeg v6b due to concerns over
  332. the Unisys LZW patent. Although this patent expired in 2006, cjpeg still
  333. lacks GIF support, for these historical reasons. (Conversion of GIF files to
  334. JPEG is usually a bad idea anyway.)
  335. HINTS FOR DJPEG
  336. To get a quick preview of an image, use the -grayscale and/or -scale switches.
  337. "-grayscale -scale 1/8" is the fastest case.
  338. Several options are available that trade off image quality to gain speed.
  339. "-fast" turns on the recommended settings.
  340. "-dct fast" and/or "-nosmooth" gain speed at a small sacrifice in quality.
  341. When producing a color-quantized image, "-onepass -dither ordered" is fast but
  342. much lower quality than the default behavior. "-dither none" may give
  343. acceptable results in two-pass mode, but is seldom tolerable in one-pass mode.
  344. Two-pass color quantization requires a good deal of memory; on MS-DOS machines
  345. it may run out of memory even with -maxmemory 0. In that case you can still
  346. decompress, with some loss of image quality, by specifying -onepass for
  347. one-pass quantization.
  348. To avoid the Unisys LZW patent (now expired), djpeg produces uncompressed GIF
  349. files. These are larger than they should be, but are readable by standard GIF
  350. decoders.
  351. HINTS FOR BOTH PROGRAMS
  352. If more space is needed than will fit in the available main memory (as
  353. determined by -maxmemory), temporary files will be used. (MS-DOS versions
  354. will try to get extended or expanded memory first.) The temporary files are
  355. often rather large: in typical cases they occupy three bytes per pixel, for
  356. example 3*800*600 = 1.44Mb for an 800x600 image. If you don't have enough
  357. free disk space, leave out -progressive and -optimize (for cjpeg) or specify
  358. -onepass (for djpeg).
  359. On MS-DOS, the temporary files are created in the directory named by the TMP
  360. or TEMP environment variable, or in the current directory if neither of those
  361. exist. Amiga implementations put the temp files in the directory named by
  362. JPEGTMP:, so be sure to assign JPEGTMP: to a disk partition with adequate free
  363. space.
  364. The default memory usage limit (-maxmemory) is set when the software is
  365. compiled. If you get an "insufficient memory" error, try specifying a smaller
  366. -maxmemory value, even -maxmemory 0 to use the absolute minimum space. You
  367. may want to recompile with a smaller default value if this happens often.
  368. On machines that have "environment" variables, you can define the environment
  369. variable JPEGMEM to set the default memory limit. The value is specified as
  370. described for the -maxmemory switch. JPEGMEM overrides the default value
  371. specified when the program was compiled, and itself is overridden by an
  372. explicit -maxmemory switch.
  373. On MS-DOS machines, -maxmemory is the amount of main (conventional) memory to
  374. use. (Extended or expanded memory is also used if available.) Most
  375. DOS-specific versions of this software do their own memory space estimation
  376. and do not need you to specify -maxmemory.
  377. JPEGTRAN
  378. jpegtran performs various useful transformations of JPEG files.
  379. It can translate the coded representation from one variant of JPEG to another,
  380. for example from baseline JPEG to progressive JPEG or vice versa. It can also
  381. perform some rearrangements of the image data, for example turning an image
  382. from landscape to portrait format by rotation. For EXIF files and JPEG files
  383. containing Exif data, you may prefer to use exiftran instead.
  384. jpegtran works by rearranging the compressed data (DCT coefficients), without
  385. ever fully decoding the image. Therefore, its transformations are lossless:
  386. there is no image degradation at all, which would not be true if you used
  387. djpeg followed by cjpeg to accomplish the same conversion. But by the same
  388. token, jpegtran cannot perform lossy operations such as changing the image
  389. quality. However, while the image data is losslessly transformed, metadata
  390. can be removed. See the -copy option for specifics.
  391. jpegtran uses a command line syntax similar to cjpeg or djpeg.
  392. On Unix-like systems, you say:
  393. jpegtran [switches] [inputfile] >outputfile
  394. On most non-Unix systems, you say:
  395. jpegtran [switches] inputfile outputfile
  396. where both the input and output files are JPEG files.
  397. To specify the coded JPEG representation used in the output file,
  398. jpegtran accepts a subset of the switches recognized by cjpeg:
  399. -optimize Perform optimization of entropy encoding parameters.
  400. -progressive Create progressive JPEG file.
  401. -arithmetic Use arithmetic coding.
  402. -restart N Emit a JPEG restart marker every N MCU rows, or every
  403. N MCU blocks if "B" is attached to the number.
  404. -scans file Use the scan script given in the specified text file.
  405. See the previous discussion of cjpeg for more details about these switches.
  406. If you specify none of these switches, you get a plain baseline-JPEG output
  407. file. The quality setting and so forth are determined by the input file.
  408. The image can be losslessly transformed by giving one of these switches:
  409. -flip horizontal Mirror image horizontally (left-right).
  410. -flip vertical Mirror image vertically (top-bottom).
  411. -rotate 90 Rotate image 90 degrees clockwise.
  412. -rotate 180 Rotate image 180 degrees.
  413. -rotate 270 Rotate image 270 degrees clockwise (or 90 ccw).
  414. -transpose Transpose image (across UL-to-LR axis).
  415. -transverse Transverse transpose (across UR-to-LL axis).
  416. The transpose transformation has no restrictions regarding image dimensions.
  417. The other transformations operate rather oddly if the image dimensions are not
  418. a multiple of the iMCU size (usually 8 or 16 pixels), because they can only
  419. transform complete blocks of DCT coefficient data in the desired way.
  420. jpegtran's default behavior when transforming an odd-size image is designed
  421. to preserve exact reversibility and mathematical consistency of the
  422. transformation set. As stated, transpose is able to flip the entire image
  423. area. Horizontal mirroring leaves any partial iMCU column at the right edge
  424. untouched, but is able to flip all rows of the image. Similarly, vertical
  425. mirroring leaves any partial iMCU row at the bottom edge untouched, but is
  426. able to flip all columns. The other transforms can be built up as sequences
  427. of transpose and flip operations; for consistency, their actions on edge
  428. pixels are defined to be the same as the end result of the corresponding
  429. transpose-and-flip sequence.
  430. For practical use, you may prefer to discard any untransformable edge pixels
  431. rather than having a strange-looking strip along the right and/or bottom edges
  432. of a transformed image. To do this, add the -trim switch:
  433. -trim Drop non-transformable edge blocks.
  434. Obviously, a transformation with -trim is not reversible, so strictly speaking
  435. jpegtran with this switch is not lossless. Also, the expected mathematical
  436. equivalences between the transformations no longer hold. For example,
  437. "-rot 270 -trim" trims only the bottom edge, but "-rot 90 -trim" followed by
  438. "-rot 180 -trim" trims both edges.
  439. If you are only interested in perfect transformations, add the -perfect switch:
  440. -perfect Fail with an error if the transformation is not
  441. perfect.
  442. For example, you may want to do
  443. jpegtran -rot 90 -perfect foo.jpg || djpeg foo.jpg | pnmflip -r90 | cjpeg
  444. to do a perfect rotation, if available, or an approximated one if not.
  445. This version of jpegtran also offers a lossless crop option, which discards
  446. data outside of a given image region but losslessly preserves what is inside.
  447. Like the rotate and flip transforms, lossless crop is restricted by the current
  448. JPEG format; the upper left corner of the selected region must fall on an iMCU
  449. boundary. If it doesn't, then it is silently moved up and/or left to the
  450. nearest iMCU boundary (the lower right corner is unchanged.) Thus, the output
  451. image covers at least the requested region, but it may cover more. The
  452. adjustment of the region dimensions may be optionally disabled by attaching an
  453. 'f' character ("force") to the width or height number.
  454. The image can be losslessly cropped by giving the switch:
  455. -crop WxH+X+Y Crop to a rectangular region of width W and height H,
  456. starting at point X,Y.
  457. Other not-strictly-lossless transformation switches are:
  458. -grayscale Force grayscale output.
  459. This option discards the chrominance channels if the input image is YCbCr
  460. (ie, a standard color JPEG), resulting in a grayscale JPEG file. The
  461. luminance channel is preserved exactly, so this is a better method of reducing
  462. to grayscale than decompression, conversion, and recompression. This switch
  463. is particularly handy for fixing a monochrome picture that was mistakenly
  464. encoded as a color JPEG. (In such a case, the space savings from getting rid
  465. of the near-empty chroma channels won't be large; but the decoding time for
  466. a grayscale JPEG is substantially less than that for a color JPEG.)
  467. jpegtran also recognizes these switches that control what to do with "extra"
  468. markers, such as comment blocks:
  469. -copy none Copy no extra markers from source file. This setting
  470. suppresses all comments and other metadata in the
  471. source file.
  472. -copy comments Copy only comment markers. This setting copies
  473. comments from the source file but discards any other
  474. metadata.
  475. -copy all Copy all extra markers. This setting preserves
  476. miscellaneous markers found in the source file, such
  477. as JFIF thumbnails, Exif data, and Photoshop settings.
  478. In some files, these extra markers can be sizable.
  479. Note that this option will copy thumbnails as-is;
  480. they will not be transformed.
  481. The default behavior is -copy comments. (Note: in IJG releases v6 and v6a,
  482. jpegtran always did the equivalent of -copy none.)
  483. Additional switches recognized by jpegtran are:
  484. -outfile filename
  485. -maxmemory N
  486. -verbose
  487. -debug
  488. These work the same as in cjpeg or djpeg.
  489. THE COMMENT UTILITIES
  490. The JPEG standard allows "comment" (COM) blocks to occur within a JPEG file.
  491. Although the standard doesn't actually define what COM blocks are for, they
  492. are widely used to hold user-supplied text strings. This lets you add
  493. annotations, titles, index terms, etc to your JPEG files, and later retrieve
  494. them as text. COM blocks do not interfere with the image stored in the JPEG
  495. file. The maximum size of a COM block is 64K, but you can have as many of
  496. them as you like in one JPEG file.
  497. We provide two utility programs to display COM block contents and add COM
  498. blocks to a JPEG file.
  499. rdjpgcom searches a JPEG file and prints the contents of any COM blocks on
  500. standard output. The command line syntax is
  501. rdjpgcom [-raw] [-verbose] [inputfilename]
  502. The switch "-raw" (or just "-r") causes rdjpgcom to output non-printable
  503. characters in JPEG comments. These characters are normally escaped for
  504. security reasons.
  505. The switch "-verbose" (or just "-v") causes rdjpgcom to also display the JPEG
  506. image dimensions. If you omit the input file name from the command line,
  507. the JPEG file is read from standard input. (This may not work on some
  508. operating systems, if binary data can't be read from stdin.)
  509. wrjpgcom adds a COM block, containing text you provide, to a JPEG file.
  510. Ordinarily, the COM block is added after any existing COM blocks, but you
  511. can delete the old COM blocks if you wish. wrjpgcom produces a new JPEG
  512. file; it does not modify the input file. DO NOT try to overwrite the input
  513. file by directing wrjpgcom's output back into it; on most systems this will
  514. just destroy your file.
  515. The command line syntax for wrjpgcom is similar to cjpeg's. On Unix-like
  516. systems, it is
  517. wrjpgcom [switches] [inputfilename]
  518. The output file is written to standard output. The input file comes from
  519. the named file, or from standard input if no input file is named.
  520. On most non-Unix systems, the syntax is
  521. wrjpgcom [switches] inputfilename outputfilename
  522. where both input and output file names must be given explicitly.
  523. wrjpgcom understands three switches:
  524. -replace Delete any existing COM blocks from the file.
  525. -comment "Comment text" Supply new COM text on command line.
  526. -cfile name Read text for new COM block from named file.
  527. (Switch names can be abbreviated.) If you have only one line of comment text
  528. to add, you can provide it on the command line with -comment. The comment
  529. text must be surrounded with quotes so that it is treated as a single
  530. argument. Longer comments can be read from a text file.
  531. If you give neither -comment nor -cfile, then wrjpgcom will read the comment
  532. text from standard input. (In this case an input image file name MUST be
  533. supplied, so that the source JPEG file comes from somewhere else.) You can
  534. enter multiple lines, up to 64KB worth. Type an end-of-file indicator
  535. (usually control-D or control-Z) to terminate the comment text entry.
  536. wrjpgcom will not add a COM block if the provided comment string is empty.
  537. Therefore -replace -comment "" can be used to delete all COM blocks from a
  538. file.
  539. These utility programs do not depend on the IJG JPEG library. In
  540. particular, the source code for rdjpgcom is intended as an illustration of
  541. the minimum amount of code required to parse a JPEG file header correctly.