Encoder  4.4
VC-5 Sample Encoder
encoder.c File Reference

Functions

bool SetImageFormatDefaults (ENCODER *encoder)
 Set default values for the pattern element structure. More...
 
bool CheckImageFormatParameters (ENCODER *encoder)
 Check for inconsistent values for the parameters specified on the command-line. More...
 
CODEC_ERROR PrepareEncoderState (ENCODER *encoder, const UNPACKED_IMAGE *image, const PARAMETERS *parameters, int input_image_index)
 Prepare the encoder state. More...
 
CODEC_ERROR InitEncoder (ENCODER *encoder, const ALLOCATOR *allocator, const VERSION *version)
 Initialize the encoder data structure. More...
 
CODEC_ERROR EncodeImage (IMAGE *image, STREAM *stream, const PARAMETERS *parameters)
 Encode the image into the output stream. More...
 
CODEC_ERROR EncodeImageList (IMAGE_LIST *image_list, STREAM *stream, const PARAMETERS *parameters)
 Encode the list of images into the bitstream as layers or sections. More...
 
CODEC_ERROR ImageListEncodingProcess (ENCODER *encoder, UNPACKED_IMAGE_LIST *unpacked_image_list, BITSTREAM *bitstream, const PARAMETERS *parameters)
 Apply the encoding process to each image in the unpacked image list. More...
 
CODEC_ERROR EncodeImageLayers (ENCODER *encoder, const UNPACKED_IMAGE_LIST *image_list, BITSTREAM *stream)
 Encode a list of unpacked images as layers.
 
CODEC_ERROR SetEncodingParameters (ENCODER *encoder, PATHNAME_DATA *pathname_data)
 Set the encoding parameters from the information in the pathname data for the encoded image.
 
CODEC_ERROR InitializeImageSectionEncoder (ENCODER *encoder, int section_index)
 Initialize the encoding parameters for an image section.
 
CODEC_ERROR PrepareEncoderImageSection (ENCODER *encoder, const UNPACKED_IMAGE *image, int section_index, ALLOCATOR *allocator, const PARAMETERS *parameters)
 Prepare the encoder to encoder the next image section.
 
CODEC_ERROR EncodeImageSections (ENCODER *encoder, const UNPACKED_IMAGE_LIST *image_list, BITSTREAM *stream, const PARAMETERS *parameters)
 Encode a list of unpacked images as layers.
 
CODEC_ERROR EncodeImageSectionLayers (IMAGE_LIST *image_list, STREAM *stream, const PARAMETERS *parameters)
 Encode the input images as image sections with nested layers. More...
 
CODEC_ERROR ImageSectionLayersEncodingProcess (ENCODER *encoder, UNPACKED_IMAGE_LIST *image_list, BITSTREAM *bitstream, const PARAMETERS *parameters)
 Apply the encoding process to each image in the unpacked image list. More...
 
CODEC_ERROR EncodingProcess (ENCODER *encoder, const UNPACKED_IMAGE *image, BITSTREAM *bitstream, const PARAMETERS *parameters)
 Reference implementation of the VC-5 encoding process. More...
 
CODEC_ERROR PrepareEncoder (ENCODER *encoder, const UNPACKED_IMAGE *image, ALLOCATOR *allocator, const PARAMETERS *parameters, int input_image_index)
 Initialize the encoder using the specified parameters. More...
 
CODEC_ERROR ReleaseEncoderTransforms (ENCODER *encoder, ALLOCATOR *allocator)
 Free the wavelet transforms allocated for the encoder.
 
CODEC_ERROR ReleaseEncoder (ENCODER *encoder)
 Free all resources allocated by the encoder.
 
CODEC_ERROR EncodeSingleImage (ENCODER *encoder, const UNPACKED_IMAGE *image, BITSTREAM *stream)
 Encode a single image into the bitstream. More...
 
CODEC_ERROR EncodeMultipleFrames (ENCODER *encoder, IMAGE *image_array[], int frame_count, BITSTREAM *stream)
 Encode multiple frames as separate layers in a sample. More...
 
CODEC_ERROR PrepareEncoderTransforms (ENCODER *encoder)
 Initialize the wavelet transforms for encoding.
 
CODEC_ERROR ImageUnpackingProcess (const PACKED_IMAGE *input, UNPACKED_IMAGE *output, const PARAMETERS *parameters, ALLOCATOR *allocator)
 Unpack the image into component arrays for encoding.
 
