📄 ebcot_encoder.h
字号:
double cumulative_wmse[MAX_PASSES];
std_int slope_rates[31];
long int cpu_time;
} block_master, *block_master_ptr;
/* There is only one instance of this structure in the entire system.
It holds all intermediate information involved in the coding of a
single block of samples. Many of its fields must be initialized
for each new block.
`max_dim' identifies the maximum dimensions of each code block.
`max_sub_dim' identifies the maximum size of each sub-block. All
sub-blocks will have `max_sub_dim' rows and `max_sub_dim' columns,
escept those near block boundaries, which might have smaller dimensions.
`row_gap' holds the separation between successive rows in the context
and sample buffers. It must be large enough to allow legal accesses
into the context words immediately before and after each row, but not
to guarantee that these out-of-bound values can be reliably recovered.
In practice, then, `row_gap' must be at least as large as `max_dim'+1
and the context array must be allocated in such a way as to allow some
negative accesses (see `context_buffer' description).
`first_subblock' and `last_subblock' point to the first and last
entries in an array which holds all sub-blocks which might be required
to cover the code block. If the maximum block dimensions are 64x64, for
example, and the maximum sub-block dimensions are 16x16, this array will
hold 16 entries, regardless of the size of the actual code block (may be
smaller near image boundaries).
`bit_idx' identifies the bit position of the current magnitude bit
plane. It is initially set to IMPLEMENTATION_PRECISION-2 (bit position
indices are zero-based) and then decremented for each successive
bit-plane.
`block_mag' holds the inclusive OR of the magnitude bits from all
samples in the block (i.e the IMPLEMENTATION_PRECISION-1 least
significant bits from each IMPLEMENTATION_PRECISION-bit word).
`block_update' points to a value into which the constant,
QUAD_PARENT_SIGNIFICANT should be OR'd when the most significant
bit-plane in the `block_mag' word is encountered. Exactly as described
for the `node_update' field in `quad_siblings', this field points either
to the first entry of a `quad_siblings' structure or a `code_subblock'
structure, depending upon whether or not there are any further levels of
quad-tree decomposition in the sub-block significance code.
`first_quad' and `last_quad' point to the first and last entries of an
array of `quad_siblings' structures which represents a flat organization
of the nodes in the partial quad-tree associated with the subblocks.
The first entry contains the four (may be less) siblings which are
descended from the root of the quad-tree. The fields hold NULL if there
is no quad-tree.
`context_buffer' points to a common context buffer which is used
for all blocks. It holds `row_gap'*(`max_dim'+2)+1 16-bit entries, but
the pointer starts `row_gap'+1 entries into the array, so that the buffer
can legally be addressed with indices from -(`row_gap'+1) to
`max_dim'*`row_gap'-1.
`sample_buffer' points to the buffer which holds the samples to be
encoded. Rows of sample values are separated by `row_gap', which is
larger than `max_dim' so the buffer must actually measure
`row_gap'*(`max_dim'-1) + `max_dim' in size. In some cases, we may
be able to use a common sample buffer, while in others this field might
be set to point to one of a number of different buffers which are
separately maintained, say, by the line buffering mechanism.
`coder_state' holds the current state of the arithmetic coder. Its
contents may be periodically saved to the `saved_states' array in order
to allow reconstruction of the number of bits required to uniquely
recover all coded symbols up to that point.
`zc_lut' identifies the zero-coding lookup table to be used in
selecting coding contexts based upon the significance of the eight
immediate neighbours. An appropriate pointer will be inserted here
for each band.
`contexts' holds the context state information used by the adaptive
arithmetic coder. Its entries are set to some initial state (usually
equi-probable distributions) before coding each block.
`saved_states' holds the arithmetic coding state information during
each successive pass through the block samples. Currently we save all
the intermediate states and compute the number of bytes required to
uniquely decode the symbols encoded for the relevant pass only once all
passes have been encoded. In a hardware solution, a more incremental
technique might be employed, but this would complement our current
software implementation.
`cumulative_wmse' holds the cumulative amounts by which each
successive block coding pass reduces the weighted MSE of the reconstructed
image. These numbers should be exact for orthogonal transforms. They
should also be exact for any transform, subject to the assumption that
quantization errors are uncorrelated (unlikely to be strictly valid in
practice). Thus, the entries should increase from pass to pass. These
numbers will be used to compute slopes on the convex hull of the
rate distortion curve once the block has been completely coded.
`slope_rates' is an array with one entry for each bit-position in
the 32-bit words used to represent rate-distortion slopes for RD
optimization. The entry at location k in this array accumulates the
total number of code bytes from all code blocks in all subbands from
all coding passes whose rate-distortion slope is greater than or equal
to 2^k, where k runs from 0 to 31.
`cpu_time' accumulates the CPU time associated with all block
coding operations. If CPU time is not required, it should hold a
negative value. */
/*****************************************************************************/
/* block_coding_pass_func */
/*****************************************************************************/
typedef std_int (*block_coding_pass_func)(block_master_ptr master);
/* This prototype defines the form of the lowest level functions in the
block coding algorithm. It uses the supplied `master' object to determine
the subblocks with the code-block which must be coded, as well as the
size and location of each subblock and all parameters relevant to the
current coding pass.
The function returns a normalized fixed-point representation of the
amount by which the squared error is reduced by the symbols encoded
during this coding pass. Specifically, to obtain the absolute reduction
in mean squared error of the IMPLEMENTATION_PRECISION-bit sample values,
the return value should be divided by 2^13 and then multiplied by 2^(2*P),
where P is the zero-based index of the current bit-plane. */
/*****************************************************************************/
/* pass_info */
/*****************************************************************************/
typedef
struct pass_info {
std_int cumulative_bytes;
std_int rd_slope;
} pass_info, *pass_info_ptr;
/* This structure manages information concerning the code size and the
rate-distortion slope at the end of any given block coding pass.
`cumulative_bytes' holds the number of code bytes which are required
to uniquely decode all symbols up to and including the completion of
the relevant pass.
`rd_slopes' holds a quantized representation of the slope of
the rate-distortion curve at each block coding pass. Specifically, the
integral value is proportional to `delta_MSE' / `delta_RATE' where
`delta_MSE' is the drop in Weighted MSE and `delta_RATE' is the increase
in bit-rate since the last pass which lay on the convex hull of the
rate-distortion curve. Coding passes whose rate-distortion performance
does not lie on the convex hull of the rate-distortion curve are assigned
a value of 0, except when the relevant coding pass does not reduce the
distortion at all, in which case a value of -1 is assigned.
Apart from these two special cases, all points which lie on the
convex hull of the rate-distortion curve are assigned integral slope
values in the range 1 through 1^30. */
/*****************************************************************************/
/* block_info */
/*****************************************************************************/
typedef
struct block_info {
int top_row, left_col, rows, cols;
int unpushed_blocks;
ifc_int *pushed_block_buffer;
heap_unit_ptr first_unit;
int first_pos;
int max_passes, num_passes, old_passes, makeup_passes;
pass_info_ptr passes;
int insignificant_msbs;
} block_info, *block_info_ptr;
/* This structure maintains summary information for each coded block.
An array of these structures is managed from the `band_info' structure,
with one entry for each block in the subband. In our current
implementation the information in these structures is examined and
used to construct the final bit-stream, only once all code blocks in
the image have been coded.
`top_row', `left_col', `rows' and `cols' hold the block dimensions
and the indices of the first row and column in the block. Indices are
zero based and relate to the subband sampling grid, rather than the image
sampling grid.
`unpushed_blocks' and `pushed_block_buffer' are used only by the
`push_block' interface function. The `unpushed_blocks' field identifies
the number of blocks which have yet to be pushed to complete the code
block. The `pushed_block_buffer' points to a sample buffer array which
is used to accumulate pushed blocks of samples until an entire code
block becomes available. The sample buffer must conform to the
requirements of the `sample_buffer' array described under the definition
of the `block_master' structure. These sample buffers are allocated
and recycled via the main encoder object's `sample_buffer_heap_mgr'
object.
`first_unit' points to the first `heap_unit' which contains code
words for the block. The `first_pos' field identifies the location
within this heap unit of the first code word generated for the block.
Code bits for each block always commence on whole word boundaries within
the heap unit structures.
`max_passes' identifies the maximum number of coding passes which
can be used to represent the coded block; this is the number which are
generated during the block coding phase. Not all of these coding passes
need necessarily be included in the bit-stream.
`old_passes' is a utility variable which is used by the
layered bit-stream formation algorithm. It represents the number of
coding passes which have been included in previously formed bit-stream
layers. `num_passes', on the other hand, represents the total
number of coding passes which are to be included in all bit-stream layers
up to and including the current layer.
`makeup_passes' manages the inclusion of extra coding passes, in
addition to those assigned by the rate-distortion optimization algorithm,
which should be included in the bit-stream to best utilize the available
bit-rate budget. Once rate-distortion optimization is complete, there
will often be a few bytes left which have not yet been used. These may
be assigned to additional coding passes whose rate-distortion slope
might not be optimal. The extra coding passes should only be included
in a final bit-stream layer. The number of additional passes is
identified by this field; it must be added to the number of passes which
would be computed from the basic rate-distortion threshold, when
generating the final bit-stream layer.
`passes' points to an array which is capable of holding `max_passes'
entries, which describe the code size and rate-distortion slope at the
end of each coding pass. In practice, we do not allocate a separate
array for each code block, but allocate a single array which holds the
concatenated `passes' arrays from all code blocks in the subband. The
first code block's `passes' field points to the head of this single
allocated array.
`insignificant_msbs' indicates the number of bit-planes, starting from
the most significant magnitude bit of the IMPLEMENTATION_PRECISION-bit
sign-magnitude words, for which all samples in the block were found to
have zero magnitude. */
/* ========================================================================= */
/* ----------------------------- Line Buffering ---------------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* line_buffering */
/*****************************************************************************/
typedef
struct line_buffering {
int num_lines;
block_info_ptr info;
ifc_int **buffers;
} line_buffering, *line_buffering_ptr;
/* This structure manages buffering of subband lines into a row of blocks
when data arrives from the quantizer in lines rather than blocks.
`num_lines' holds the number of lines which have arrived. Once
this reaches the height of a block (or the end of the image), the
blocks will all be coded at once.
`info' points to the `block_info' entry for the first block in
the row of blocks which is currently being accumulated.
`buffers' points to a row of block buffers. Each block buffer
conforms to the requirements of the `sample_buffer' array described
under the definition of the `block_master' structure. The buffers
are only allocated in the event that the `push_line' interface
function is used. */
/* ========================================================================= */
/* ---------------------------- Subband Structure -------------------------- */
/* ========================================================================= */
/*****************************************************************************/
/* band_info */
/*****************************************************************************/
typedef
struct band_info {
int component_idx, level_idx, band_idx;
int band_rows, band_cols;
int blocks_high, blocks_wide, band_blocks;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -