home *** CD-ROM | disk | FTP | other *** search
/ Encyclopedia of Graphics File Formats Companion / GFF_CD.ISO / formats / jpeg / spec / jfif.txt < prev    next >
Text File  |  1994-06-01  |  15KB  |  367 lines

  1. JPEG File Interchange Format
  2. Version 1.02
  3.  
  4.  
  5. September 1, 1992
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.                             Eric Hamilton
  16.                             C-Cube Microsystems
  17.                             1778 McCarthy Blvd.
  18.                             Milpitas, CA 95035
  19.  
  20.                             +1 408 944-6300
  21.                             Fax: +1 408 944-6314
  22.                             E-mail: eric@c-cube.com
  23.                             
  24.  
  25.  
  26.  
  27. JPEG File Interchange Format
  28. Version 1.02
  29.  
  30. Why a File Interchange Format
  31.  
  32. JPEG File Interchange Format is a minimal file format which enables JPEG 
  33. bitstreams to be exchanged between a wide variety of platforms and 
  34. applications.  This minimal format does not include any of the advanced 
  35. features found in the TIFF JPEG specification or any application specific 
  36. file format. Nor should it, for the only purpose of this simplified 
  37. format is to allow the exchange of JPEG compressed images.
  38.  
  39. JPEG File Interchange Format features
  40.  
  41. o      Uses JPEG compression
  42. o      Uses JPEG interchange format compressed image representation
  43. o      PC or Mac or Unix workstation compatible
  44. o      Standard color space: one or three components. For three components, 
  45.        YCbCr (CCIR 601-256 levels)
  46. o      APP0 marker used to specify Units, X pixel density, Y pixel density, 
  47.        thumbnail
  48. o      APP0 marker also used to specify JFIF extensions
  49. o      APP0 marker also used to specify application-specific information
  50.  
  51. JPEG Compression
  52.  
  53. Although any JPEG process is supported by the syntax of the JPEG File 
  54. Interchange Format (JFIF) it is strongly recommended that the JPEG baseline 
  55. process be used for the purposes of file interchange. This ensures maximum 
  56. compatibility with all applications supporting JPEG. JFIF conforms to the 
  57. JPEG Draft International Standard (ISO DIS 10918-1).
  58.  
  59. The JPEG File Interchange Format is entirely compatible with the standard 
  60. JPEG interchange format;  the only additional requirement is the mandatory 
  61. presence of the APP0 marker right after the SOI marker.  Note that JPEG 
  62. interchange format requires (as does JFIF) that all table specifications 
  63. used in the encoding process be coded in the bitstream prior to their use.
  64.  
  65. Compatible across platforms
  66.  
  67. The JPEG File Interchange Format is compatible across platforms: for 
  68. example, it does not use any resource forks, supported by the Macintosh but 
  69. not by PCs or workstations.
  70.  
  71.  
  72. Standard color space
  73.  
  74. The color space to be used is YCbCr as defined by CCIR 601 (256 levels).  
  75. The RGB components calculated by linear conversion from YCbCr shall not be 
  76. gamma corrected (gamma = 1.0).  If only one component is used, that 
  77. component shall be Y.
  78.  
  79. APP0 marker used to identify JPEG FIF
  80.  
  81. The APP0 marker is used to identify a JPEG FIF file.  The JPEG FIF APP0 
  82. marker is mandatory right after the SOI marker.
  83.  
  84. The JFIF APP0 marker is identified by a zero terminated string: "JFIF". 
  85. The APP0 can be used for any other purpose by the application provided it 
  86. can be distinguished from the JFIF APP0.  
  87.  
  88. The JFIF APP0 marker provides information which is missing from the JPEG 
  89. stream: version number, X and Y pixel density (dots per inch or dots per 
  90. cm), pixel aspect ratio (derived from X and Y pixel density), thumbnail.
  91.  
  92. APP0 marker used to specify JFIF extensions
  93.  
  94. Additional APP0 marker segment(s) can optionally be used to specify JFIF 
  95. extensions.  If used, these segment(s) must immediately follow the JFIF 
  96. APP0 marker.  Decoders should skip any unsupported JFIF extension 
  97. segments and continue decoding.
  98.  
  99. The JFIF extension APP0 marker is identified by a zero terminated string:  
  100. "JFXX".  The JFIF extension APP0 marker segment contains a 1-byte code 
  101. which identifies the extension.  This version, version 1.02, has only 
  102. one extension defined:  an extension for defining thumbnails stored in 
  103. formats other than 24-bit RGB.
  104.  
  105. APP0 marker used for application-specific information
  106.  
  107. Additional APP0 marker segments can be used to hold application-specific 
  108. information which does not affect the decodability or displayability of 
  109. the JFIF file.  Application-specific APP0 marker segments must appear 
  110. after the JFIF APP0 and any JFXX APP0 segments.  Decoders should skip any 
  111. unrecognized application-specific APP0 segments. 
  112.  
  113. Application-specific APP0 marker segments are identified by a zero 
  114. terminated string which identifies the application (not "JFIF" or "JFXX").  
  115. This string should be an organization name or company trademark.  Generic 
  116. strings such as dog, cat, tree, etc. should not be used. 
  117.  
  118.  
  119.  
  120. Conversion to and from RGB
  121.     
  122. Y, Cb, and Cr are converted from R, G, and B as defined in CCIR 
  123. Recommendation 601 but are normalized so as to occupy the full 256 levels 
  124. of a 8-bit binary encoding.  More precisely:
  125.  
  126. Y   = 256 * E'y
  127. Cb  = 256 * [ E'Cb ] + 128
  128. Cr  = 256 * [ E'Cr ] + 128
  129.  
  130. where the E'y, E'Cb and E'Cb are defined as in CCIR 601.  Since values of 
  131. E'y have a range of 0 to 1.0 and those for  E'Cb and E'Cr have a range of 
  132. -0.5 to +0.5,  Y, Cb, and Cr must be clamped to 255 when they are maximum 
  133. value.
  134.  
  135. RGB to YCbCr Conversion
  136.     
  137. YCbCr (256 levels) can be computed directly from 8-bit RGB as follows:
  138.  
  139. Y   =     0.299  R + 0.587  G + 0.114  B
  140. Cb  =   - 0.1687 R - 0.3313 G + 0.5    B + 128
  141. Cr  =     0.5    R - 0.4187 G - 0.0813 B + 128
  142.  
  143. NOTE - Not all image file formats store image samples in the order R0, G0, 
  144. B0, ... Rn, Gn, Bn.  Be sure to verify the sample order before converting an 
  145. RGB file to JFIF.
  146.  
  147.     
  148. YCbCr to RGB Conversion
  149.     
  150. RGB can be computed directly from YCbCr (256 levels) as follows:
  151.  
  152. R = Y                    + 1.402   (Cr-128)
  153. G = Y - 0.34414 (Cb-128) - 0.71414 (Cr-128)
  154. B = Y + 1.772   (Cb-128)
  155.  
  156.  
  157. Image Orientation
  158.  
  159. In JFIF files, the image orientation is always top-down.  This means that 
  160. the first image samples encoded in a JFIF file are located in the upper left 
  161. hand corner of the image and encoding proceeds from left to right and top to 
  162. bottom.  Top-down orientation is used for both the full resolution image 
  163. and the thumbnail image.
  164.  
  165. The process of converting an image file having bottom-up orientation to 
  166. JFIF must include inverting the order of all image lines before JPEG encoding.
  167.  
  168.  
  169. Spatial Relationship of Components
  170.  
  171. Specification of the spatial positioning of pixel samples within components 
  172. relative to the samples of other components is necessary for proper image 
  173. post processing and accurate image presentation.  In JFIF files, the 
  174. position of the pixels in subsampled components are defined with respect 
  175. to the highest resolution component.  Since components must be 
  176. sampled orthogonally (along rows and columns), the spatial position of the 
  177. samples in a given subsampled component may be determined by specifying the 
  178. horizontal and vertical offsets of the first sample, i.e. the sample in 
  179. the upper left corner, with respect to the highest resolution component.
  180.  
  181. The horizontal and vertical offsets of the first sample in a subsampled 
  182. component, Xoffseti[0,0] and Yoffseti[0,0], is defined to be
  183.  
  184. Xoffseti[0,0] = ( Nsamplesref / Nsamplesi  ) / 2 - 0.5
  185. Yoffseti[0,0] = ( Nlinesref / Nlinesi  ) / 2 - 0.5
  186.  
  187. where
  188.  
  189. Nsamplesref is the number of samples per line in the largest component,
  190. Nsamplesi is the number of samples per line in the ith component,
  191. Nlinesref is the number of lines in the largest component,
  192. Nlinesi is the number of lines in the ith component.
  193.   
  194. Proper subsampling of components incorporates an anti-aliasing filter 
  195. which reduces the spectral bandwidth of the full resolution components.   
  196. Subsampling can easily be accomplished using a symmetrical digital filter 
  197. with an even number of taps (coefficients).  A commonly used filter for 
  198. 2:1 subsampling utilizes two taps (1/2,1/2).
  199.  
  200. ED. NOTE:  Figures are not available in this plain text version of
  201. the specification.  See the PostScript version for a figure in this
  202. section.
  203.  
  204. NOTE - This definition is compatible with industry standards such as 
  205. Postcript Level 2 and QuickTime. This defintition is not compatible with the 
  206. conventions used by CCIR Recommendation 601-1 and other digital video 
  207. formats.  For these formats, pre-processing of the chrominance components 
  208. is necessary prior to compression in order to ensure accurate reconstruction 
  209. of the compressed image.
  210.  
  211.  
  212. JPEG File Interchange Format Specification
  213.  
  214. The syntax of a JFIF file conforms to the syntax for interchange format 
  215. defined in Annex B of ISO DIS 10918-1.  In addition, a JFIF file uses APP0 
  216. marker segments and constrains certain parameters in the frame header as 
  217. defined below.
  218.  
  219.     X'FF', SOI
  220.          X'FF', APP0, length, identifier, version, units, Xdensity, Ydensity, 
  221.          Xthumbnail, Ythumbnail, (RGB)n
  222.  
  223.               length     (2 bytes)  Total APP0 field byte count, including 
  224.                     the byte count value (2 bytes), but 
  225.                     excluding the APP0 marker itself
  226.               identifier (5 bytes)  = X'4A', X'46', X'49', X'46', X'00' 
  227.                                     This zero terminated string ("JFIF") 
  228.                     uniquely identifies this APP0 marker.  
  229.                         This string shall have zero parity 
  230.                     (bit 7=0).
  231.               version    (2 bytes)  = X'0102'
  232.                                     The most significant byte is used for 
  233.                     major revisions, the least significant 
  234.                     byte for minor revisions. Version 1.02 
  235.                     is the current released revision.
  236.               units      (1 byte)   Units for the X and Y densities.
  237.                                     units = 0:  no units, X and Y specify the 
  238.                         pixel aspect ratio
  239.                                     units = 1:  X and Y are dots per inch
  240.                                     units = 2:  X and Y are dots per cm
  241.               Xdensity   (2 bytes)  Horizontal pixel density
  242.               Ydensity   (2 bytes)  Vertical pixel density
  243.               Xthumbnail (1 byte)   Thumbnail horizontal pixel count
  244.               Ythumbnail (1 byte)   Thumbnail vertical pixel count
  245.               (RGB)n     (3n bytes) Packed (24-bit) RGB values for the 
  246.                     thumbnail pixels, n = Xthumbnail * 
  247.                     Ythumbnail
  248.         [ Optional JFIF extension APP0 marker segment(s) - see below ]
  249.                 o
  250.                 o
  251.                 o
  252.         X'FF', SOFn, length, frame parameters
  253.            Number of components Nf  = 1 or 3
  254.            1st component    C1    = 1 = Y component
  255.            2nd component    C2    = 2 = Cb component
  256.            3rd component    C3    = 3 = Cr component
  257.                 o
  258.                 o
  259.                 o
  260.     X'FF', EOI
  261.  
  262. JFIF Extension APP0 Marker Segment
  263.  
  264. Immediately following the JFIF APP0 marker segment may be a JFIF extension 
  265. APP0 marker.  This JFIF extension APP0 marker segment may only be present for 
  266. JFIF versions 1.02 and above.  The syntax of the JFIF extension APP0 marker 
  267. segment is:
  268.  
  269.          X'FF', APP0, length, identifier, extension_code, extension_data
  270.             length   (2 bytes)    Total APP0 field byte count, including 
  271.                   the byte count value (2 bytes), but 
  272.                   excluding the APP0 marker itself
  273.             identifier  (5 bytes)    = X'4A', X'46', X'58', X'58', X'00' 
  274.                                   This zero terminated string ("JFXX") 
  275.                   uniquely identifies this APP0 marker.  This 
  276.                   string shall have zero parity (bit 7=0).
  277.             extension_code (1 byte)    = Code which identifies the 
  278.                   extension.  In this version, the following 
  279.                   extensions are defined:
  280.                                    = X'10'   Thumbnail coded using JPEG
  281.                                    = X'11'   Thumbnail stored using 1 byte/
  282.                         pixel
  283.                                    = X'13'   Thumbnail stored using 3 bytes/
  284.                         pixel
  285.             extension_data (variable)    = The specification of the remainder 
  286.                    of the JFIF extension APP0 marker segment 
  287.                   varies with the extension. See below for 
  288.                   a specification of extension_data for each 
  289.                   extension.
  290.  
  291. JFIF Extension:  Thumbnail coded using JPEG
  292.  
  293. This extension supports thumbnails compressed using JPEG.  The compressed 
  294. thumbnail  immediately follows the extension_code (X'10') in the 
  295. extension_data field and the length of the compressed data must be 
  296. included in the JFIF extension APP0 marker length field.
  297.  
  298. The syntax of the extension_data field conforms to the syntax for 
  299. interchange format defined in Annex B of ISO DIS 10918-1.  However, no 
  300. "JFIF" or "JFXX" marker segments shall be present.  As in the full 
  301. resolution image of the JFIF file, the syntax of extension_data constrains 
  302. parameters in the frame header as defined below:
  303.  
  304.     X'FF', SOI
  305.                 o
  306.                 o
  307.                 o
  308.         X'FF', SOFn, length, frame parameters
  309.              Number of components    Nf    = 1 or 3
  310.              1st component    C1    = 1 = Y component
  311.              2nd component    C2    = 2 = Cb component
  312.              3rd component    C3    = 3 = Cr component
  313.                 o
  314.                 o
  315.                 o
  316.     X'FF', EOI
  317.  
  318.  
  319.  
  320. JFIF Extension:  Thumbnail stored using one byte per pixel
  321.  
  322. This extension supports thumbnails stored using one byte per pixel and a 
  323. color palette in the extension_data field.  The syntax of extension_data is:
  324.  
  325.         Xthumbnail       (1 byte)    Thumbnail horizontal pixel count
  326.         Ythumbnail       (1 byte)    Thumbnail vertical pixel count
  327.         palette          (768 bytes) 24-bit RGB pixel values for the color 
  328.                      palette.  The RGB values define the 
  329.                      colors represented by each value of 
  330.                      an 8-bit binary encoding (0 - 255).
  331.         (pixel)n        (n bytes)    8-bit values for the thumbnail pixels 
  332.                                      n = Xthumbnail * Ythumbnail
  333.  
  334. JFIF Extension:  Thumbnail stored using three bytes per pixel
  335.  
  336. This extension supports thumbnails stored using three bytes per pixel in the 
  337. extension_data field.  The syntax of extension_data is:
  338.  
  339.         Xthumbnail       (1 byte)    Thumbnail horizontal pixel count
  340.         Ythumbnail       (1 byte)    Thumbnail vertical pixel count
  341.         (RGB)n           (3n bytes)  Packed (24-bit) RGB values for the 
  342.                      thumbnail pixels, 
  343.                      n = Xthumbnail * Ythumbnail
  344.  
  345. Useful tips
  346.  
  347. o you can identify a JFIF file by looking for the following sequence: 
  348. X'FF', SOI, X'FF', APP0, <2 bytes to be skipped>, "JFIF", X'00'.
  349.  
  350. o if you use APP0 elsewhere, be sure not to have the strings "JFIF" or 
  351. "JFXX" right after the APP0 marker.
  352.  
  353. o if you do not want to include a thumbnail, just program Xthumbnail = 
  354. Ythumbnail = 0.
  355.  
  356. o be sure to check the version number in the special APP0 field.  In 
  357. general, if the major version number of the JFIF file matches that 
  358. supported by the decoder, the file will be decodable.
  359.  
  360. o if you only want to specify a pixel aspect ratio, put 0 for the units 
  361. field in the special APP0 field. Xdensity and Ydensity can then be 
  362. programmed for the desired aspect ratio. Xdensity = 1, Ydensity = 1 
  363. will program a 1:1 aspect ratio.  Xdensity and Ydensity should 
  364. always be non-zero.
  365.  
  366.  
  367.