CODEC_ERROR ImageListUnpackingProcess (PACKED_IMAGE_LIST *packed_image_list, UNPACKED_IMAGE_LIST *unpacked_image_list, const PARAMETERS *parameters, ALLOCATOR *allocator)
 
CODEC_ERROR UnpackImage (const PACKED_IMAGE *input, UNPACKED_IMAGE *output, ENABLED_PARTS enabled_parts)
 Unpack the image into component arrays.
 
CODEC_ERROR UnpackImageRow (uint8_t *input_row_ptr, DIMENSION image_width, PIXEL_FORMAT pixel_format, PIXEL *output_row_ptr[], PRECISION bits_per_component[], int channel_count, ENABLED_PARTS enabled_parts)
 
CODEC_ERROR EncodeBitstreamHeader (ENCODER *encoder, BITSTREAM *stream)
 Insert the header segments that are common to all samples. More...
 
CODEC_ERROR EncodeBitstreamTrailer (ENCODER *encoder, BITSTREAM *stream)
 Write the trailer at the end of the encoded sample. More...
 
CODEC_ERROR EncodeExtensionHeader (ENCODER *encoder, BITSTREAM *stream)
 Write extra information that follows the sample header into the bitstream. More...
 
CODEC_ERROR EncodeExtensionTrailer (ENCODER *encoder, BITSTREAM *stream)
 Write the sample extension trailer into the bitstream. More...
 
CODEC_ERROR EncodeMultipleChannels (ENCODER *encoder, const UNPACKED_IMAGE *image, BITSTREAM *stream)
 Encode the portion of a sample that corresponds to a single layer. More...
 
CODEC_ERROR EncodeLayerHeader (ENCODER *encoder, BITSTREAM *stream, COUNT layer_number)
 Write the sample layer header. More...
 
CODEC_ERROR EncodeLayerTrailer (ENCODER *encoder, BITSTREAM *stream)
 Write the sample layer trailer. More...
 
CODEC_ERROR EncodeChannelWavelets (ENCODER *encoder, BITSTREAM *stream)
 Encode the channel into the bistream. More...
 
CODEC_ERROR EncodeChannelHeader (ENCODER *encoder, int channel_number, BITSTREAM *stream)
 Write the channel header into the bitstream. More...
 
CODEC_ERROR EncodeChannelSubbands (ENCODER *encoder, int channel_number, BITSTREAM *stream)
 Write the encoded subbands for this channel into the bitstream. More...
 
CODEC_ERROR EncodeChannelTrailer (ENCODER *encoder, int channel, BITSTREAM *stream)
 Write the channel trailer into the bitstream. More...
 
CODEC_ERROR AllocateEncoderHorizontalBuffers (ENCODER *encoder, int buffer_width)
 Allocate intermediate buffers for the horizontal transform results. More...
 
CODEC_ERROR DeallocateEncoderHorizontalBuffers (ENCODER *encoder)
 Deallocate the intermediate buffers for the horizontal transform results. More...
 
CODEC_ERROR AllocateEncoderUnpackingBuffers (ENCODER *encoder, int frame_width)
 Allocate buffers for unpacking rows of the input frame. More...
 
CODEC_ERROR AllocateHorizontalBuffers (ALLOCATOR *allocator, PIXEL *lowpass_buffer[], PIXEL *highpass_buffer[], int buffer_width)
 Allocate buffers used for computing the forward wavelet transform.
 
CODEC_ERROR DeallocateHorizontalBuffers (ALLOCATOR *allocator, PIXEL *lowpass_buffer[], PIXEL *highpass_buffer[])
 Deallocate buffers used for computing the forward wavelet transform.
 
CODEC_ERROR ShiftHorizontalResultBuffers (ENCODER *encoder)
 Shift the buffers of horizontal highpass results. More...
 
CODEC_ERROR ShiftHorizontalBuffers (PIXEL *lowpass_buffer[], PIXEL *highpass_buffer[])
 Shift the array of buffers of horizontal highpass results. More...
 
CODEC_ERROR TransformForwardSpatialChannel (ENCODER *encoder, const UNPACKED_IMAGE *image, int channel_number)
 Apply the forward spatial wavelet transform to the component array. More...
 
CODEC_ERROR TransformForwardSpatialLowpass (ENCODER *encoder, WAVELET *input, WAVELET *output, int prescale)
 Apply the forward spatial wavelet transform to the lowpass band. More...
 
CODEC_ERROR PadWaveletBands (ENCODER *encoder, WAVELET *wavelet)
 Zero the padding at the bottom of the wavelet bands.
 
CODEC_ERROR CodecErrorBitstream (BITSTREAM_ERROR error)
 Convert a bitstream error code to a codec error codec. More...
 
CODEC_ERROR AllocEncoderTransforms (ENCODER *encoder)
 Allocate all of the wavelets used during encoding. More...
 
CODEC_ERROR AllocEncoderBuffers (ENCODER *encoder)
 Allocate all of the buffers required for encoding. More...
 
CODEC_ERROR SetTransformParameters (ENCODER *encoder)
 Set the configuration of the wavelet tree. More...
 
CODEC_ERROR SetEncoderQuantization (ENCODER *encoder, const PARAMETERS *parameters)
 Set the quantization parameters in the encoder. More...
 
CODEC_ERROR SetTransformQuantTable (ENCODER *encoder, int channel, const QUANT table[], int table_length)
 Copy the quantization table into the wavelet bands.
 
CODEC_ERROR GetChannelDimensions (ENCODER *encoder, int channel_number, DIMENSION *channel_width_out, DIMENSION *channel_height_out)
 Return the encoded dimensions for the specified channel. More...
 
DIMENSION ChannelWidth (ENCODER *encoder, int channel_index, DIMENSION width)
 Adjust the width of a channel to account for chroma sampling.
 
DIMENSION EncodedLayerHeight (ENCODER *encoder, DIMENSION height)
 Adjust the height of encoded layer. More...
 
CODEC_ERROR GetMaximumChannelDimensions (const UNPACKED_IMAGE *image, DIMENSION *width_out, DIMENSION *height_out)
 Compute the dimensions of the image as reported by the ImageWidth and ImageHeight parameters. More...
 
CODEC_ERROR SetEncodedBandMask (CODEC_STATE *codec, int subband)
 Set the bit for the specified subband in the decoded band mask. More...
 
CODEC_ERROR EncodeLowpassBand (ENCODER *encoder, WAVELET *wavelet, int channel_number, BITSTREAM *stream)
 Encoded the lowpass band from the bitstream. More...
 
CODEC_ERROR EncodeHighpassBand (ENCODER *encoder, WAVELET *wavelet, int band, int subband, BITSTREAM *stream)
 Encode the highpass band into the bitstream. More...
 
CODEC_ERROR EncodeHighpassBandLongRuns (BITSTREAM *stream, CODESET *codeset, PIXEL *data, DIMENSION width, DIMENSION height, DIMENSION pitch)
 Encode the highpass band into the bitstream. More...
 
CODEC_ERROR EncodeHighpassBandRowRuns (BITSTREAM *stream, CODESET *codeset, PIXEL *data, DIMENSION width, DIMENSION height, DIMENSION pitch)
 Encode the highpass band from the bitstream. More...
 
CODEC_ERROR EncodeBandTrailer (BITSTREAM *stream)
 Encode the band trailer that follows a highpass band. More...
 
CODEC_ERROR DumpEncodedSubbands (ENCODER *encoder, int channel_index, uint32_t subband_mask, const char *pathname)
 Write selected subbands to a wavelet band file. More...
 
CODEC_ERROR DumpWaveletBands (ENCODER *encoder, int channel_index, int wavelet_index, uint32_t band_mask, const char *pathname)
 Write selected bands in a wavelet to a band file.
 
CODEC_ERROR DumpTransformBands (ENCODER *encoder, uint32_t channel_mask, uint32_t channel_wavelet_mask, uint32_t wavelet_band_mask, const char *pathname)
 Write selected wavelet bands to a band file.
 
CODEC_ERROR CreateEncodedBandFile (ENCODER *encoder, const char *pathname)
 Create a band data file for the encoded highpass bands.
 
CODEC_ERROR CloseEncodedBandFile (ENCODER *encoder)
 Close the bitstream used for encoded band data.
 

Detailed Description

Implementation of functions for encoding samples.

Encoded samples must be aligned on a four byte boundary. Any constraints on the alignment of data within the sample are handled by padding the sample to the correct alignment.

Note that the encoded dimensions are the actual dimensions of each channel (or the first channel in the case of 4:2:2 sampling) in the encoded sample. The display offsets and dimensions specify the portion of the encoded frame that should be displayed, but in the case of a Bayer image the display dimensions are doubled to account for the effects of the demosaic filter. If a Bayer image is encoded to Bayer format (no demosaic filter applied), then the encoded dimensions will be the same as grid of Bayer quads, less any padding required during encoding, but the display dimensions and offset will be reported as if a demosiac filter were applied to scale the encoded frame to the display dimensions (doubling the width and height).

(c) 2013-2017 Society of Motion Picture & Television Engineers LLC and Woodman Labs, Inc. All rights reserved–use subject to compliance with end user license agreement.

Function Documentation

◆ AllocateEncoderHorizontalBuffers()

CODEC_ERROR AllocateEncoderHorizontalBuffers ( ENCODER encoder,
int  buffer_width 
)

Allocate intermediate buffers for the horizontal transform results.

Todo:
Need to return an error code if allocation fails
Here is the call graph for this function:
Here is the caller graph for this function:

◆ AllocateEncoderUnpackingBuffers()

CODEC_ERROR AllocateEncoderUnpackingBuffers ( ENCODER encoder,
int  frame_width 
)

Allocate buffers for unpacking rows of the input frame.

The unpacking buffers are used to unpack the input frame into separate channels one row at a time for more efficient memory usage.

Here is the call graph for this function:

◆ AllocEncoderBuffers()

CODEC_ERROR AllocEncoderBuffers ( ENCODER encoder)

Allocate all of the buffers required for encoding.

This routine allocates buffers required for encoding, not including the wavelet images in the wavelet tree which are allocated by AllocEncoderTransforms

This routine is used to preallocate buffers before encoding begins. If the buffers are allocated on demand if not preallocated.

The encoding parameters, including the encoded frame dimensions, resolution of the decoded frame, and the decoded pixel format, are taken into account when the buffers are allocated. For example, buffer space that is only used when encoding to full resolution will not be allocated if the frame is decoded to a smaller size.

Note that it is not an error to preallocate more buffer space than what is strictly required for encoding. For example, it is okay to allocate buffer space required for full frame encoding even if the encoded sample will be decoded at lower resolution. In many applications, it is simpler to preallocate the maximum buffer space that may be needed.

Currently, the reference encoder allocates scratch buffers as required by each routine that needs scratch space and the scratch buffers are deallocated at the end each routine that allocates scratch space. A custom memory allocator can make this scheme efficient. See comments in the documentation for the memory allocator module.

Todo:
Should it be an error if the buffers are not preallocated?

◆ AllocEncoderTransforms()

CODEC_ERROR AllocEncoderTransforms ( ENCODER encoder)

Allocate all of the wavelets used during encoding.

This routine allocates all of the wavelets in the wavelet tree that may be used during encoding.

This routine is used to preallocate the wavelets before encoding begins. If the wavelet bands are allocated on demand if not preallocated.

By default, the wavelet bands are encoded into the bitstream with the bands from the wavelet at the highest level (smallest wavelet) first so that the bands can be processed by the encoder in the order as the sample is decoded.

Todo:
Do not allocate wavelets for resolutions that are larger then the decoded resolution. At lower resolutions, the depth of the wavelet tree can be reduced and the highpass bands in the unused wavelets to not have to be decoded.
Todo:
Should it be an error if the wavelets are not preallocated?
Here is the call graph for this function:

◆ CheckImageFormatParameters()

bool CheckImageFormatParameters ( ENCODER encoder)

Check for inconsistent values for the parameters specified on the command-line.

This routine looks for inconsistencies between the image format, the dimensions of the pattern elements, and the number of components per sample.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CodecErrorBitstream()

CODEC_ERROR CodecErrorBitstream ( BITSTREAM_ERROR  error)

Convert a bitstream error code to a codec error codec.

The bitstream and byte stream modules use a separate enumeration for error codes since these modules are used in other applications. The bistream error code is embedded in a range of codec error codes that are reserved for bitstream errors.

Here is the caller graph for this function:

◆ DeallocateEncoderHorizontalBuffers()

CODEC_ERROR DeallocateEncoderHorizontalBuffers ( ENCODER encoder)

Deallocate the intermediate buffers for the horizontal transform results.

It is possible to avoid reallocating the buffers for the horizontal transform results if the buffers were not deallocated between encoded frames. In this case, it would be necessary to call this routine inside ReleaseEncoder and it would also be necessary to modify AllocateEncoderHorizontalBuffers to not allocate the buffers if they are already allocated.

Here is the call graph for this function:

◆ DumpEncodedSubbands()

CODEC_ERROR DumpEncodedSubbands ( ENCODER encoder,
int  channel_index,
uint32_t  subband_mask,
const char *  pathname 
)

Write selected subbands to a wavelet band file.

Each bit in the subband mask argument specifies whether the corresponding subband should be written to the wavelet band file.

Note that the band file can contain reconstructed lowpass bands, but this routine only write decoded subbands to the wavelet band file.

Todo:
Change the channel index into a channel mask
Here is the call graph for this function:

◆ EncodeBandTrailer()

CODEC_ERROR EncodeBandTrailer ( BITSTREAM stream)

Encode the band trailer that follows a highpass band.

This routine aligns the bitstream to a tag value boundary. Currently the band trailer does not perform any function beyond preparing the bitstream for reading the next tag value pair.

Here is the call graph for this function:

◆ EncodeBitstreamHeader()

CODEC_ERROR EncodeBitstreamHeader ( ENCODER encoder,
BITSTREAM stream 
)

Insert the header segments that are common to all samples.

This code was derived from PutVideoIntraFrameHeader in the current codec.

Todo:
Need to output the channel size table.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeBitstreamTrailer()

CODEC_ERROR EncodeBitstreamTrailer ( ENCODER encoder,
BITSTREAM stream 
)

Write the trailer at the end of the encoded sample.

This routine updates the sample size segment in the sample extension header with the actual size of the encoded sample. The size of the encoded sample does not include the size of the sample header or trailer.

Note that the trailer may not be necessary as the decoder may stop reading from the sample after it has decoded all of the information required to reconstruct the frame.

This code was derived from PutVideoIntraFrameTrailer in the current codec.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeChannelHeader()

CODEC_ERROR EncodeChannelHeader ( ENCODER encoder,
int  channel_number,
BITSTREAM stream 
)

Write the channel header into the bitstream.

The channel header separates channels in the encoded layer. The channel header is not required before the first encoded channel because the codec state is initialized for decoding the first channel.

The first channel is channel number zero.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeChannelSubbands()

CODEC_ERROR EncodeChannelSubbands ( ENCODER encoder,
int  channel_number,
BITSTREAM stream 
)

Write the encoded subbands for this channel into the bitstream.

This routine writes the encoded subbands in the wavelet tree for this channel into the bitstream, including both the lowpass band and all of the highpass bands in each wavelet in this channel.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeChannelTrailer()

CODEC_ERROR EncodeChannelTrailer ( ENCODER encoder,
int  channel,
BITSTREAM stream 
)

Write the channel trailer into the bitstream.

A channel trailer is not required as the channel header functions as a marker between channels in the bitstream.

It may be necessary to update the channel size in a channel section header that was written into the channel header if channel sections are enabled.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeChannelWavelets()

CODEC_ERROR EncodeChannelWavelets ( ENCODER encoder,
BITSTREAM stream 
)

Encode the channel into the bistream.

This routine encodes all of the subbands (lowpass and highpass) in the wavelet tree for the specified channel into the bitstream.

Here is the call graph for this function:

◆ EncodedLayerHeight()

DIMENSION EncodedLayerHeight ( ENCODER encoder,
DIMENSION  height 
)

Adjust the height of encoded layer.

Interleaved frames are encoded as separate layers with half the height.

Here is the caller graph for this function:

◆ EncodeExtensionHeader()

CODEC_ERROR EncodeExtensionHeader ( ENCODER encoder,
BITSTREAM stream 
)

Write extra information that follows the sample header into the bitstream.

This routine writes metadata into the sample header extension.

Metadata includes the unique GUID for each video clip, the number of each video frame, and the timecode (if available). The GUID and frame number pair uniquely identify each frame in the encoded clip.

This routine also outputs additional information that describes the characterstics of the encoded video in the GOP extension and sample flags.

The size of the sample extension header is provided by the sample size segment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeExtensionTrailer()

CODEC_ERROR EncodeExtensionTrailer ( ENCODER encoder,
BITSTREAM stream 
)

Write the sample extension trailer into the bitstream.

This routine must be called after encoding the sample and before writing the sample trailer, but must only be called if the sample extension header was written into the bitstream.

Here is the caller graph for this function:

◆ EncodeHighpassBand()

CODEC_ERROR EncodeHighpassBand ( ENCODER encoder,
WAVELET wavelet,
int  band,
int  subband,
BITSTREAM stream 
)

Encode the highpass band into the bitstream.

The specified wavelet band is decoded from the bitstream using the codebook and encoding method specified in the bitstream.

Here is the call graph for this function:

◆ EncodeHighpassBandLongRuns()

CODEC_ERROR EncodeHighpassBandLongRuns ( BITSTREAM stream,
CODESET codeset,
PIXEL data,
DIMENSION  width,
DIMENSION  height,
DIMENSION  pitch 
)

Encode the highpass band into the bitstream.

The highpass band in the bitstream is decoded using the specified codebook. This routine assumes that the highpass band was encoded using the run lengths encoding method which is the default for all current codec implementations.

The encoded highpass band consists of signed values and runs of zeros. Each codebook entry specifies either an unsigned magnitude with a run length of one or a run of zeros. The unsigned magnitude is immediately followed by the sign bit.

Unsigned magnitudes always have a run length of one.

Note that runs of zeros can straddle end of line boundaries.

The end of the highpass band is marked by a special codeword. Special codewords in the codebook have a run length of zero. The value indicates the type or purpose of the special codeword.

Here is the call graph for this function:

◆ EncodeHighpassBandRowRuns()

CODEC_ERROR EncodeHighpassBandRowRuns ( BITSTREAM stream,
CODESET codeset,
PIXEL data,
DIMENSION  width,
DIMENSION  height,
DIMENSION  pitch 
)

Encode the highpass band from the bitstream.

This routine does not encode runs of zeros across row boundaries.

Here is the call graph for this function:

◆ EncodeImage()

CODEC_ERROR EncodeImage ( IMAGE image,
STREAM stream,
const PARAMETERS parameters 
)

Encode the image into the output stream.

This is a convenience routine for applications that use a byte stream to represent a memory buffer or binary file that will store the encoded image.

The image is unpacked into a set of component arrays by the image unpacking process invoked by calling the routine ImageUnpackingProcess. The image unpacking process is informative and is not part of the VC-5 standard.

The main entry point for encoding the component arrays output by the image unpacking process is EncodingProcess.

Here is the call graph for this function:

◆ EncodeImageList()

CODEC_ERROR EncodeImageList ( IMAGE_LIST image_list,
STREAM stream,
const PARAMETERS parameters 
)

Encode the list of images into the bitstream as layers or sections.

The layer flag in the encoding parameters determines whether the images are encoded as layers or sections. If the images are encoded as layers, then each image must have the same dimensions and pixel format.

Todo:
Finish handling the encoding of sections.
Here is the call graph for this function:

◆ EncodeImageSectionLayers()

CODEC_ERROR EncodeImageSectionLayers ( IMAGE_LIST image_list,
STREAM stream,
const PARAMETERS parameters 
)

Encode the input images as image sections with nested layers.

This routine unpacks the list of input images and binds a bitstream to the byte stream passed as an argument. Most of the encoding work is performed by ImageSectionLayersEncodingProcess.

Here is the call graph for this function:

◆ EncodeLayerHeader()

CODEC_ERROR EncodeLayerHeader ( ENCODER encoder,
BITSTREAM stream,
COUNT  layer_number 
)

Write the sample layer header.

The baseline profile only supports a single layer so the layer header and trailer are not required.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeLayerTrailer()

CODEC_ERROR EncodeLayerTrailer ( ENCODER encoder,
BITSTREAM stream 
)

Write the sample layer trailer.

The baseline profile only supports a single layer so the layer header and trailer are not required.

If more than one layer is present, the layers must be terminated by a layer trailer. Otherwise, the decoder will continue to parse tag-value pairs that belong to the next layer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodeLowpassBand()

CODEC_ERROR EncodeLowpassBand ( ENCODER encoder,
WAVELET wavelet,
int  channel_number,
BITSTREAM stream 
)

Encoded the lowpass band from the bitstream.

The wavelet at the highest level is passes as an argument. This routine decodes lowpass band in the bitstream into the lowpass band of the wavelet.

Here is the call graph for this function:

◆ EncodeMultipleChannels()

CODEC_ERROR EncodeMultipleChannels ( ENCODER encoder,
const UNPACKED_IMAGE image,
BITSTREAM stream 
)

