Encoder  4.4
VC-5 Sample Encoder
codec.h
Go to the documentation of this file.
1 
20 #ifndef _CODEC_H
21 #define _CODEC_H
22 
23 static const SEGMENT StartMarkerSegment = ((0x56 << 24) | (0x43 << 16) | (0x2D << 8) | 0x35);
24 
46 typedef enum _codec_tag
47 {
60 
61 #if _DEBUG
62  // Optional tag-value pairs used for debugging
64 #endif
65 
67 
70 
73 
74 #if VC5_ENABLED_PART(VC5_PART_IMAGE_FORMATS)
75  // Codec tags used by VC-5 Part 3 bitstreams
81 
82  // Small chunk elements defined by VC-5 Part 3
88 #endif
89 
90 #if VC5_ENABLED_PART(VC5_PART_LAYERS)
94 #endif
95 
96 #if VC5_ENABLED_PART(VC5_PART_SECTIONS)
99 
100  // Predefined codec tags for structures in the VC-5 bitstream
107 #endif
108 
109 #if VC5_ENABLED_PART(VC5_PART_METADATA)
110  // Small and large chunks of metadata
113 #endif
114 
115 } CODEC_TAG;
116 
117 #if VC5_ENABLED_PART(VC5_PART_IMAGE_FORMATS)
118 
125 typedef enum _image_format
126 {
132 
133 
134  /***** Add new encoded formats above this line *****/
135 
137 
138 } IMAGE_FORMAT;
139 
140 #endif
141 
142 #if VC5_ENABLED_PART(VC5_PART_SECTIONS)
143 
144 /*
145  @brief Enumeration of the predefined section numbers
146 
147  The predefined section numbers are defined in ST 2073-2.
148  */
149 typedef enum _section_number
150 {
157 
158  //TODO: Add more section number definitions as required
159 
162  SECTION_NUMBER_MAXIMUM = SECTION_NUMBER_SUBBAND,
163 
164 } SECTION_NUMBER;
165 
166 /*
167  @Macro for creating a section number bit mask from a section number
168 
169  The macro does not check that the section number argument is valid.
170  */
171 #define SECTION_NUMBER_MASK(section_number) (1 << (section_number - 1))
172 
173 /*
174  @brief Data type for the bit mask that represents enabled sections
175 
176  The bit mask indicates which section numbers defined in ST 2073-2 are enabled
177  at runtime.
178  */
179 typedef uint32_t ENABLED_SECTIONS;
180 
181 #endif
182 
197  BAND_ENCODING_ZEROTREE = 1,
198  BAND_ENCODING_CODEBOOK,
199  BAND_ENCODING_RUNLENGTHS,
200  BAND_ENCODING_16BIT,
201  BAND_ENCODING_LOSSLESS
202 };
203 
222 typedef struct _codec_state
223 {
224  uint16_t channel_number;
228 
229  uint16_t subband_number;
230 
231 #if VC5_ENABLED_PART(VC5_PART_IMAGE_FORMATS)
232  IMAGE_FORMAT image_format;
237 #endif
238 
239 #if VC5_ENABLED_PART(VC5_PART_LAYERS)
242  uint16_t layer_pattern;
244 #endif
245 
246  uint_least8_t channel_count;
247  uint_least8_t wavelet_count;
248  uint_least8_t subband_count;
249 
252 
253  uint32_t encoded_format;
254  uint32_t encoded_quality;
255 
257 
258  bool progressive;
259 
261 
263 
264  uint_least8_t group_length;
265 
266 #if 0
267  uint8_t active_codebook;
269 #endif
270 
273 
276 
278  bool header;
279 
281  bool codeblock;
282 
284  struct
285  {
286  //DIMENSION width; //!< Width of the decoded band
287  //DIMENSION height; //!< Height of the decoded band
288  uint_least8_t subband;
289  //uint_least8_t encoding; //!< Band encoding method
290  uint16_t quantization;
291 
292  } band;
293 
296 
298 
299 #if _DEBUG
300  struct
302  {
304 
305  } input;
306 #endif
307 
315  //uint_fast8_t prescale_table[MAX_WAVELET_COUNT];
316  PRESCALE prescale_table[MAX_WAVELET_COUNT];
317 
320  {
321  uint_least16_t x;
322  uint_least16_t y;
323 
325 
326 #if VC5_ENABLED_PART(VC5_PART_LAYERS)
327  //uint32_t interlaced_flags;
328  //uint32_t protection_flags;
329 
331  struct
332  {
333  int width;
334  int height;
335 
336  } layer;
337 
338 #endif
339 
340 #if VC5_ENABLED_PART(VC5_PART_SECTIONS)
343 #endif
344 
345 } CODEC_STATE;
346 
347 #if 0
348 
351 typedef struct _codec
352 {
353  FILE *logfile;
358 
361 
362 } CODEC;
363 #endif
364 
365 // Initialize the codec state
367 
368 uint32_t EncoderVersion(uint32_t value);
369 
370 uint32_t RepackedEncoderVersion(uint32_t value);
371 
372 void SetCodecVersion(uint8_t version[3], uint16_t value);
373 
374 #if VC5_ENABLED_PART(VC5_PART_IMAGE_FORMATS)
375 IMAGE_FORMAT DefaultImageFormat(PIXEL_FORMAT pixel_format);
376 #endif
377 
379 
381 
383 
384 CODEC_ERROR UpdateSampleFlags(CODEC_STATE *codec, TAGWORD value);
385 
386 CODEC_ERROR UpdateCodecFlags(CODEC_STATE *codec, TAGWORD value);
387 
389 
390 int LowpassChannelOffset(CODEC_STATE *codec, PIXEL_FORMAT output_format);
391 
393 
394 #if VC5_ENABLED_PART(VC5_PART_IMAGE_FORMATS)
395 const char *ImageFormatString(IMAGE_FORMAT image_format);
396 #endif
397 
398 bool IsPartEnabled(ENABLED_PARTS enabled_parts, int part_number);
399 
400 #if VC5_ENABLED_PART(VC5_PART_SECTIONS)
401 bool IsSectionEnabled(ENABLED_SECTIONS enabled_sections, SECTION_NUMBER section_number);
402 bool IsImageSectionEnabled(ENABLED_PARTS enabled_parts, ENABLED_SECTIONS enabled_sections);
403 #endif
404 
405 #endif
int height
Height of the current layer.
Definition: codec.h:334
struct _codec CODEC
Fields that are common to the encoder and decoder.
enum _image_format IMAGE_FORMAT
Format of the encoded sample.
bool end_of_sample
Indicates that enough of the sample has been read to allow decoding the sample.
Definition: codec.h:272
uint_least8_t channel_count
Number of channels in the current layer.
Definition: codec.h:246
CODEC_ERROR error
Error code from the most recent codec operation.
Definition: codec.h:354
Mask for detecting the tag for a small or large chunk (including codeblocks)
Definition: codec.h:72
bool codeblock
Most recent syntax element was a codeblock (large chunk element)
Definition: codec.h:281
Packed prescale shift for each wavelet level.
Definition: codec.h:57
struct _codec_state::@2 input
Information about the packed image input to the encoder (for debugging)
bool IsImageSectionEnabled(ENABLED_PARTS enabled_parts, ENABLED_SECTIONS enabled_sections)
Return true if image sections are enabled.
Definition: codec.c:443
Section that contains a single layer.
Definition: codec.h:103
RGB image with optional alpha channel.
Definition: codec.h:128
The image format has not been specified.
Definition: codec.h:127
Small chunk with a 16-bit payload size (in segments)
Definition: codec.h:68
Unique number assigned to an image bitstream section.
Definition: codec.h:98
DIMENSION channel_width
Width of the next channel in the bitstream.
Definition: codec.h:225
Small chunk containing metadata tuples (VC-5 Part 7)
Definition: codec.h:111
uint32_t encoded_format
Internal encoded representation.
Definition: codec.h:253
Small chunk containing the inverse component permutation.
Definition: codec.h:84
int LowpassChannelOffset(CODEC_STATE *codec, PIXEL_FORMAT output_format)
Compute the channel offset added to each lowpass pixel value.
Definition: codec.c:322
Number of image bitstream sections in the bitstream.
Definition: codec.h:97
int16_t TAGWORD
Bitstream tag or value.
Definition: syntax.h:27
Bayer image format (special case of CFA)
Definition: codec.h:130
bool difference_coding
Enables or disables differential coding.
Definition: codec.h:268
size_t channel_position
The channel position is used for skipping subbands and jumping to particular channels.
Definition: codec.h:251
IMAGE_FORMAT DefaultImageFormat(PIXEL_FORMAT pixel_format)
Set the image format using the pixel format.
Definition: codec.c:118
uint16_t channel_number
Index of current channel being decoded.
Definition: codec.h:224
ALLOCATOR * allocator
Memory allocator used to allocate all dyynamic data.
Definition: codec.h:355
uint8_t active_codebook
Non-zero value indicates which codebook is used.
Definition: codec.h:267
YCbCr image with optional alpha channel.
Definition: codec.h:129
Number of the next layer in the bitstream.
Definition: codec.h:92
Small chunk containing the identifier and sequence number for the image.
Definition: codec.h:87
Number of components in each sample in the pattern element.
Definition: codec.h:78
Number of layers in the bitstream.
Definition: codec.h:91
Definition: codec.h:222
Modify the smallest and largest section numbers as more sections are added.
Definition: codec.h:161
uint_least16_t DIMENSION
Data type for image and frame dimensions.
Definition: types.h:24
struct _codec_state::_picture_aspect_ratio picture_aspect_ratio
Picture aspect ratio read from the sample.
Section that contains a single image.
Definition: codec.h:101
bool progressive
True if the encoded frame is progressive.
Definition: codec.h:258
DIMENSION image_width
Upper bound on the channel width.
Definition: codec.h:294
Channel section.
Definition: codec.h:154
Fields that are common to the encoder and decoder.
Definition: codec.h:351
uint16_t subband_number
Index of current subband being decoded.
Definition: codec.h:229
ENABLED_PARTS enabled_parts
Parts of the VC-5 standard that are supported at runtime by the codec implementation.
Definition: codec.h:360
int EncodedPrecision(PIXEL_FORMAT format)
Return the encoded precision for an input pixel format.
Definition: codec.c:179
Pixel fomrat of the packed input image.
Definition: codec.h:63
CODEC_ERROR UpdatePrescaleTable(CODEC_STATE *codec, TAGWORD value)
Unpack the tag value into the prescale table.
Definition: codec.c:261
Upper bound on the width of the image.
Definition: codec.h:48
Upper bound on the height of the image.
Definition: codec.h:49
Channel number.
Definition: codec.h:53
void SetCodecVersion(uint8_t version[3], uint16_t value)
Unpack the version tag value into its components.
Definition: codec.c:94
Small chunk containing the inverse component transform (8 bit representation)
Definition: codec.h:85
Wavelet section.
Definition: codec.h:155
Section that contains all subbands for one wavelet.
Definition: codec.h:105
uint32_t decoded_layer_mask
Indicates which layers have been decoded.
Definition: codec.h:243
uint_least8_t subband_count
Number of suibbands in the current layer.
Definition: codec.h:248
PRECISION lowpass_precision
Number of bits per lowpass coefficient.
Definition: codec.h:297
Number of encoded subbands.
Definition: codec.h:52
uint_least8_t group_length
Number of frames in a group of pictures (GOP)
Definition: codec.h:264
Generic color filter array (CFA) image.
Definition: codec.h:131
uint16_t PRESCALE
Integer value for the amount of prescale shift.
Definition: types.h:45
uint_least8_t wavelet_count
Number of wavelets in the current layer.
Definition: codec.h:247
PRECISION bits_per_component
Precision of the component array (in bits)
Definition: codec.h:227
VERSION version
Codec version (major, minor, revision, build)
Definition: codec.h:357
DIMENSION pattern_width
Width of the pattern elements (in samples)
Definition: codec.h:233
Height of the next channel in the bitstream.
Definition: codec.h:59
CODEC_STATE codec
Information gathered while decoding the current sample.
Definition: codec.h:356
bool IsPartEnabled(ENABLED_PARTS enabled_parts, int part_number)
Return true if the specified part is enabled at runtime.
Definition: codec.c:415
Section that contains a single channel.
Definition: codec.h:104
CODEC_ERROR SetBandCoding(CODEC_STATE *codec, TAGWORD value)
Set the flags that determine the band coding.
Definition: codec.c:397
Quantization applied to band.
Definition: codec.h:56
Mask indicating the use cases in the bitstream.
Definition: codec.h:93
struct _codec_state::@3 layer
< Parameters of the current layer
Large chunk containing metadata tuples (VC-5 Part 7)
Definition: codec.h:112
Bitstream header section.
Definition: codec.h:152
const char * ImageFormatString(IMAGE_FORMAT image_format)
Return a string for the name of the image format.
Definition: codec.c:152
band_encoding
Band encoding method.
Definition: codec.h:196
DIMENSION image_height
Upper bound on the channel height.
Definition: codec.h:295
Large chunk with a 24-bit payload size (in segments)
Definition: codec.h:69
Format of the image represented by the bitstream.
Definition: codec.h:79
Section that contains the bitstream header.
Definition: codec.h:102
Section that contains a single subband.
Definition: codec.h:106
DIMENSION channel_height
Height of the next channel in the bitstream.
Definition: codec.h:226
uint16_t quantization
Quantization parameter.
Definition: codec.h:290
uint_least16_t COUNT
Data type for an unsigned number (count) that can be the value in a tag-value pair.
Definition: types.h:27
int InputPrecision(PIXEL_FORMAT format)
Return the precision of a pixel format.
Definition: codec.c:211
Number of bits in the source image.
Definition: codec.h:50
Number of channels in the transform.
Definition: codec.h:51
DIMENSION pattern_height
Height of the pattern elements (in rows)
Definition: codec.h:234
enum _pixel_format PIXEL_FORMAT
Pixels formats supported by the codec.
bool end_of_layer
Indicates that the layer has been decoded.
Definition: codec.h:275
Subband number of this wavelet band.
Definition: codec.h:54
uint_least16_t x
Relative width of the picture.
Definition: codec.h:321
uint32_t decoded_subband_mask
Indicates which subbands have been decoded.
Definition: codec.h:256
Subband section.
Definition: codec.h:156
uint16_t layer_pattern
Indicates the use case for layers in the bitstream.
Definition: codec.h:242
Width of the next channel in the bitstream.
Definition: codec.h:58
Image section.
Definition: codec.h:151
enum _codec_tag CODEC_TAG
Tags that define elements in the bitstream.
uint_least8_t PRECISION
Number of bits in a component value.
Definition: types.h:51
Number of bits per lowpass coefficient.
Definition: codec.h:55
struct _codec_state::@1 band
Parameters of the most recently decoded subband.
CODEC_ERROR UpdateFrameStructureFlags(CODEC_STATE *codec, TAGWORD value)
Update the flags that describe the frame structure.
Definition: codec.c:288
bool top_field_first
True if the top field is encoded first.
Definition: codec.h:260
PRECISION max_bits_per_component
Maximum number of bits for each value in the component arrays.
Definition: codec.h:236
Large chunk that contains a codeblock.
Definition: codec.h:66
struct _codec_state CODEC_STATE
CODEC_ERROR PrepareCodecState(CODEC_STATE *codec)
Initialize the codec state to before encoding or decoding the bitstream.
Definition: codec.c:36
Codec version number (major, minor, revision, build)
Definition: types.h:80
bool frame_inverted
True if the frame is encoded upside down.
Definition: codec.h:262
int section_number
Number of the most recent section encountered in the bitstream.
Definition: codec.h:341
COUNT layer_number
Number of the next layer in the bitstream.
Definition: codec.h:241
DIMENSION components_per_sample
Number of components in each sample in the pattern element.
Definition: codec.h:235
enum _codec_error CODEC_ERROR
Codec error codes.
void * ALLOCATOR
Opaque data type for the default memory allocator.
Definition: allocator.h:20
uint32_t encoded_quality
Quality setting of the encoded video.
Definition: codec.h:254
Number of image formats that have been defined.
Definition: codec.h:136
Number of rows of samples in each pattern element.
Definition: codec.h:77
int section_length
Length of the most recent section element payload (in segments)
Definition: codec.h:342
_codec_tag
Tags that define elements in the bitstream.
Definition: codec.h:46
_image_format
Format of the encoded sample.
Definition: codec.h:125
uint32_t EncoderVersion(uint32_t value)
Reformat a segment value into the encoder version.
Definition: codec.c:84
_section_number
Definition: codec.h:149
bool header
Most recent tag-value pair was a header parameter.
Definition: codec.h:278
Small chunk containing vendor-specific data.
Definition: codec.h:83
PIXEL_FORMAT format
Pixel format of the input image.
Definition: codec.h:303
COUNT layer_count
Number of layers in the bitstream.
Definition: codec.h:240
uint_least16_t y
Relative height of the picture.
Definition: codec.h:322
bool IsSectionEnabled(ENABLED_SECTIONS enabled_sections, SECTION_NUMBER section_number)
Return true if the specified type of section is enabled.
Definition: codec.c:426
Picture aspect ratio read from the encoded sample.
Definition: codec.h:319
Small chunk containing the inverse component transform (16 bit representation)
Definition: codec.h:86
int width
Width of the current layer.
Definition: codec.h:333
uint32_t SEGMENT
The bitstream is a sequence of segments.
Definition: syntax.h:25
IMAGE_FORMAT image_format
Format of the image represented by the bitstream.
Definition: codec.h:232
Number of samples per row in each pattern element.
Definition: codec.h:76
uint_least8_t subband
Subband index.
Definition: codec.h:288
Upper bound on the number of bits per component.
Definition: codec.h:80
uint32_t ENABLED_PARTS
Data type for the bit mask that represents enabled parts.
Definition: types.h:70
FILE * logfile
File for writing debugging information.
Definition: codec.h:353
PRESCALE prescale_table[MAX_WAVELET_COUNT]
Table of prescale shifts applied before computing each wavelet transform.
Definition: codec.h:316
Layer section.
Definition: codec.h:153