Dali: ScImage -- C API

[ Header Files | Types | Constants | Allocation | Initialization | Decoding | Encoding | Queries | See Also ]

Header Files

#include <dvmbasic.h>

Type Definitions

ScImage

An ScImage ("semi-compressed image") is a two-dimensional array of ScBlocks (see the typedef below). Each ScBlock corresponds to an 8x8 array of DCT coefficients -- a representation that occurs in compression standards such as MPEG, H.261, H.263, and JPEG. The ScImage represents the entire image in the DCT domain.

The coefficients in an ScImage are often scaled using a quantization table (an array of 64 coefficients). That is, each coefficient is divided by the corresponding integer in the quantization table, and the result is rounded. Dali provides constants for the recommended quantization tables from the JPEG and MPEG standards. The functions Sc*Quantize scale the coefficients; the functions Sc*Dequantize descale the coefficients.

Since each element in an ScImage corresponds to an 8x8 pixel block, the width and height of an ScImage are 1/8 of the width and height (rounded up) of the corresponding ByteImage. For example, if a ByteImage is 40x36, the corresponding ScImage is 5x5.

An ScImage is similar to a ByteImage in that both physical and virtual ScImages can be created. Using a virtual ScImage, you can decompress or replace part of a compressed image (e.g., the central portion of a JPEG image) without decompressing the entire image. To make these operations possible, the ScBlocks in an ScImage are stored as dequantized values and have no dependencies between them.

We plan to support other compressed domain operations, such as scaling, on ScImages in future releases.

    typedef struct ScImage {
        int width;
        int height;
        int x;
        int y;
        int parentWidth;
        unsigned char isVirtual;
        ScBlock *firstBlock;
    } ScImage;
  
width
the width of the ScImage in terms of ScBlocks
height
the height of the ScImage in terms of ScBlocks
x
the x-offset of the top-left corner of the ScImage from it's parent (non-zero only for virtual ScImages).
y
the y-offset of the top-left corner of the ScImage from it's parent (non-zero only for virtual ScImages).
parentWidth
For virtual ScImages, the width of the parent ScImage. For physical ScImages, the same as the width (should be called rootWidth since the parent might not be physical)
isVirtual
1 iff the ScImage is virtual. 0 otherwise.
firstBlock
pointer to the first block in the buffer.

ScBlock

An ScBlock is a structure that stores information about a block in a ScImage. The values are stored in zig-zag scan order, and are dequaantized. Since ScBlocks are typically derived from run-length encoded blocks, the DCT values are stored as (index, value) pairs. Index indicates the position of the non-zero coefficient, value its (dequantized) value.

    typedef struct ScBlock {
        int  intracoded;
        char skipMB;
        char skipBlock;
        short dc;
        char  numOfAC;
        char  index[63];
        short value[63];
    } ScBlock;
  
intracoded
1 iff this block is an intracoded block in an MPEG P-frame or B-frame, 0 otherwise. This flag is uninitialized for MPEG I-frames and JPEG since all blocks is intracoded.
skipMB
1 iff this block is part of a skipped macroblock, 0 otherwise. This flag is uninitialized for MPEG I-frame and JPEG since every block is coded. For MPEG P-frames and B-frames, if this flag is set the coefficient data (dc, numOfAC, index, and value) is not valid.
skipBlock
1 iff this block is a skipped block, 0 otherwise. This flag is uninitialized for MPEG I-frame and JPEG since every blocks is coded. For MPEG P-frames and B-frames, if this flag is set the coefficient data (dc, numOfAC, index, and value) is not valid.
dc
DC component of this block.
numOfAC
number of AC components in this block.
index[63]
an array of numOfAC indices (in zig-zag order) where the AC value is non-zero.
value[63]
an array of numOfAC non-zero AC value. The AC component at position index[k] has value value[k].

Constants

Return Codes

Return code from various SC primitives. DVM_SC_OK indicates the primitives executed succesfully. DVM_SC_ERROR indicates some error has occurs.

    #define DVM_SC_OK 0
    #define DVM_SC_ERROR 1
  

Quantization Matrices

Pointers to default 8 by 8 quantzation matrices.

    #define JPEG_LUM       default_jpeg_y_quant
    #define JPEG_CHROM     default_jpeg_uv_quant
    #define MPEG_INTRA     default_mpeg_intra_quant
    #define MPEG_NON_INTRA default_mpeg_non_intra_quant
  

Operators

Allocation

ScImage *ScNew (int w, int h)

void ScFree (ScImage *scImage)

ScImage *ScClip (ScImage *scImage, int x, int y, int w, int h)

void ScReclip (ScImage *scImage, int x, int y, int w, int h, ScImage *clipped)


Initialization

void ScCopy (ScImage *src, ScImage *dest)

void ScCopyDcAc (ScImage *src, ScImage *dest)


Decoding

void ScIToByte (ScImage *scImage, ByteImage *dest)

void ScPToY (ScImage *scImage, VectorImage *v, ByteImage *prev, ByteImage *dest)
void ScPToUV (ScImage *scImage, VectorImage *v, ByteImage *prev, ByteImage *dest)

void ScBToY (ScImage *scImage, VectorImage *fwd, VectorImage *bwd, ByteImage *past, ByteImage *future, ByteImage *dest)
void ScBToUV (ScImage *scImage, VectorImage *fwd, VectorImage *bwd, ByteImage *past, ByteImage *future, ByteImage *dest)

void ScDequantize(ScImage *scIn, ByteImage *qScale, int *qTable, ScImage *scOut)

void ScNonIDequantize(ScImage *scIn, ByteImage *qScale, int *qTable, int *niqTable, ScImage *scOut)


Encoding

void ByteToSc(ByteImage *byteImage, ScImage *scImage)

void ScQuantize(ScImage *scIn, ByteImage *qScale, int *qTable, ScImage *scOut)

void ByteToScI(ByteImage *byte, ByteImage *qScale, int *qTable, ScImage *sc)

void ByteYToScP (ByteImage *curr, ByteImage *prev, VectorImage *fmv, ByteImage *qScale, int *qTable, int *niqTable, ScImage *sc)
void ByteUVToScP(ByteImage *curr, ByteImage *prev, VectorImage *fmv, ByteImage *qScale, int *qTable, int *niqTable, ScImage *sc)

void ByteYToScB (ByteImage *curr, ByteImage *prev, ByteImage *next, VectorImage *fmv, VectorImage *bmv, ByteImage *qScale, int *qTable, int *niqTable, ScImage *sc)
void ByteUVToScB(ByteImage *curr, ByteImage *prev, ByteImage *next, VectorImage *fmv, VectorImage *bmv, ByteImage *qScale, int *qTable, int *niqTable, ScImage *sc)


Queries

int ScGetX(ScImage *scImage)
int ScGetY(ScImage *scImage)
int ScGetWidth(ScImage *scImage)
int ScGetHeight(ScImage *scImage)
int ScGetVirtual(ScImage *scImage)


See Also

ByteImage , VectorImage , JPEG , MPEG


Last updated : Saturday, November 14, 1998, 08:31 PM