wizard.txt 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. Advanced usage instructions for the Independent JPEG Group's JPEG software
  2. ==========================================================================
  3. This file describes cjpeg's "switches for wizards".
  4. The "wizard" switches are intended for experimentation with JPEG by persons
  5. who are reasonably knowledgeable about the JPEG standard. If you don't know
  6. what you are doing, DON'T USE THESE SWITCHES. You'll likely produce files
  7. with worse image quality and/or poorer compression than you'd get from the
  8. default settings. Furthermore, these switches must be used with caution
  9. when making files intended for general use, because not all JPEG decoders
  10. will support unusual JPEG parameter settings.
  11. Quantization Table Adjustment
  12. -----------------------------
  13. Ordinarily, cjpeg starts with a default set of tables (the same ones given
  14. as examples in the JPEG standard) and scales them up or down according to
  15. the -quality setting. The details of the scaling algorithm can be found in
  16. jcparam.c. At very low quality settings, some quantization table entries
  17. can get scaled up to values exceeding 255. Although 2-byte quantization
  18. values are supported by the IJG software, this feature is not in baseline
  19. JPEG and is not supported by all implementations. If you need to ensure
  20. wide compatibility of low-quality files, you can constrain the scaled
  21. quantization values to no more than 255 by giving the -baseline switch.
  22. Note that use of -baseline will result in poorer quality for the same file
  23. size, since more bits than necessary are expended on higher AC coefficients.
  24. You can substitute a different set of quantization values by using the
  25. -qtables switch:
  26. -qtables file Use the quantization tables given in the named file.
  27. The specified file should be a text file containing decimal quantization
  28. values. The file should contain one to four tables, each of 64 elements.
  29. The tables are implicitly numbered 0,1,etc. in order of appearance. Table
  30. entries appear in normal array order (NOT in the zigzag order in which they
  31. will be stored in the JPEG file).
  32. Quantization table files are free format, in that arbitrary whitespace can
  33. appear between numbers. Also, comments can be included: a comment starts
  34. with '#' and extends to the end of the line. Here is an example file that
  35. duplicates the default quantization tables:
  36. # Quantization tables given in Annex K (Clause K.1) of
  37. # Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994.
  38. # This is table 0 (the luminance table):
  39. 16 11 10 16 24 40 51 61
  40. 12 12 14 19 26 58 60 55
  41. 14 13 16 24 40 57 69 56
  42. 14 17 22 29 51 87 80 62
  43. 18 22 37 56 68 109 103 77
  44. 24 35 55 64 81 104 113 92
  45. 49 64 78 87 103 121 120 101
  46. 72 92 95 98 112 100 103 99
  47. # This is table 1 (the chrominance table):
  48. 17 18 24 47 99 99 99 99
  49. 18 21 26 66 99 99 99 99
  50. 24 26 56 99 99 99 99 99
  51. 47 66 99 99 99 99 99 99
  52. 99 99 99 99 99 99 99 99
  53. 99 99 99 99 99 99 99 99
  54. 99 99 99 99 99 99 99 99
  55. 99 99 99 99 99 99 99 99
  56. If the -qtables switch is used without -quality, then the specified tables
  57. are used exactly as-is. If both -qtables and -quality are used, then the
  58. tables taken from the file are scaled in the same fashion that the default
  59. tables would be scaled for that quality setting. If -baseline appears, then
  60. the quantization values are constrained to the range 1-255.
  61. By default, cjpeg will use quantization table 0 for luminance components and
  62. table 1 for chrominance components. To override this choice, use the -qslots
  63. switch:
  64. -qslots N[,...] Select which quantization table to use for
  65. each color component.
  66. The -qslots switch specifies a quantization table number for each color
  67. component, in the order in which the components appear in the JPEG SOF marker.
  68. For example, to create a separate table for each of Y,Cb,Cr, you could
  69. provide a -qtables file that defines three quantization tables and say
  70. "-qslots 0,1,2". If -qslots gives fewer table numbers than there are color
  71. components, then the last table number is repeated as necessary.
  72. Sampling Factor Adjustment
  73. --------------------------
  74. By default, cjpeg uses 2:1 horizontal and vertical downsampling when
  75. compressing YCbCr data, and no downsampling for all other color spaces.
  76. You can override this default with the -sample switch:
  77. -sample HxV[,...] Set JPEG sampling factors for each color
  78. component.
  79. The -sample switch specifies the JPEG sampling factors for each color
  80. component, in the order in which they appear in the JPEG SOF marker.
  81. If you specify fewer HxV pairs than there are components, the remaining
  82. components are set to 1x1 sampling. For example, the default YCbCr setting
  83. is equivalent to "-sample 2x2,1x1,1x1", which can be abbreviated to
  84. "-sample 2x2".
  85. There are still some JPEG decoders in existence that support only 2x1
  86. sampling (also called 4:2:2 sampling). Compatibility with such decoders can
  87. be achieved by specifying "-sample 2x1". This is not recommended unless
  88. really necessary, since it increases file size and encoding/decoding time
  89. with very little quality gain.
  90. Multiple Scan / Progression Control
  91. -----------------------------------
  92. By default, cjpeg emits a single-scan sequential JPEG file. The
  93. -progressive switch generates a progressive JPEG file using a default series
  94. of progression parameters. You can create multiple-scan sequential JPEG
  95. files or progressive JPEG files with custom progression parameters by using
  96. the -scans switch:
  97. -scans file Use the scan sequence given in the named file.
  98. The specified file should be a text file containing a "scan script".
  99. The script specifies the contents and ordering of the scans to be emitted.
  100. Each entry in the script defines one scan. A scan definition specifies
  101. the components to be included in the scan, and for progressive JPEG it also
  102. specifies the progression parameters Ss,Se,Ah,Al for the scan. Scan
  103. definitions are separated by semicolons (';'). A semicolon after the last
  104. scan definition is optional.
  105. Each scan definition contains one to four component indexes, optionally
  106. followed by a colon (':') and the four progressive-JPEG parameters. The
  107. component indexes denote which color component(s) are to be transmitted in
  108. the scan. Components are numbered in the order in which they appear in the
  109. JPEG SOF marker, with the first component being numbered 0. (Note that these
  110. indexes are not the "component ID" codes assigned to the components, just
  111. positional indexes.)
  112. The progression parameters for each scan are:
  113. Ss Zigzag index of first coefficient included in scan
  114. Se Zigzag index of last coefficient included in scan
  115. Ah Zero for first scan of a coefficient, else Al of prior scan
  116. Al Successive approximation low bit position for scan
  117. If the progression parameters are omitted, the values 0,63,0,0 are used,
  118. producing a sequential JPEG file. cjpeg automatically determines whether
  119. the script represents a progressive or sequential file, by observing whether
  120. Ss and Se values other than 0 and 63 appear. (The -progressive switch is
  121. not needed to specify this; in fact, it is ignored when -scans appears.)
  122. The scan script must meet the JPEG restrictions on progression sequences.
  123. (cjpeg checks that the spec's requirements are obeyed.)
  124. Scan script files are free format, in that arbitrary whitespace can appear
  125. between numbers and around punctuation. Also, comments can be included: a
  126. comment starts with '#' and extends to the end of the line. For additional
  127. legibility, commas or dashes can be placed between values. (Actually, any
  128. single punctuation character other than ':' or ';' can be inserted.) For
  129. example, the following two scan definitions are equivalent:
  130. 0 1 2: 0 63 0 0;
  131. 0,1,2 : 0-63, 0,0 ;
  132. Here is an example of a scan script that generates a partially interleaved
  133. sequential JPEG file:
  134. 0; # Y only in first scan
  135. 1 2; # Cb and Cr in second scan
  136. Here is an example of a progressive scan script using only spectral selection
  137. (no successive approximation):
  138. # Interleaved DC scan for Y,Cb,Cr:
  139. 0,1,2: 0-0, 0, 0 ;
  140. # AC scans:
  141. 0: 1-2, 0, 0 ; # First two Y AC coefficients
  142. 0: 3-5, 0, 0 ; # Three more
  143. 1: 1-63, 0, 0 ; # All AC coefficients for Cb
  144. 2: 1-63, 0, 0 ; # All AC coefficients for Cr
  145. 0: 6-9, 0, 0 ; # More Y coefficients
  146. 0: 10-63, 0, 0 ; # Remaining Y coefficients
  147. Here is an example of a successive-approximation script. This is equivalent
  148. to the default script used by "cjpeg -progressive" for YCbCr images:
  149. # Initial DC scan for Y,Cb,Cr (lowest bit not sent)
  150. 0,1,2: 0-0, 0, 1 ;
  151. # First AC scan: send first 5 Y AC coefficients, minus 2 lowest bits:
  152. 0: 1-5, 0, 2 ;
  153. # Send all Cr,Cb AC coefficients, minus lowest bit:
  154. # (chroma data is usually too small to be worth subdividing further;
  155. # but note we send Cr first since eye is least sensitive to Cb)
  156. 2: 1-63, 0, 1 ;
  157. 1: 1-63, 0, 1 ;
  158. # Send remaining Y AC coefficients, minus 2 lowest bits:
  159. 0: 6-63, 0, 2 ;
  160. # Send next-to-lowest bit of all Y AC coefficients:
  161. 0: 1-63, 2, 1 ;
  162. # At this point we've sent all but the lowest bit of all coefficients.
  163. # Send lowest bit of DC coefficients
  164. 0,1,2: 0-0, 1, 0 ;
  165. # Send lowest bit of AC coefficients
  166. 2: 1-63, 1, 0 ;
  167. 1: 1-63, 1, 0 ;
  168. # Y AC lowest bit scan is last; it's usually the largest scan
  169. 0: 1-63, 1, 0 ;
  170. It may be worth pointing out that this script is tuned for quality settings
  171. of around 50 to 75. For lower quality settings, you'd probably want to use
  172. a script with fewer stages of successive approximation (otherwise the
  173. initial scans will be really bad). For higher quality settings, you might
  174. want to use more stages of successive approximation (so that the initial
  175. scans are not too large).