Encode the portion of a sample that corresponds to a single layer.

Samples can be contain multiple subsamples. Each subsample may correspond to a different view. For example, an encoded video sample may contain both the left and right subsamples in a stereo pair.

Subsamples have been called tracks or channels, but this terminology can be confused with separate video tracks in a multimedia container or the color planes that are called channels elsewhere in this codec.

The subsamples are decoded seperately and composited to form a single frame that is the output of the complete process of decoding a single video sample. For this reason, the subsamples are called layers.

Todo:
Need to reset the codec state for each layer?
Here is the caller graph for this function:

◆ EncodeMultipleFrames()

CODEC_ERROR EncodeMultipleFrames ( ENCODER encoder,
IMAGE image_array[],
int  frame_count,
BITSTREAM stream 
)

Encode multiple frames as separate layers in a sample.

The encoder must have been initialized by a call to PrepareEncoder.

The bitstream must be initialized and bound to a byte stream before calling this routine.

Here is the call graph for this function:

◆ EncodeSingleImage()

CODEC_ERROR EncodeSingleImage ( ENCODER encoder,
const UNPACKED_IMAGE image,
BITSTREAM stream 
)

Encode a single image into the bitstream.

This is the main entry point for encoding a single image into the bitstream. The encoder must have been initialized by a call to PrepareEncoder.

The unpacked image is the set of component arrays output by the image unpacking process. The bitstream must be initialized and bound to a byte stream before calling this routine.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ EncodingProcess()

CODEC_ERROR EncodingProcess ( ENCODER encoder,
const UNPACKED_IMAGE image,
BITSTREAM bitstream,
const PARAMETERS parameters 
)

Reference implementation of the VC-5 encoding process.

The encoder takes input image in the form of a list of component arrays produced by the image unpacking process and encodes the image into the bitstream.

External parameters are used to initialize the encoder state.

The encoder state determines how the image is encoded int the bitstream.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetChannelDimensions()

CODEC_ERROR GetChannelDimensions ( ENCODER encoder,
int  channel_number,
DIMENSION channel_width_out,
DIMENSION channel_height_out 
)

Return the encoded dimensions for the specified channel.

The encoded dimensions for each channel may differ due to color difference component sampling.

Here is the caller graph for this function:

◆ GetMaximumChannelDimensions()

CODEC_ERROR GetMaximumChannelDimensions ( const UNPACKED_IMAGE image,
DIMENSION width_out,
DIMENSION height_out 
)

Compute the dimensions of the image as reported by the ImageWidth and ImageHeight parameters.

The image width is the maximum width of all component arrays and the image height is the maximum height of all component arrays.

Here is the caller graph for this function:

◆ ImageListEncodingProcess()

CODEC_ERROR ImageListEncodingProcess ( ENCODER encoder,
UNPACKED_IMAGE_LIST unpacked_image_list,
BITSTREAM bitstream,
const PARAMETERS parameters 
)

Apply the encoding process to each image in the unpacked image list.

The images are encoded as layers or image sections depending on whether layers or image sections are enabled.

Here is the call graph for this function:

◆ ImageSectionLayersEncodingProcess()

CODEC_ERROR ImageSectionLayersEncodingProcess ( ENCODER encoder,
UNPACKED_IMAGE_LIST image_list,
BITSTREAM bitstream,
const PARAMETERS parameters 
)

Apply the encoding process to each image in the unpacked image list.

The images are encoded as image sections with nested layers according to the pattern specified by the layers command-line option.

This routine is only called with both layers and image sections are enabled.

If the layers command-line option is not provided, then this routine encodes the input images as image sections with one image per section witout using layer syntax.

This routine is an adaption of ImageListEncodingProcess, EncodeImageLayers, and EncodeImageSections.

< Number of image sections to encode into the bitstream

< Index of the image section that is being encoded

< Index of the layer within the image section

< Index of the input image

< Number of images to encode as nested layers

Here is the call graph for this function:

◆ InitEncoder()

CODEC_ERROR InitEncoder ( ENCODER encoder,
const ALLOCATOR allocator,
const VERSION version 
)

Initialize the encoder data structure.

This routine performs the same function as a C++ constructor. The encoder is initialized with default values that are replaced by the parameters used to prepare the encoder (see PrepareEncoder).

This routine does not perform all of the initializations required to prepare the encoder data structure for decoding a sample.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareEncoder()

