#include <dvmbasic.h>
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.
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].
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
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
ScImage *ScNew (int w, int h)
Create a new physical ScImage of size w by h blocks and return a pointer to that ScImage.
void ScFree (ScImage *scImage)
Deallocate scImage.
ScImage *ScClip (ScImage *scImage, int x, int y, int w, int h)
Create a virtual ScImage with scImage as the parent. The new ScImage starst at block (x,y) in scImage and w by h blocks. A pointer to the new (virtual) ScImage is returned.
void ScReclip (ScImage *scImage, int x, int y, int w, int h, ScImage *clipped)
This function is identical to ScClip, except that it destructively modifies the virtual ScImage clipped (instead of creating a new virtual ScImage). Warning : memory leaks will occurs if clipped is a physical ScImage.
void ScCopy (ScImage *src, ScImage *dest)
Copy ScImage src into dest. The width and height copied in the minimum of the width and height of src and dest.
void ScCopyDcAc (ScImage *src, ScImage *dest)
This function is similar to ScCopy except that only the DC and AC components of src are copied. The intracoded, skipMB, and skipBlock flags are not copied. This is useful for copying ScImage that originated from JPEG or MPEG I-Frame, since these three flags are not meaningful in them.
void ScIToByte (ScImage *scImage, ByteImage *dest)
This function perform an Inverse DCT on the data in scImage and puts the result into ByteImage dest. It is the programmer's responsibility to ensure that dest is large enough to hold the decoded data. If scImage is of size w by h, dest must be at least 8w by 8h. Assumes scImage contains dequantized values.
void ScPToY (ScImage *scImage, VectorImage *v, ByteImage *prev, ByteImage *dest)
void ScPToUV (ScImage *scImage, VectorImage *v, ByteImage *prev, ByteImage *dest)
These functions perform MPEG P-frame decoding on scImage and store the result into ByteImage dest. These functions use VectorImage v for the motion vectors and prev for the reference frame pixel data.
ScPToY is used to decode the Y plane in MPEG P-frame; ScPToUV is used to decode the U and V planes. In ScPToUV, each vector in v is treated as a motion-vector the corresponding block in scImage; in ScPToY, each vector in v is treated as a motion vector for every 4 blocks in scImage. It is the programmer's responsibility to ensure that dest, v, and prev are of large enough for the operations. Assumes scImage contains dequantized values.
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)
These functions perform MPEG B-frame decoding on scImage and store the result into dest. Both functions use VectorImages fwd and bwd for the forward and backward motion-vectors, and ByteImages past and future for the past and future reference frame pixel data.
ScBToY is used to decode the Y plane in MPEG B-frame; ScBToUV is used to decode the U and V planes. ScBToY treats uses one vector in v for each group of 4 blocks in scImage, whereas ScBToUV uses one vector in v for every block in scImage. It is the programmer's responsibility to ensure that dest, fwd, bwd, past, and future of large enough for the operations. Assumes scImage contains dequantized values.
void ScDequantize(ScImage *scIn, ByteImage *qScale, int *qTable, ScImage *scOut)
Dequantize the values in scIn using quantizer scales in qScale and an 8x8 quantizer matrix qTable into scOut. The matrix qTable is stored in row-major order (not zig-zag order). The dimensions of qScale is equal to the macroblock dimensions of scIn (for Y plane half the width and height of scIn; for U and V planes the same dimensions as scIn). One of the default tables defined above can be used for qTable. scIn and scOut may point to the same ScImage.
When the function completes, every coefficient in scIn will be scaled by q*s/8, where q is obtained from the appropriate entry from qTable, and s is obtained from qScale (at the corresponding location on the image).
void ScNonIDequantize(ScImage *scIn, ByteImage *qScale, int *qTable, int *niqTable, ScImage *scOut)
Dequantize the values in scIn using quantizer scales in qScale and quantizer matrices qTable, niqTable into scOut. Blocks in scIn maybe intra coded or non-intra coded. The dimensions of qScale is equal to the macroblock dimensions of scIn (for Y plane half the width and height of scIn; for U and V planes the same dimensions as scIn). One of the default tables defined above can be used for qTable. and niqTable. scIn and scOut may point to the same ScImage.
void ByteToSc(ByteImage *byteImage, ScImage *scImage)
Perform a discrete cosine transform (DCT) on byteImage, zig-zag encode it, and store the result in scImage. The resulting data in scImage is lossless (up to round-off error) version of byteImage in the DCT domain. To further compress the result use the ScQuantize function described below. For Jpeg encoding, JpegScanEncode will perform this quantization.
void ScQuantize(ScImage *scIn, ByteImage *qScale, int *qTable, ScImage *scOut)
Quantize scIn using the quantizer scales in qScale and a quantizer matrix qTable. The dimensions of qScale is equal to the macroblock dimensions of scIn (for Y plane half the width and height of scIn; for U and V planes the same dimensions as scIn). One of the default tables defined above can be used for qTable. scIn and scOut may point to the same ScImage.
void ByteToScI(ByteImage *byte, ByteImage *qScale, int *qTable, ScImage *sc)
This function is equivalent to calling ByteToSc followed by ScQuantize. It performs DCT tranformation and quantization on the values of byte and outputs them in sc. It is the programmer's responsibility to allocate space for 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)
These functions are used for MPEG P-frame encoding on curr. Using the forward motion vectors in fmv, perform DCT and quantization. For intra coded macroblocks, use qTable for regular I-frame compression on the macroblock of curr. For non-intra coded macroblocks, calculate the difference between the block in curr and the motion-compensated one in prev. Then DCT transform and quantize using niqTable. The exists field in each Vector of fmv determines if the macroblock is intra coded (exists = 0) or non-intra coded (exists = 1). The output is stored in sc which should be allocated by the programmer.
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)
These functions are used for MPEG B-frame encoding on curr. For intra coded macroblocks, use qTable for regular I-frame compression on the macroblock of curr. For non-intra coded macroblocks, calculate the difference values between the macroblock in curr and the interpolated one between prev and next. Then DCT transform and quantize using niqTable. The macroblock may also be skipped and nothing is done. The exists field in each Vector of fmv and bmfdetermines if the macroblock is intra coded (exists = 0), non-intra coded (exists = 1) or skipped (exists = 2). The output is stored in sc which should be allocated by the programmer.
int ScGetX(ScImage *scImage)
int ScGetY(ScImage *scImage)
int ScGetWidth(ScImage *scImage)
int ScGetHeight(ScImage *scImage)
int ScGetVirtual(ScImage *scImage)
Return the appropriate attribute of scImage -- its x or y offset from its parent (non-zero if scImage is virtual), the width and height of scImage in blocks, and whether or not scImage is virtual. Note: these primitives are implemented as macros
ByteImage , VectorImage , JPEG , MPEG
Last updated : Saturday, November 14, 1998, 08:31 PM