📄 ebcot_encoder.h
字号:
function; this is a constant, generally equal to the `max_width' value.
`causal' is a flag identifying whether or not the context formation
process should be vertically stripe-causal.
`reset' is a flag identifying whether or not the probability
models should be reinitialized at the beginning of each coding pass.
`terminate_each_pass' is a flag identifying whether or not the
arithmetic code-word generation process should be terminated at the
end of each coding pass. Note that this need not necessarily be
accompanied by model reset.
`lazy' is a flag identifying whether or not the lazy coding mode
is to be used, as parametrized by the `full_effort_msbs' field (see
below).
`easy_termination' is a flag identifying whether or not to use a
simplified algorithm for computing the termination length for each
arithmetic codeword segment. The decoder does not need to know about
this.
`error_resilient_termination' is a flag identifying whether or not
to use the predictable error resilient termination policy. In the
current implementation, the easy termination policy is identical to
the error resilient termination policy.
`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.
`first_bit_idx' holds the value of `bit_idx' in the first bit-plane
for which any sample was significant.
`full_effort_msbs' holds the number of most significant bit-planes,
starting with the first bit-plane in which the relevant code-block is
first found to be significant, for which arithmetic coding is used in
all passes. After this point, only the main coding pass (i.e. that
in which samples with previously all-zero neighbourhoods are coded)
receives the full coding effort, and the other passes are performed
without the aid of arithmetic coding, sending the raw binary symbols
directly to the bit-stream. Note that this behaviour occurs only
when the `elias' flag is turned on.
`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).
`interleaved_sample_buffer' points to the buffer which holds the
samples to be encoded. The sample buffer is organized in terms of
stripes. Specifically, the stripes appear one after the other, with
some intervening spacing to avoid access violations at boundaries.
The four rows of each stripe are interleaved and corresponding samples
from adjacent stripes are separated by `stripe_gap' entries
in the array.
`interleaved_context_buffer' points to a common context buffer which
is used for all code-blocks. It has the same interleaved stripe
organization as the `interleaved_sample_buffer' array. There is a single
16-bit context word for each sample, which is updated only when the
sample or one of its immediate neighbours becomes significant. The
value of `stripe_gap' is chosen to be sufficiently large to
ensure that accesses of up to eight stripe columns beyond the last
sample in any stripe will not cause any access violations or overwrite
real data. Also, accesses one stripe column to the left and a full
stripe before the first sample in the code-block or four samples to the
right and a full stripe after the last sample in the code-block will not
cause access violations, which means that the base of the allocated
memory is below the location pointed to by the
`interleaved_context_buffer' field. For ease of deallocation, this
base address is kept in the `context_buffer_handle' field.
`d_cells' points to an array of distortion accumulation cells,
each of which accommodates a nominal cell size of 8x8 samples. Vertically
adjacent cells are separated by `d_cell_row_gap' entries in this array.
`exploit_visual_masking' indicates whether or not the MSE distortion
metric should be modified to account for visual masking phenomena.
This is generally desirable if the objective is to optimize for visual
quality.
`masking_exponent' identifies the exponent for the local masking
strength computation. If the sample values are normalized so that
their magnitudes lie in the nominal range from 0 to 1.0, then the
masking strength is found by taking a local average of the sample
magnitudes, after first raising them to the power of this exponent.
Each sample is then conceptually divided by (1 + a suitably scaled version
of this masking strength) before computing the MSE contribution.
`max_masked_sensitivity_reduction' holds the maximum value of the
`fully_masked_sensitivity_reduction' field in the `ebcot_band_info'
structure, taken over all subbands. It is used to calculate a global
gain for visually masked distortion values so as to best utilize the
dynamic range available for the representation of distortion-rate slopes.
`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 the relevant subband.
`initial_mse_lut' points to one of the two global LUT's
`ebcot_initial_mse_lut' or `ebcot_lossless_initial_mse_lut',
depending upon whether the current coding pass involves potential
refinement to the LSB of a lossless representation of the relevant
sample values. MSE estimation is different in this case, since the
dequantizer will not be introducing any half steps. Similarly,
`refinement_mse_lut' points to one of the two global LUT's
`ebcot_refinement_mse_lut' or `ebcot_lossless_refinement_mse_lut',
depending upon whether the current coding pass involves potential
refinement to the LSB of a lossless representation of the
relevant subband sample values.
`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.
`roi_mask' points to an array with `max_height' entries which is used
to store pointers to the rows of the mask returned by calls to
`forward_roi__check_roi'. */
/*****************************************************************************/
/* block_coding_pass_func */
/*****************************************************************************/
typedef void /* David T Cvis mod */
(*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 fills in the `delta_mse' field of each distortion
cell in the `d_cells' array identified in the `master' structure, to
reflect the normalized reduction in MSE which may be attributed to the
coding pass for each distortion cell in the code-block. See the
definition of `distortion_cell' for more information. */
/*****************************************************************************/
/* ebcot_pass_info */
/*****************************************************************************/
typedef
struct ebcot_pass_info {
std_int cumulative_bytes;
rd_slope_type rd_slope;
std_short terminated;
} ebcot_pass_info, *ebcot_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_slope' holds a quantized representation of the slope of
the rate-distortion curve at each block coding pass. Specifically, the
slope value, S, 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. It should be noted, however, that S is related
to the integer value in `rd_slope' via the exponent-mantissa relationship
discussed with the definition of `rd_slope_type'.
Coding passes whose rate-distortion performance does not lie on the
convex hull of the rate-distortion curve are assigned `rd_slope' = 0,
except when the relevant coding pass does not reduce the distortion at
all, in which case we assign `rd_slope' = -1. 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 <= `rd_slope' < (1^16), which means that the actual range of legal
slopes is (1+2^{-Mbits}) <= S < 2^{2^{Ebits}}, where Ebits and Mbits
are the RD_SLOPE_EXPONENT_BITS and RD_SLOPE_MANTISSA_BITS values,
respectively. For more information, consult the definition of the
`rd_slope_type' data type.
`terminated' is a flag which is true (non-zero) if the arithmetic
codeword generation process was terminated at the end of this coding
pass. Of course, the last coding pass has this flag set, but other
intermediate coding passes may also be terminated to enable parallelism
and/or memory savings in certain hardware implementations and also to
facilitate the lazy coding mode and error resilience. */
/*****************************************************************************/
/* ebcot_block_info */
/*****************************************************************************/
typedef
struct ebcot_block_info {
int top_row, left_col, rows, cols;
dst_heap_unit_ptr first_unit;
int first_pos;
/* CRIL Technology/SAIC Scan Buffer begin */
dst_heap_unit_ptr next_unit;
int next_unit_used;
/* CRIL Technology/SAIC Scan Buffer end */
int max_passes, num_passes, old_passes;
ebcot_pass_info_ptr passes;
int insignificant_msbs;
int byte_count_bits, old_byte_count_bits;
} ebcot_block_info, *ebcot_block_info_ptr;
/* This structure maintains summary information for each coded block.
An array of these structures is managed from the `ebcot_band_info'
structure, with one entry for each block in the subband within the
relevant tile. Pointers into this array are also managed by the
`ebcot_precinct_band_info' structure which represents an organization of
the blocks in the subband into precincts. 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
relative to the upper left hand sample in the relevant subband-tile.
They are not expressed relative to the absolute canvas coordinate system.
`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.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -