usage.txt 32 KB

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