Dali : JPEG -- C API

[ Header Files | Types | Constants | Allocation | Decoding | Encoding | Huffman Table | JPEG Header Queries | JPEG Scan Header Queries | JPEG Header Initialization | JPEG Scan Header Initialization | See Also ]

Header Files

#include <dvmjpeg.h>

Type Definitions

JpegHdr

The struct JpegHdr corresponds to the JPEG frame header.

        typedef struct JpegHdr {
            short width;
            short height;
            short restartInterval;
            short numOfQts;
            char precision;
            unsigned char numComps;
            char blockWidth[3];
            char blockHeight[3];
            char qtId[3];          
            char compId[3]; 
            char maxBlockWidth; 
            char maxBlockHeight;
            JpegQt qt[4]; 
            JpegHt ht[4];
        } JpegHdr;
    
width
Width of the image in pixels
height
Height of the image in pixels
restartInterval
The restart interval for MCUs. An MCU (Minimum Coding Unit) is the smallest collection of blocks that correspond to an area in the decoded image. For instance, if the image is interleaved (meaning more than one component is encoded in a scan) and encoded using 4:2:2 subsampling, then for every block in the U and V planes, there are 2 blocks from the Y plane. These four blocks (one from the U plane, one from the V plane, and two from the Y plane) are called an MCU, and correspond to a 16x8 pixel region of the image.

In non-interleaved images (every color plane is stored in a seperate scan), an MCU corresponds to one block.

After every restartInterval MCUs, the predictor value for the DC components is reset to 0 (i.e the DC is not predicted from the previous DC). If restartInverval is 0, then all DC values in the image are predicted. If restartInterval is 1, then all DC values are non-predicted.

numOfQts
Number of quantization tables in this header.
precision
The sample precision - 8 or 12
numComps
The number of components (color planes) in the image. This is typically 1 for gray scale images, or 3 for color images.
blockWidth[i]
Horizontal blocks per MCU of component i
blockHeight[i]
Vertical blocks per MCU of component i
qtid[i]
ID of the quantization table to use for component i
compId[i]
Unique id assigned to component i in the bistream. compId[i] is often equal to i.
maxBlockWidth
The maximum of the blockWidth[] values.
maxBlockHeight
The maximum of the blockHeight[] values.
qt[i]
The ith quantization table in the bitstream (see the JpegQt type below). The total number of quantization table used is given by numOfQts.
ht[i]
The ith Huffman table in the bitstream. (see the JpegHt type below).

JpegQt

JpegQt holds the information about the quantization table of a JPEG image.

     typedef struct JpegQt {
        char precision;
        short v[64];
     } JpegQt;
    
precision
The precision of the quantization factors - either 8 or 16.
v[]
Array of quantization factors in row major order.

JpegHt

A JpegHt holds the information about the Huffman table of a JPEG image. The information is this representation is packed in the same way as in JPEG bitstreams.

        typedef struct JpegHt {
            int valid;
            unsigned char dcBits[16];
            unsigned char *dcVals;
            unsigned char acBits[16];
            unsigned char *acVals;
        } JpegHt;
    
valid
This slot indicates if this huffman table is used or not. The last bit is set if the DC table is valid; the second last bit is set if the AC table is valid. In other words, valid == 3 if both DC and AC table are valid, valid == 2 if only AC table is used, valid == 1 if only DC table is used, and valid == 0 if both table are invalid.
dcBits,dcVals
The DC table as seen in the bitstream.
acBits,acVals
The AC table as seen in the bitstream.

JpegScanHdr

JpegScanHdr maintains data from a JPEG scan header. Each scan encodes one or more component (color plane).

     typedef struct JpegScanHdr {
        int numComps;
        char scanid[3];
        char dcid[3];
        char acid[3];
     } JpegScanHdr;
    
numComps
number of components present in this scan
scanid[i]
the component number of the ith scan component (in order of appearance). Note that scanid[i] is the index used to look up all the component information in the JpegHdr
dcid[i]
the id of the dc huffman table to use to decode the ith scan component
acid[i]
the id of the ac huffman table to use to decode the ith scan component

JpegHuffTable

This structure maintains "unpacked" Huffman tables for all components. It is primarily used in encoding. It contains, for each component, 4096 pairs of (code, symbol) for DC coefficients, and 256 pairs (code, symbol) for AC coefficients. There is also a table of 1024 entries specifying the number of bits in the huffman code for AC coefficients.

        typedef struct JpegHuffTable {
            int numOfComponents;
            unsigned short *dcCode;  
            unsigned short *dcSymbol; 
            unsigned short *acCode;  
            unsigned short *acSymbol;
            unsigned char *acNumOfBits;
        } JpegHuffTable;
    
numOfComponents
Number of components in this JPEG file. This is usually 3 (for Y, U, V) although other values are possible.
dcCode
An array of numOfComponents*4096 elements, containing the codes for dc coefficients. The codes for components i (0,1,2,..) starts at position i*4096.
dcSymbol
An array of numOfComponents*4096 elements, containing the symbols for dc coefficients. The symbols for components i (0,1,2,..) starts at position i*4096.
acCode
An array of numOfComponents*256 elements, containing the codes for ac coefficients. The codes for component i (0,1,2,..) starts at position i*256.
acSymbol
An array of numOfComponents*256 elements, containing the symbols for ac coefficients. The symbols for component i (0,1,2,..) starts at position i*256.
acNumOfBits
An array of numOfComponents*1024 elements, containing the table for the number of bits of huffman code. The elements for component i (0,1,2,..) start at position i*1024.

Constants

Return Codes

These are the returned codes from various JPEG operations.

        #define DVM_JPEG_OK 0
        #define DVM_JPEG_INVALID_ID -1
        #define DVM_JPEG_INVALID_PRECISION -2
        #define DVM_JPEG_WRONG_COMPONENTS -3
        #define DVM_JPEG_INVALID_WIDTH -4
        #define DVM_JPEG_INVALID_HEIGHT -5
        #define DVM_JPEG_INVALID_MARKER -6
        #define DVM_JPEG_AC_UNSUPPORTED -7
    

Operators

Allocation

JpegHdr *JpegHdrNew()

void JpegHdrFree (JpegHdr *hdr)

JpegScanHdr *JpegScanHdrNew ( )

void JpegScanHdrFree (JpegScanHdr *scanHdr)


Decoding

int JpegHdrParse (BitParser *bp, JpegHdr *hdr)

int JpegScanHdrParse (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr)

int JpegScanParse (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr, ScImage *scans[], int num)

int JpegScanSelectiveParse (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr, ScImage *scans[], int num)

int JpegScanIncParseStart (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr, ScImage *scans[], int num)

int JpegScanIncParse (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr, int howMany, ScImage *scans[], int num)

int JpegScanIncParseEnd (BitParser *bp, JpegHdr *hdr, JpegScanHdr *scanHdr, ScImage *scans[], int num)


Encoding

int JpegHdrHtEncode (JpegHdr *hdr, BitParser *bp)

int JpegHdrQtEncode (JpegHdr *hdr, BitParser *bp)

int JpegHdrEncode (JpegHdr *hdr, int baseline, BitParser *bp)

int JpegScanHdrEncode (JpegHdr *hdr, JpegScanHdr *scanHdr, BitParser *bp)

int JpegScanEncode (JpegHdr *hdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable, ScImage *scans[], int num, BitParser *bp)

int JpegScanEncode420 (JpegHdr *hdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable, ScImage *scY, ScImage *scU, ScImage *scV, BitParser *bp)

int JpegScanEncode422 (JpegHdr *hdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable, ScImage *scY, ScImage *scU, ScImage *scV, BitParser *bp)

int JpegScanIncEncode420 (JpegHdr *hdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable, ScImage *scY, ScImage *scU, ScImage *scV, BitParser *bp)

int JpegScanIncEncode422 (JpegHdr *hdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable, ScImage *scY, ScImage *scU, ScImage *scV, BitParser *bp)

int JpegStartCodeEncode (BitParser *bp)

int JpegEndCodeEncode (BitParser *bp)


Huffman Table

JpegHuffTable *JpegHuffTableNew (int numOfComponents)

void JpegHuffTableInit (JpegHdr *jpegHdr, JpegScanHdr *scanHdr, JpegHuffTable *huffTable)

void JpegHdrHuffTableFree huffTable


JPEG Header Queries

short JpegHdrGetWidth (JpegHdr *hdr)
short JpegHdrGetHeight (JpegHdr *hdr)
short JpegHdrGetRestartInterval (JpegHdr *hdr)
unsigned char JpegHdrGetNumOfComponents (JpegHdr *hdr)
unsigned char JpegHdrGetPrecision (JpegHdr *hdr)
unsigned char JpegHdrGetMaxBlockHeight (JpegHdr *hdr)
unsigned char JpegHdrGetMaxBlockWidth (JpegHdr *hdr)

char JpegHdrGetComponentId (JpegHdr *hdr, int i)
char JpegHdrGetQtId (JpegHdr *hdr, int i)
char JpegHdrGetBlockWidth (JpegHdr *hdr, int i)
char JpegHdrGetBlockHeight (JpegHdr *hdr, int i)

short *JpegHdrGetQt(JpegHdr *hdr)


JPEG Scan Header Queries

char JpegScanHdrGetNumOfComponents (JpegScanHdr *hdr)
char JpegScanHdrGetScanId (JpegScanHdr *hdr, int i)
char JpegScanHdrGetDcId (JpegScanHdr *hdr, int i)
char JpegScanHdrGetAcId (JpegScanHdr *hdr, int i)


JPEG Header Initialization

void JpegHdrSetWidth (JpegHdr *hdr)
void JpegHdrSetHeight (JpegHdr *hdr)
void JpegHdrSetNumOfComponents (JpegHdr *hdr)
void JpegHdrSetPrecision (JpegHdr *hdr)
void JpegHdrSetRestartInterval (JpegHdr *hdr)

void JpegHdrStdQtInit (JpegHdr *hdr)

void JpegHdrStdHtInit (JpegHdr *hdr)

void JpegHdrSetQt (JpegHdr *hdr, int id, int precision, short qList[])

void JpegHdrSetQtIds (JpegHdr *hdr, char qtIdList[], int n);

char JpegHdrSetComponentId(JpegHdr *hdr, int i, int id)
char JpegHdrSetQtId(JpegHdr *hdr, int i, int id)

char JpegHdrSetBlockWidth(JpegHdr *hdr, int i, int width)
char JpegHdrSetBlockHeight(JpegHdr *hdr, int i, int height)

void JpegHdrSetMaxBlockHeight (JpegHdr *hdr)
void JpegHdrSetMaxBlockWidth (JpegHdr *hdr)

void JpegHdrSetBlockWidths(JpegHdr *hdr, char widths[], int n);

void JpegHdrSetBlockHeights(JpegHdr *hdr, char heights[], int n);


JPEG Scan Header Initialization

char JpegScanHdrSetNumOfComponents(JpegScanHdr *hdr, int n)
char JpegScanHdrSetScanId(JpegScanHdr *hdr, int i, int id)
char JpegScanHdrSetDcId(JpegScanHdr *hdr, int i, int id)
char JpegScanHdrSetAcId(JpegScanHdr *hdr, int i, int id)

void JpegScanHdrSetScanIds(JpegScanHdr *scanHdr, char scanIds[], int n);

void JpegScanHdrSetDcIds(JpegScanHdr *scanHdr, char dcIds[], int n);

void JpegScanHdrSetAcIds(JpegScanHdr *scanHdr, char acIds[], int n);


See Also

ScImage , BitParser , ByteImage


Last updated : Saturday, November 14, 1998, 07:50 PM