Chapter 25. Using Compression Library Algorithms and Parameters

This chapter describes how to use the Compression Library algorithms and parameters.

In this chapter:

Using the Compression Library Algorithms

This section describes how to use the algorithms that are supplied with libcl. See Chapter 26, “Customizing the Compression Library,” for information on adding and using your own algorithms.

To use one of the algorithms supplied with libcl, you need to select an appropriate algorithm for your application and specify it in the compress or decompress routines.

Choosing a Compression Library Algorithm

Perhaps the most important aspect of developing an application that uses libcl is selecting the appropriate algorithm to use for the application. The algorithm affects the data size and quality and the rate of compression and decompression, so it is important to consider how an algorithm will affect the end result and to consider whether a particular algorithm will achieve the desired effect. A certain amount of experimentation may be necessary.

If you are interested in a particular quality level, you need to set the compression ratio to achieve that quality; if you are primarily interested in a particular data size or data rate, you need to set the compression ratio to achieve the desired data size or rate.

Here are some suggestions for typical application categories:


Note: The performance is quoted for Indigo workstations with 33Mhz MIPS® R3000® processors only.


  • Algorithms for Multimedia Information Delivery Applications

    Video 

    The key factors to consider when choosing a video compression algorithm for multimedia applications are playback speed, data size or rate, and quality.

    MPEG gives the best video quality for a given data size or rate, but playback speed is limited by the CPU. MVC1 is usually the best choice if MPEG is not fast enough. If an expensive frame-by-frame VCR is not available, recording in real time to disk is important, which can be done with RTR1.

    Audio 

    μ-law and A-law audio compression are appropriate for some movies. If higher quality is desired, a license for Aware Inc.'s audio compression can be obtained (see Aware (5)).

  • Algorithms for Telecommunications Applications

    Video 

    The key factors to consider when choosing a video compression algorithm for video/voice mail, video teleconferencing, and other telecommunications applications are the combined compression-decompression speed, data size/rate, and to a lesser extent, quality.

    MVC1 gives the best result for video of about 10 frames per second for a 160 by 120 frame size at the cost of a very high data rate. More performance can be achieved by using grayscale.

    Audio 

    Either μ-law or A-law audio compression at 8KHz can be used with satisfactory results, or the audio can be left uncompressed if the degradation in sound quality is such that it renders the voice data unusable.

  • Algorithms for Previewing Animations

    Video 

    The key factors when choosing a video compression algorithm for previewing 2D and 3D animations are playback speed, quality, and, to a lesser extent, data size/rate. MVC1 gives the appropriate speed and quality.

    Audio 

    Audio compression is usually not an issue for these applications.

  • Algorithms for Editing Movies

    Video 

    The key factors to consider when choosing a video compression algorithm for movie editing applications are decompression speed, image quality, data size/rate, and compression speed.

    For motion video applications, MVC1 is the best choice, especially when the playback is provided by the MoviePlayer tool. MVC1 provides rapid decompression. Playback speed can be traded off with image quality. When recording from video hardware to disk, recording in real time to disk is important if a frame-by-frame VCR is not available—leading to the use of RTR1

    Audio 

    The current audio compression algorithms are not particularly suited to editing. Uncompressed audio is recommended.

Table 25-1 summarizes the compression and performance relationships of the image and motion video algorithms. Compression, decompression, and codec performance measurements are in frames per second (FPS), as measured for 320 by 240 frames on Indigo workstations with 33Mhz MIPS R3000 processors only.

Table 25-1. Capabilities of Image and Video Algorithms




Algorithm

Typical
compression
ratio from
24-bit RGB

Average
bits
per
pixel

Bits per
second at
15 frames
per second

Bytes
per
frame
compression




Compress




Decompress[a]




Codec

Uncompresse d

1:1

24

27.65Mb

230.4KB

 

 

 

RLE 8 bit

4.8:1

5

5.76Mb

48KB

6 FPS

11.5 FPS

3.9 FPS

MVC1

5.33:1

4.5

5.2Mb

43.2KB

3 FPS

25 FPS

2.8 FPS

MVC1
Grayscale

8:1

3

3.456Mb

28.8KB

7 FPS

28 FPS

5.6 FPS

RTR1

6:1

4

4.608Mb

38.4KB

NYM[b]

2.5 FPS

2.0 FPS

RTR1
Grayscale

9:1

