usage.txt 31 KB

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