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