2.67

3.072Mb

25.6KB

NYM

8 FPS

NYM

JPEG

16:1

1.5

1.728Mb

14.4KB

1.1 FPS

1.8 FPS

0.7 FPS

MPEG

48:1

0.5

0.576Mb

4.8KB

<< 1 FPS

4.75 FPS

<<1 FPS

[a] Decompressed frame per second is the measured performance, including reading the data from disk, decompressing it, and writing it to the screen.

[b] NYM—Not Yet Measured.


Querying Compression Library Algorithms

This section explains how you can get a list of available algorithms for an audio or video compressor or decompressor, along with the name and type of algorithm, or find the identifier for an algorithm given its name. Other features of the algorithms can also be queried by the application at run time. Querying algorithms, rather than having hard-coded setups, makes it possible to have an algorithm-independent interface, which lets you take advantage of future algorithms as they are implemented without redesigning your code.

Getting a List of Algorithms

Use clQueryAlgorithms() to get a list of algorithms for the compressor or decompressor identified by handle. clQueryAlgorithms() returns the size of the buffer needed to contain the list of algorithms and their types.

If the size of the algorithmTypeBuffer is smaller than the returned value, a partial list of the algorithms and their types is returned, and you must enlarge the algorithmTypeBuffer in order to receive a complete list.

The function prototype for clQueryAlgorithms() is:

int clQueryAlgorithms ( int algorithmMediaType,
                        int *algorithmTypebuffer, int bufferLength )

where:

algorithmMediaType 


is the media type of the algorithm, which can be either of the following values:

CL_AUDIO

specifies an audio algorithm

CL_VIDEO

specifies a video algorithm


algorithmTypeBuffer  


is a pointer to an array of ints into which clQueryAlgorithms() can write algorithm name/type pairs for each parameter associated with handle. The even (0,2,4,...) entries receive the algorithm name. The odd entries (1,3,5,...) receive the types. The returned types take on one of three values:


bufferLength 

is the length of the buffer, in ints, pointed to by paramValueBuffer. If bufferLength is zero, then paramValueBuffer is ignored and only the return value is valid.

Getting an Algorithm Scheme or Name

Use clQuerySchemeFromHandle() or clQuerySchemeFromName() to return the algorithm scheme identifier used by the other compression functions. Use clGetAlgorithmName() to return the algorithm name. Their function prototypes are:

int clQuerySchemeFromHandle(CLhandle handle)
int clQuerySchemeFromName(int algorithmMediaType, char *name)
char *clGetAlgorithmName(int scheme)

where:

handle 

is a handle to a compressor or a decompressor

algorithmMediaType 


is the media type of the algorithm, which can be either of the following values:


name 

is the algorithm name

scheme 

is the algorithm scheme

Example 25-1 demonstrates how to query the CL for a list of algorithms—in this case, video algorithms. The necessary buffer size is returned in the first call to clQueryAlgorithms(), then malloc() is used to allocate enough buffer space to store the returned list of video algorithms.

Example 25-1. Getting a List of Compression Library Algorithms

#include <dmedia/cl.h>
#include <malloc.h>

int *buffer, bufferLength;
char *name;
/*
* Get a buffer containing all the video algorithms and types
*/
bufferLength = clQueryAlgorithms(CL_VIDEO, NULL, 0);
buffer = (int *)malloc(bufferLength * sizeof(int));
clQueryAlgorithms(CL_VIDEO, buffer, bufferLength);

scheme = clQuerySchemeFromName(handle);
name = clGetAlgorithmName(scheme);


Getting License Information

Use clQueryLicense() to obtain license information about an algorithm. The returned message is text intended for inclusion in a message box that is displayed for a user, explaining how to license an algorithm. Failure returns the license error code.

The function prototype is:

int clQueryLicense ( int scheme, int functionality,
                     char **message)

where:

scheme 

is the algorithm scheme.

functionality 

is the type of algorithm, which can be one of:

  • CL_COMPRESSOR for compression

  • CL_DECOMPRESSOR for decompression

  • CL_CODEC for both compression and decompression

message 

is a pointer to a returned pointer to a character string containing a message.

Using the Compression Library Parameters

The CL has a group of routines for working with a set of state variables called “parameters” that are unique for each instantiation. These routines are similar to a set of routines in the audio library. You can get and set parameters, either individually or as a group; however, all of the parameters have reasonable defaults that are algorithm-dependent and need not be set.

The Compression Library works with data that is contained in frames. A frame is defined as a sample in time so that:

1 audio sample: 

mono 8 bit = 1 byte
mono 16 bit = 2 bytes
stereo 8 bit = 2 bytes
stereo 16 bit = 4 bytes

1 video frame: 

width * height * components * bitsPerComponent/8 = n bytes

Compression Library Parameter Definitions

Parameters provide state information about frame characteristics, data formats, and algorithms for each compressor/decompressor.

These parameters provide information about image frame dimensions:

CL_IMAGE_WIDTH 


The spatial width of a sample (not relevant for audio); the video default is 320, and the audio default is 1.

CL_IMAGE_HEIGHT 


The spatial height of a sample (not relevant for audio); the video default is 240, and the audio default is 1.

These parameters describe data formats:

CL_ORIGINAL_FORMAT 


On compression, this is the format of the original audio or video. On decompression, this is the format that you want after decompression. The value is a symbolic constant from one of the following lists, depending on its data type:

Video values are: CL_RGB, CL_RGBX (default), CL_RGBA, CL_RGB332, CL_GRAYSCALE, CL_YUV, CL_YUV422, or CL_YUV422DC.

Audio values are: CL_MONO or CL_STEREO_INTERLEAVED (default).

CL_INTERNAL_FORMAT 


Some video algorithms have several “natural” formats that can be compressed without color space conversion. This parameter allows the selection of one of these formats. The video default is algorithm-specific. Not relevant for audio.

CL_COMPONENTS 


A read-only value, as determined by CL_ORIGINAL_FORMAT, that indicates the number of components in the data. For example, audio is 1 for mono, and 2 for stereo, video is generally 1 for grayscale, and 3 or 4 for color. The audio default is 2; video default is 4.

CL_BITS_PER_COMPONENT 


The number of bits per component. For example, audio data is either 8-bit or 16-bit, video is generally 8-bit. The audio default is 16; video default is 8.

CL_ORIENTATION 


Specifies the orientation of compressed data, which can be either:

The orientation of compressed data is always top down. When specifying compression or decompression, the original format (or final format) of the data may be bottom up. Specify this inversion by setting the CL_ORIENTATION parameter to CL_BOTTOM_UP instead of the default.

These parameters describe buffer sizes and characteristics:

CL_FRAME_BUFFER_SIZE 


The maximum size, in bytes, of the frame buffer. If clDecompress() is called with numberOfFrames larger than 1, this value should be the frame size × numberOfFrames. Because this is almost always true for audio, CL_FRAME_BUFFER_SIZE should be set when doing audio decompression.

CL_COMPRESSED_BUFFER_SIZE 


The maximum size of the compressed data buffer. The default is calculated as the maximum possible size, taking into account all the factors such as algorithm, encoding method, data type, and so on. If you want to try to use a smaller buffer, you can set this value explicitly. If clCompress() is called with numberOfFrames larger than 1, this value should be the maximum compressed size of one frame × numberOfFrames. Because this is almost always true for audio, CL_COMPRESSED_BUFFER_SIZE should be set when doing audio compression.

CL_NUMBER_OF_FRAMES 


The number of frames in the sequence.

CL_BLOCK_SIZE 


The natural block size of the algorithm in samples. It is most efficient to specify numberOfFrames to be a multiple of the block size when calling clCompress() or clDecompress().

CL_PREROLL 


The number of blocks of frames that must be supplied to clDecompress() before decompressed frames will be returned.

CL_FRAME_RATE 


The requested number of frames per second.

CL_FRAME_TYPE 


The decompressor fills in the frame type when it decompresses a frame. Frame type is one of:

CL_KEYFRAME

frame is a keyframe

CL_INTRA

equivalent to CL_KEYFRAME

CL_PREDICTED

frame contains information about its succeeding frames

CL_BIDIRECTIONAL

frame contains information about frames that precede and succeed it


CL_ACTUAL_FRAME_INDEX 


The frame number of the frame most recently decompressed by clDecompress().

These parameters control the compression ratio and/or quality:

CL_ALGORITHM_ID 


A parameter that can be queried to find out the scheme identifier of the algorithm of an open compressor or decompressor.

CL_COMPRESSION_RATIO 


The target compression ratio. Some algorithms (MVC1, JPEG, and MPEG) are tunable, that is, they allow quality to be traded for compression ratio.

CL_EXACT_COMPRESSION_RATIO 


A flag determines whether the compression ratio is a target or must be exact. Some algorithm implementations, such as for JPEG, can be only approximated and can never be exact. For algorithms that do support it, it is generally kept within a small range that over time is guaranteed to average out to the specified compression ratio.

CL_SPEED 

The relative speed of playback. A value of 1.0 for this single-precision floating point value means no change. When this value is greater than 1.0, the algorithm tries to use less CPU time by dropping frames or by reducing the quality.

JPEG has the following additional parameters:

CL_JPEG_COMPONENT_TABLES 


Specifies the IDs of the AC Huffman table, DC Huffman table, and quantization table to be used for each component. Currently, this parameter cannot be changed directly, rather, it is set up automatically for processing the selected CL_INTERNAL_FORMAT.

YUV formats use AC huffman table 0, DC huffman table 0, and quantization table 0 for component 0; AC huffman table 1, DC huffman table 1, and quantization table 1 for components 1 and 2. RGB formats use tables AC table 0, DC table 0, and quantization table 0 for all components.

CL_JPEG_QUANTIZATION_TABLES  


Sets or gets the quantization tables to be used. For setting, an unsigned short *qtables[4] argument is specified as the argument to this parameter. For each j, qtables[j] must either be NULL or point to a unsigned short[64] area of memory which represents a JPEG base-line quantization table in natural scan order. The user-specified tables are stored as reference tables, and scaled versions of them based on the current CL_JPEG_QUALITY_FACTOR are downloaded into the codec and become the table associated with the ID j. For getting, the library allocates the memory as described above, and the tables returned to the user are those which are specified by CL_JPEG_COMPONENT_TABLES as being in use and are scaled as indicated by CL_JPEG_QUALITY_FACTOR. The user is responsible for freeing the memory.

CL_JPEG_QUALITY_FACTOR 


A JPEG quantization table scale factor that represents a rough percentage of the image detail preservation. This is one method to control the image loss and therefore the compression ratio for the JPEG algorithm.

Each time the quality factor is set, the reference quantization tables are scaled and downloaded into the codec. The formula used to obtain the scale factor is:

scalefactor = 50/quality          (quality < 50)
scalefactor = 2 - 2*quality/100;  (otherwise)

Using a value of 1 results in coarse quantization, a high compression ratio, and very poor image quality. Using a value of 100 results in the finest possible quantization, a low compression ratio (perhaps even image expansion), and near-perfect image quality. The most useful quality factor is typically in the range of 25–95. The default quality is CL_JPEG_QUALITY_DEFAULT, which represents a good-quality compressed image. Use the value CL_JPEG_QUALITY_NO_SCALE to bypass scaling.

When CL_QUALITY_FACTOR is set, the approximate value of CL_COMPRESSION_RATIO is calculated; when CL_COMPRESSION_RATIO is set, the approximate value of CL_QUALITY_FACTOR is calculated. When decompressing JPEG, clDecompress() fills in this value. The actual compression ratio is determined by the quality factor and the image content and therefore may not be exactly what you expect.

MPEG_VIDEO has the following additional parameters:

CL_END_OF_SEQUENCE 


An end of sequence flag. When the decompressor arrives at the end of the sequence, it sets this flag. The default is FALSE (0).

RTR has the following additional parameters:

CL_QUALITY_LEVEL 


Selects a quantization table. 6 is the highest compression ratio and therefore the worst quality; 0 (default) is the lowest compression ratio and therefore the highest quality.

Table 25-2 lists the parameters and their types, ranges, and defaults.

Table 25-2. Compression Library Parameters

Parameter

Range

Default

CL_ALGORITHM_ID

Current ID

Current ID

CL_ALGORITHM_VERSION

Current version

Current version

CL_BITS_PER_COMPONENT

0–32

Audio: 16

Video: 8

CL_BLOCK_SIZE

0–2 Billion

1, depends on algorithm

CL_COMPONENTS (read only)

0–8

Depends on original format

CL_COMPRESSED_BUFFER_SIZE

0–2 Billion

Maximum amount of compressed data needed for one frame

CL_COMPRESSION_RATIO

Depends on original format and algorithm

Uncompressed 1.0:1

μ-law 2.0:1

A-law 2.0:1

Aware MultiRate I 2–4:1

Aware MPEG 2–4:1

MVC1 5.3:1

JPEG 15.0:1

MPEG Video 48.0:1

RLE 1.0:1

RLE24 1.5:1

RTR 5.0:1

CL_ENABLE_IMAGEINFO
(Cosmo Compress JPEG only)

 

 

CL_END_OF_SEQUENCE
(MPEG_VIDEO only)

0 (FALSE)–1 (TRUE)

0 (FALSE)

CL_EXACT_COMPRESSION_RATIO

0 (FALSE)– 1 (TRUE)

Audio: 0 (FALSE)

Video: 0 (FALSE)

CL_FRAME_BUFFER_SIZE

0–2 Billion

Size of one frame

CL_FRAME_RATE

0–1 Million

Audio: 44100.0

Video: 30.0

CL_FRAME_TYPE

0–2

Supplied by decompressor

CL_IMAGE_HEIGHT

0–1Million

Audio: 1

Video: 320

CL_IMAGE_WIDTH

0–1Million

Audio: 1

Video: 240

CL_INTERNAL_FORMAT

0–max[a]

Audio: CL_STEREO_INTERLEAVED

Video: depends on algorithm

CL_INTERNAL_IMAGE_HEIGHT

 

 

CL_INTERNAL_IMAGE_WIDTH

 

 

CL_JPEG NUM_PARAMS (JPEG only)

0–2 Billion

0 (unknown)

CL_JPEG_QUALITY_FACTOR
(JPEG only)

0–100

75

CL_JPEG_QUANTIZATION_TABLES
(JPEG only)

 

 

CL_LAST_FRAME_INDEX

0–2 Billion

0

CL_NUMBER_OF_FRAMES

 

 

CL_NUMBER_OF_PARAMS

 

 

CL_ORIENTATION

CL_TOP_DOWN to CL_BOTTOM_UP

CL_TOP_DOWN

CL_ORIGINAL_FORMAT

0–max[b]

Audio: CL_STEREO_INTERLEAVED

Video: CL_RGBX

CL_PREROLL

0–2Billion

0, depends on algorithm

CL_RTR_QUALITY_LEVEL (RTR only)

1–6

1

CL_SPEED

0 (stopped) to 2 Billion, depends on algorithm

1.0 (real-time playback)

[a] max = CL_MAX_NUMBER_OF_ORIGINAL_FORMATS.

[b] max = Enumerated type value that depends on the format.


Setting and Querying Compression Library Parameters

After a compressor or decompressor is opened, thus specifying the compression scheme to use, various parameters can be modified using clSetParams(). All of these parameters have reasonable defaults that are algorithm-dependent and need not be set. Some parameters, such as CL_IMAGE_WIDTH and CL_IMAGE_HEIGHT for video compression, should be set, but setting them is not required.

Getting a List of Parameters and Parameter Types

Use clQueryParams() to get a list of valid parameters and their types for a specified a compressor or decompressor. The compressor being queried is identified by its handle. Its function prototype is:

int clQueryParams(CLhandle handle,int *paramValuebuffer, int maxLength)

where:

handle 

is the handle to a compressor or decompressor.

paramValuebuffer 


is a pointer to an array of ints into which clQueryParams() can write parameter identifier/parameter type pairs for each parameter associated with the compressor or decompressor. The even (0,2,4,...) entries receive a string that is the parameter identifier. The odd entries (1,3,5,...) receive the parameter type. Parameter type is one of four values:

  • CL_RANGE_VALUE, meaning that a parameter can assume a range of values in which the relative magnitude of the value is meaningful—that is, increasing values indicate increasing quantities of whatever this parameter controls, and vice-versa.

  • CL_ENUM_VALUE, meaning that a parameter assumes values from an enumerated type. They have a limited range, but there is no inherent relationship between the range values.

  • CL_FLOATING_RANGE_VALUE, meaning that a parameter can assume a range of floating point values, in which the relative magnitude of the value is meaningful—that is, increasing values indicate increasing quantities of whatever this parameter controls, and vice-versa.

  • CL_FLOATING_ENUM_VALUE, meaning that a parameter assumes values from an enumerated type. They have a limited floating point range, but there is no inherent relationship between the range values.

maxLength 

is the length of the buffer, in ints, pointed to by paramValuebuffer. If maxLength is zero, then paramValuebuffer is ignored and only the return value is valid.

