libextractor

GNU libextractor
Log | Files | Refs | Submodules | README | LICENSE

jfif.txt (15311B)


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