CODEC_ERROR PrepareEncoder ( ENCODER encoder,
const UNPACKED_IMAGE image,
ALLOCATOR allocator,
const PARAMETERS parameters,
int  input_image_index 
)

Initialize the encoder using the specified parameters.

It is important to use the correct encoded image dimensions (including padding) and the correct encoded format to initialize the encoder. The decoded image dimensions must be adjusted to account for a lower decoded resolution if applicable.

It is expected that the parameters data structure may change over time with additional or different fields, depending on the codec profile or changes made to the codec during further development. The parameters data structure may have a version number or may evolve into a dictionary of key-value pairs with missing keys indicating that a default value should be used.

Todo:
Add more error checking to this top-level routine
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrepareEncoderState()

CODEC_ERROR PrepareEncoderState ( ENCODER encoder,
const UNPACKED_IMAGE image,
const PARAMETERS parameters,
int  input_image_index 
)

Prepare the encoder state.

This routine works for single images and works for layers since each layer has the same number of channels and the same information per channel, but image sections do not have the same image dimensions and pixel format for each image.

The values set using the first pathname will not work for image sections after the first image section, but the values set by this routine are overridden by a call to the routine InitializeImageSectionEncoder from inside PrepareEncoderImageSection immediately after this routine is called.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetEncodedBandMask()

CODEC_ERROR SetEncodedBandMask ( CODEC_STATE codec,
int  subband 
)

Set the bit for the specified subband in the decoded band mask.

The decoded subband mask is used to track which subbands have been decoded in teh current channel. It is reset at the start of each channel.

The decoded subband mask is used when decoding a sample at less than full resolution. The mask indicates when enough subbands have been decoded for a channel and that remaining portion of the encoded sample for the current channel may be skipped.

◆ SetEncoderQuantization()

CODEC_ERROR SetEncoderQuantization ( ENCODER encoder,
const PARAMETERS parameters 
)

Set the quantization parameters in the encoder.

This routine computes the parameters in the quantizer used by the encoder based based on the quality setting and the desired bitrate. The quantization parameters are adjsuted to compensate for the precision of the input pixels.

Note that the baseline profile does not support quantization to achieve a desired bitrate.

Here is the call graph for this function:

◆ SetImageFormatDefaults()

bool SetImageFormatDefaults ( ENCODER encoder)

Set default values for the pattern element structure.

Some image formats imply specific parameters for the dimensions of the pattern elements and the number of components per sample. If the pattern element structure has not been fully specified by the command-line arguments, then missing values can be filled in from the default values for the image format.

Here is the call graph for this function:

◆ SetTransformParameters()

CODEC_ERROR SetTransformParameters ( ENCODER encoder)

Set the configuration of the wavelet tree.

The parameters that determine the configuration of the wavelet tree can be computed from the encoded format.

◆ ShiftHorizontalBuffers()

CODEC_ERROR ShiftHorizontalBuffers ( PIXEL lowpass_buffer[],
PIXEL highpass_buffer[] 
)

Shift the array of buffers of horizontal highpass results.

The buffers are used to store siz rows of horizontal lowpass and highpass results while applying the forward wavelet transform.

◆ ShiftHorizontalResultBuffers()

CODEC_ERROR ShiftHorizontalResultBuffers ( ENCODER encoder)

Shift the buffers of horizontal highpass results.

The encoder contains six rows of horizontal lowpass and highpass results for each channel. This routine shifts the buffers by two rows to make room for two more rows of horizontal results for each channel.

Here is the caller graph for this function:

◆ TransformForwardSpatialChannel()

CODEC_ERROR TransformForwardSpatialChannel ( ENCODER encoder,
const UNPACKED_IMAGE image,
int  channel_number 
)

Apply the forward spatial wavelet transform to the component array.

Each channel in the bitstream represents a single component array.

This routine applies the forward spatial wavelet transform to the component array for the specified channel.

Here is the call graph for this function:

◆ TransformForwardSpatialLowpass()

CODEC_ERROR TransformForwardSpatialLowpass ( ENCODER encoder,
WAVELET input,
WAVELET output,
int  prescale 
)

Apply the forward spatial wavelet transform to the lowpass band.

The forward spatial wavelet transform is applied to the lowpass band in the input wavelet producing four bands of results in the output wavelet.

The input values are prescaled to avoid overflow. The quantization values stored in the output wavelet are applied to the result.

Here is the call graph for this function: