Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ Jpeg(3) — Solaris 2.4 x86 SDK

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

xil_cis_create(3)

xil_cis_get_attribute(3)

xil_cis_get_bits_ptr(3)

xil_compress(3)

xil_decompress(3)

Jpeg(3)

NAME

Jpeg − JPEG compressor/decompressor for compressed image sequences

DESCRIPTION

The Joint Photographic Experts Group (JPEG) is a joint ISO/CCITT technical committee.  JPEG has developed a general-purpose international standard for the compression of continuous tone (grayscale or color) still images. The standard has three categories:

The baseline specification,
An extended features specification, and
A lossless compression specification.

The baseline specification is a simple coding method based on the Discrete Cosine Transform (DCT) and uniform quantization in combination with statistical Huffman coding techniques for 8-bit image components. The extended features specification provides support for higher image precision, alternate statistical coding techniques, and progressive operation. The lossless compression technique is a two-dimensional predictive differential coding technique, which also combines with statistical coding. 

The XIL implementation supports the baseline specification, "Jpeg", and the lossless specification, "JpegLL".  Consult JpegLL(3) for more information on the XIL library’s JPEG Lossless implementation. 

Certain combinations of XIL operations are accelerated.  These combinations should be used for the highest performance in JPEG decompression.  For more information and example programs, see the XIL Programmer’s Guide. 

Creating a CIS

To compress a compressed image sequence (CIS) with the XIL JPEG compressor, specify "Jpeg" for the compressorname argument in xil_cis_create(3). 

Getting and Setting JPEG Attributes

Use xil_cis_get_attribute(3) and xil_cis_set_attribute(3) to get and set JPEG CIS attributes.  These attributes are as described in the following sections.  Refer to the example section for additional information. 

JPEG Compression Attributes

The following paragraphs describe the JPEG CIS attributes available with the XIL library. All structures and enumerations are defined via xil.h.  Note that some attributes are "set-only" and others are "get-only."  This is noted under the Access heading for each attribute. 

Note that if you are setting an attribute and that attribute is a structure, you must pass the address of that structure.  If you are getting an attribute, you always pass its address. 

BAND_HUFFMAN_TABLE

Description Associates a band of an image to a Huffman table

Access set-only

Type typedef struct {

                int band;
                int table;
                XilJpegHTableType type;
} XilJpegBandHTable;

Values band: Can have a value in the range 0-255.  table: For Baseline JPEG, you can have a value in the range 0-1.  type: For Baseline JPEG, you can have a value DC or AC. 

Default band 0’s DC component is associated to table 0, type DC and band 0’s AC component is associated to table 0, type AC.  All other bands’ DC component is associated to table 1, type DC, and their AC component is associated to table 1, type AC. 

Notes Bands may be associated to tables that have not yet been set. However, the tables must be set before a call to compress is made or an error occurs. 

BAND_QUANTIZER

Description Associates a band of an image to a quantization table

Access set-only

Type typedef struct {

                int band;
                int table;
} XilJpegBandQTable;

Values band: Can have a value in the range 0-255.  table: Can have a value in the range 0-3. 

Default band 0 is associated to table 0.  All other bands are associated to table 1. 

Notes Bands may be associated to tables that have not yet been set. However, the tables must be set before a call to compress is made or an error occurs. 

BYTES_PER_FRAME

Description Number of bytes in the last frame compressed by a CIS. This value can be used to assist in selecting a COMPRESSION_QUALITY to achieve a desired bit rate. 

Access get-only

Type int

Default Not applicable. Value is undefined for a CIS that has not compressed any frames. 

COMPRESSED_DATA_FORMAT

Description defines output format for JPEG compressor

Access set

Type typedef enum{

              INTERCHANGE, ABBREVIATED_FORMAT
} XilJpegCompressedDataFormat;

Values INTERCHANGE: Use JPEG interchange format. All quantization and entropy-coding table specifications needed by the decoding process are included in each compressed frame.  ABBREVIATED_FORMAT: Use JPEG abbreviated format for compressed images. Quantization and  entropy-coding table specifications are not included in a compressed frame if the specifications are defined in a previous frame in the compressed sequence. If any table values change after they are defined in the compressed sequence, a new table definition is included in the first compressed frame that uses the new table values. 

Default ABBREVIATED_FORMAT

Notes This does not include the third type: ABBREVIATED_TABLE, in which a frame contains only table specifications. However, the decoder will accept this format. 

COMPRESSION_QUALITY

Description Provide a hint to the compressor, enabling it to increase the compression ratio by reducing the compressed image quality. 

Access set-only

Type int value

Values value can be an integer from 1 to 100. Setting value to 100 requests the highest quality achievable by the compressor. A value equal to 1 sets the compression ratio to the maximum achievable while reducing quality. The compression ratio may also be affected by modifying the quantization table. However, this attribute will not cause a change in values for the QUANTIZATION_TABLE. 

Default 50

ENCODE_INTERLEAVED

Description If the image to compress is composed of 4 bands or less, having this attribute set to TRUE will generate an interleaved JPEG-compliant bitstream (for example, 1:1:1:1 for a 4 banded image). If the number of bands exceeds 4  or if this attribute is set to FALSE, a noninterleaved JPEG-compliant bitstream is generated. Note, that the ENCODE_411_INTERLEAVED attribute takes precedence over ENCODE_INTERLEAVED for Baseline JPEG. 

Access set-only

Type Xil_boolean

Values TRUE: For images of 4 bands or less, produce an interleaved JPEG-compliant bitstream.  FALSE: Produce a noninterleaved JPEG-compliant bitstream. 

Default TRUE

ENCODE_411_INTERLEAVED

Description For Baseline JPEG, if the image to compress is a 3-banded image, setting this attribute to TRUE generates a 2x2:1:1 macroblock JPEG-compliant bitstream.  This is useful to gain additional compression for YCbCr images and is mandatory for most decompression molecules.  It is not appropriate for RGB images.  If an image is not 3-banded, then the ENCODE_411_INTERLEAVED attribute is treated as if it were false, and therefore the ENCODE_INTERLEAVED attribute controls the interleaved format of the bitstream.  Otherwise, the ENCODE_411_INTERLEAVED attribute takes precedence over ENCODE_INTERLEAVED.  Because some decompressor molecules require the bitstream image size to be a multiple of 16 in both width and height, source images should be clipped (for example, by using a child image) before compression, if the highest decompression speed is desired. 

Access set-only

Type Xil_boolean

Values TRUE: Generate a 2x2:1:1 macroblock, JPEG-compliant bitstream if the input image is a 3-banded image.  FALSE: Do not generate a 2x2:1:1 macroblock, JPEG-compliant bitstream. 

Default FALSE

HUFFMAN_TABLE

Description Set values in specified Huffman table

Access set-only

Type typedef struct {

                int table;
                XilJpegHTableType type;
                XilJpegHTableValue ∗value;
} XilJpegHTable;
typedef enum {
              DC, AC
} XilJpegHTableType;
typedef struct {
                int bits;
                int pattern;
} XilJpegHTableValue;

Values table: For Baseline JPEG, you can have a value in the range from 0-1.  type: For Baseline JPEG, you can have a value DC or AC.  It also specifies how many entries are in the value array: 16 if type is DC; 256 if type is AC.  value: A pointer to an array of dyads, where the first element ‘bits’ indicates the number of valid bits in the second element ‘pattern’. 

Default By default, the values in each of the tables are pre-initialized to the example values given in Annex K of the ANSI JPEG specification.  Default values for table 0, type DC are given in Table K.3 and are useful for the DC coefficients of the luminance band of 8-bit Y,Cb,Cr images. Default values for table 1, type DC are given in Table K.4 and are useful for the DC coefficients of the chrominance bands of 8-bit Y,Cb,Cr images.  Default values for table 0, type AC are given in Table K.5 and are useful for the AC coefficients of the luminance band of 8-bit Y,Cb,Cr images. Default values for table 1, type AC are given in Table K.6 and are useful for the AC coefficients of the chrominance bands of 8-bit Y,Cb,Cr images. 

OPTIMIZE_HUFFMAN_TABLES

Description Provide a hint to the compressor, enabling it to generate optimal Huffman tables instead of using the default example values specified in the ANSI specification. This is only a hint; the compressor is free to ignore the hint. 

Access set-only

Type Xil_boolean

Values TRUE: Huffman tables may vary from image to image to achieve higher compression.  FALSE: Use fixed Huffman tables for each image in the sequence. 

Default FALSE

QUANTIZATION_TABLE

Description Set the values in a specific quantization table

Access set-only

Type typedef struct {

                int table;
                int (∗value)[8];
} XilJpegQTable;

Values table: Can have a value in the range 0-3.  value: For Baseline JPEG, the 64 quantization table elements are defined to be 8-bit values; the compressor uses the least significant 8 bits of the input table value. This precision assumption may vary according to the compressor/decompressor configuration. The quantization operation for a DCT coefficient uses the corresponding element from the input quantization table. 

Default Default values for table 0 are given in Table K.1 of Annex K of the ANSI JPEG specification, and are useful for the luminance band of 8-bit Y,Cb,Cr images. The default values for table 1 are given in Table K.2 of Annex K of the ANSI JPEG specification, and are useful for the chrominance bands of 8 bit Y,Cb,Cr images.  tables 2 and table 3 are not loaded with any values. 

Notes A table that is to be used to compress an image must be set before the call to compress. The compressor issues an error if a band has been set to use a particular quantization table that has not yet been set. 

TEMPORAL_FILTERING

Description Turns on or off a form of temporal filtering that may reduce noise in video sequences.  The filtering may also introduce undesirable artifacts in sequences containing motion.  Filtering is only performed on 3-banded images. 

Access get and set

Type Xil_boolean

Values TRUE: Filtering turned on FALSE: Filtering turned off

Default FALSE

JPEG Decompression Attributes

DECOMPRESSION_QUALITY

Description Provide a suggestion to the decompressor, enabling it to trade off reconstruction quality in exchange for an increase in decoding speed. 

Access set

Type int value

Values value can be between 1 and 100. A value of 100 sets the quality to maximum. A value of 1 sets the speed to its maximum and allows the quality to decrease to the minimum allowed by the decompressor. The decompressor is free to ignore this hint. 

Default 100

Notes The JPEG decompressor will increase speed by decreasing the number of quantized coefficients that it uses in reconstruction. 

IGNORE_HISTORY

Description Some JPEG bitstreams contain images that define tables (Huffman and/or Quantization) and images that use tables defined in previous images.  These bitstreams are not, in general, randomly seekable, because it is possible to backup to a point where the required tables for decoding the next image have not been loaded into the decoder.  The JPEG decoder detects such bitstreams. 

Access set-only

Type Xil_boolean

Values FALSE: The decoder will set the RandomAccess attribute of such CISs to FALSE (i.e., xil_cis_get_random_access(3) returns FALSE), and it is impossible to seek backwards.  TRUE: The function xil_cis_get_random_access(3) returns TRUE, regardless of the type of bitstream, and it is always possible to seek backwards.  If IGNORE_HISTORY is set to TRUE, the application should not seek forward beyond frames that contain table definitions if those definitions are needed for subsequent decoding; the decoder will not ensure that these table definitions are loaded. 

Default FALSE

Notes If this attribute is set to TRUE, it is the responsibility of the application to seek to a spot in the bitstream that will decode correctly (either the image defines its own tables, or it depends on tables that have been most recently loaded into the decoder).  If you have a CIS that is randomly seekable and you never back up, you can seek forward to any frame and get the correct answer, regardless of the setting of IGNORE_HISTORY.  If you have a CIS that is randomly seekable and if IGNORE_HISTORY is FALSE, you can seek forward to any frame and get the correct answer (regardless of whether you have ever backed up).  If you have a CIS that is randomly seekable and if the attribute is TRUE, and if you have ever backed up, you need to control the loading of Q tables yourself by explicitly decompressing the frames that contain the tables. This is only practical if (1) you are decompressing every frame, or (2) you know the location of the Q tables because you glued together two CISs so that you know the location of the boundary.

EXAMPLES

The following example opens and closes a JPEG CIS using the XIL library:

XilSystemState State;
XilCis cis;
State = xil_open();
cis = xil_cis_create(State, "Jpeg");
 -- calls to Jpeg-specific compression routines --
 xil_cis_destroy(cis);
xil_close(State);

The following example sets a JPEG CIS attribute called ENCODE_INTERLEAVED to TRUE.  Note that because this attribute is not a structure, it is not necessary to pass the address of ENCODE_INTERLEAVED when setting it. 

XilCis cis;
xil_cis_set_attribute(cis,"ENCODE_INTERLEAVED", (void ∗) TRUE);

The following example returns the value of a JPEG CIS attribute called ENCODE_INTERLEAVED.  Note that when getting an attribute it is always necessary to pass the address. 

Xil_boolean encode_type;
XilCis cis;
xil_cis_get_attribute(cis, "ENCODE_INTERLEAVED", (void ∗∗) &encode_type);

NOTES

The xil_cis_set_attribute() and xil_cis_get_attribute() calls are used to modify the default behavior of a specific compressor.  Generic attributes of compressors are set by individual function calls.

SEE ALSO

xil_cis_create(3), xil_cis_get_attribute(3), xil_cis_get_bits_ptr(3), xil_compress(3), xil_decompress(3). 

SunOS   —  Last change: 29 July 1993

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026