clQueryParams() returns the size of the buffer, in ints, needed to hold all the parameter identifier/parameter type pairs for the compressor or decompressor identified by handle. The parameters are returned in the even locations of paramValuebuffer, and their types are returned in the odd locations.

If the size of the paramValuebuffer is smaller than the returned value, a partial list of the parameter identifier/parameter type pairs is returned, making it necessary to enlarge the paramValuebuffer in order to receive a complete list. To avoid this situation, you can obtain the correct size of the buffer by calling clQueryParams() with a NULL buffer pointer and a maxLength of 0 to return the actual buffer length without writing any data.

clQueryParams() also reports whether the parameter is one of a set of enumerated types, any integer number within a specific range, or any floating point number within a specific range. In each case, the values are numbers within the range returned by clGetMinMax() and have the defaults returned by clGetDefault().

Example 25-2 demonstrates how to get a list of parameters for a specified compressor/decompressor.

Example 25-2. Getting a List of Parameters for a Compressor/Decompressor

#include <dmedia/cl.h>
#include <malloc.h>

/*
* Get a buffer containing all the parameters for a specified
* compressor or decompressor.
*/

int *buf, bufferLength;
bufferLength = clQueryParams(handle, 0, 0);
buf = (int *)malloc(bufferLength * sizeof(int));
clQueryParams(handle, buf, bufferLength);


Getting the Parameter ID that Corresponds to a Parameter Name

If you know the name of a parameter, but not its identifier, you can use clGetParamID() to get the identifier of a parameter from its name.

Its function prototype is:

int clGetParamID(CLhandle handle, char *name)

Getting and Setting Parameter Values

You can get or set parameter values as a group or individually.

Use clGetParams() to return the current values for the parameters referenced in the paramValuebuffer array. The values are written into the odd locations of paramValuebuffer immediately after the corresponding parameters.

Use clSetParams() to set the current state of the parameters referenced in the paramValuebuffer array.

To change a state parameter:

  1. Call clQueryParams() to find out which parameters are available.

  2. Call clGetParams() to find out the current state.

  3. Fill in the even entries of the paramValuebuffer array corresponding to the parameters to be changed and then call clSetParams().

The function prototypes are:

void clGetParams ( CLhandle handle, int *paramValuebuffer,
                   int bufferLength )
void clSetParams ( CLhandle handle, int *paramValuebuffer,
                   int bufferLength )

where:

handle 

is a handle that identifies a compressor or decompressor.

paramValuebuffer 


is a pointer to an array of pairs of ints. The even elements of this array select the parameters to be read or changed. The subsequent odd elements are the current or new values of these parameters.

bufferLength 

is the number of ints in the buffer pointed to by paramValuebuffer.

Alternatively, parameters can be changed individually with clSetParam() and clGetParam(). clGetParam() returns the current value of the parameter. clSetParam() returns the previous value of the parameter.

The function prototypes are:

int clGetParam(CLhandle handle, int paramID)
int clSetParam(CLhandle handle, int paramID, int value)

where:

handle 

is a handle that identifies a compressor or decompressor.

paramID 

is the identifier of the parameter to get or set.

value 

is the new value of the parameter.

Example 25-3 demonstrates how to extract the current value of specific parameters from a list of parameters returned as a group. In this case, the current block size and preroll values are obtained from the list of parameters that are returned in paramValuebuffer from clGetParams().

Example 25-3. Getting the Current Values of Selected Parameters

#include <dmedia/cl.h>
...
/* Get the block size and preroll */
int paramValueBuffer[][2] = {
CL_BLOCK_SIZE, 0,
CL_PREROLL, 0
};
clGetParams(handle, (int *)paramValueBuffer,
sizeof(paramValueBuffer) / sizeof(int));
/* paramValueBuffer[0][1] is the block size */
/* paramValueBuffer[1][1] is the preroll */


Getting or Setting the Value of a Floating Point Parameter

Some parameters, such as CL_COMPRESSION_RATIO and CL_FRAME_RATE, are floating point values. You don't have to cast expressions involving floating point values, because macros are provided within libcl that handle the conversions for you; even though a value is a float you can cast to an int. To set a floating point value, use the macro CL_TypeIsInt(); to retrieve a floating point value, use the macro CL_TypeIsFloat().

The argument must be a variable, because the type definitions in /usr/include/dmedia/cl.h are:

float 

*(float *) &value

int 

*(int *) &value

Example 25-4 demonstrates how to use the libcl macros to get/set a floating point parameter value.

Example 25-4. Using Macros to Get or Set the Value of a Floating Point Parameter

float number;
number = 3.0;
...
clSetParam(handle, CL_COMPRESSION_RATIO, CL_TypeIsInt(number));
number = CL_TypeIsFloat(clGetParam(handle,CL_COMPRESSION_RATIO));


Getting or Setting Individual Parameter Attributes

You can query parameters individually to get the name, defaults, and range of valid values, given the parameter identifier and a handle.

Use clGetName() to return a pointer to a null-terminated string that supplies the English name of a parameter. Its function prototype is:

char* clGetName(CLhandle handle, int param)

where:

handle 

is a handle that identifies a compressor or decompressor.

param 

is a parameter identifier.

Use clGetDefault() to return the default value of the parameter specified by param. Use clSetDefault() to set the default value. Setting the default value is particularly useful when an algorithm has been added and new defaults need to be set.

The function prototypes are:

int clGetDefault(CLhandle handle, int param)
int clSetDefault(int scheme, int paramID, int value)

where:

handle 

is a handle that identifies a compressor or decompressor.

paramID 

is a parameter identifier.

scheme 

is the identifier of the scheme for which to set the defaults.

value 

is the new default value associated with param.

Example 25-5 demonstrates how to get and set defaults for a parameter. In this case, the default for the CL_ORIGINAL_FORMAT parameter is set to CL_RGBX for the specified decompressor.

Example 25-5. Getting and Setting Parameter Defaults

#include <dmedia/cl.h>
int default;
...
clOpenDecompressor(scheme, &handle);
...
default = clGetDefault(handle, CL_ORIGINAL_FORMAT);
clSetDefault(scheme, CL_ORIGINAL_FORMAT, CL_RGBX);
...

Use clGetMinMax() to get the maximum and minimum values for a parameter. Use clSetMin() and clSetMax() to set new minimum and maximum parameter values, or to establish the minimum and maximum values when adding a new algorithm.

The function prototypes are:

int clGetMinMax ( CLhandle handle, int param, int *minParam,
                  int *maxParam)

int clSetMin(int scheme, int paramID, int min)
int clSetMax(int scheme, int paramID, int max)

where:

handle 

is a handle that identifies a compressor or decompressor.

paramID 

is a parameter identifier.

minParam 

is a pointer to the parameter into which clGetMinMax() can write the minimum value associated with paramID.

maxParam 

is a pointer to the parameter into which clGetMinMax() can write the maximum value associated with paramID.

scheme 

is the identifier of the scheme that is to have its minimum or maximum value changed.

min 

is the new minimum value associated with paramID.

max 

is the new maximum value associated with paramID.

Example 25-6 demonstrates how to get and set the minimum and maximum values of a particular parameter for the specified compressor or decompressor.

Example 25-6. Getting and Setting Minimum and Maximum Parameter Values

#include <dmedia/cl.h>
int oldMin, oldMax;
...
clOpenDecompressor(scheme, &handle);
6
...
clGetMinMax(handle, CL_ORIGINAL_FORMAT, &oldMin, &oldMax);
clSetMin(scheme, CL_ORIGINAL_FORMAT, CL_RGB);
clSetMax(scheme, CL_ORIGINAL_FORMAT, CL_RGB332);
...


Using Frame Type Parameters

Some compression algorithms do not allow direct compression or decompression of an arbitrary frame. These algorithms—MPEG, CCITT H.261, and so on—have blocks of frames, where each frame can be decompressed only if all previous frames in the block have been decompressed. The frame at the beginning of the block is called a keyframe.

A frame can be queried for its status as a keyframe by using the CL_FRAME_TYPE state parameter. Legal values are CL_KEYFRAME (or CL_INTRA), CL_PREDICTED, and CL_BIDIRECTIONAL. Predicted frames use information from a previous keyframe, bidirectional frames use information from both previous and future reference frames, where a reference frame is either of the other two types—CL_KEYFRAME or CL_PREDICTED.The Compression Library interface allows keyframe control from the application.

Some algorithms contain only keyframes, such as JPEG, MVC1, RTR, RLE, G.711, and so on. MPEG Video is the only algorithm currently supported that has all three types of frames.