public class EBCOTRateAllocator extends PostCompRateAllocator
This implementation also provides some timing features. They can be enabled by setting the 'DO_TIMING' constant of this class to true and recompiling. The timing uses the 'System.currentTimeMillis()' Java API call, which returns wall clock time, not the actual CPU time used. The timing results will be printed on the message output. Since the times reported are wall clock times and not CPU usage times they can not be added to find the total used time (i.e. some time might be counted in several places). When timing is disabled ('DO_TIMING' is false) there is no penalty if the compiler performs some basic optimizations. Even if not the penalty should be negligeable.
Modifier and Type | Field and Description |
---|---|
private long |
buildTime
The wall time for the building of layers.
|
private CBlkRateDistStats[][][][][] |
cblks
5D Array containing all the coded code-blocks:
1st index: tile index
2nd index: component index
3rd index: resolution level index
4th index: subband index
5th index: code-block index
|
private static boolean |
DO_TIMING
Whether to collect timing information or not: false.
|
private static float |
FLOAT_ABS_PRECISION
The precision for float data type, in an absolute sense.
|
private static float |
FLOAT_REL_PRECISION
The relative precision for float data.
|
private long |
initTime
The wall time for the initialization.
|
private EBCOTLayer[] |
layers
Array containing the layers information.
|
private static double |
LOG2
The log of 2, natural base
|
private LayersInfo |
lyrSpec
The layer specifications
|
private float |
maxSlope
The maximum slope accross all code-blocks and truncation points.
|
private static int |
MIN_AVG_PACKET_SZ
Minimum average size of a packet.
|
private float |
minSlope
The minimum slope accross all code-blocks and truncation points.
|
private Point[][][] |
numPrec
Maximum number of precincts :
1st dim: tile index.
2nd dim: component index.
3nd dim: resolution level index.
|
private PktEncoder |
pktEnc
Packet encoder.
|
private static int |
RD_SUMMARY_OFF
The normalization offset for the R-D summary table
|
private static int |
RD_SUMMARY_SIZE
The size of the summary table
|
private int[] |
RDSlopesRates
The R-D summary information collected from the coding of all
code-blocks.
|
private int[][][][][][] |
truncIdxs
6D Array containing the indices of the truncation points.
|
private long |
writeTime
The wall time for the writing of layers.
|
bsWriter, headEnc, numLayers, OPT_PREFIX, src, wp
imgdatasrc, tIdx
Constructor and Description |
---|
EBCOTRateAllocator(CodedCBlkDataSrcEnc src,
LayersInfo lyrs,
CodestreamWriter writer,
J2KImageWriteParamJava wp)
Initializes the EBCOT rate allocator of entropy coded data.
|
Modifier and Type | Method and Description |
---|---|
private void |
buildAndWriteLayers()
This method builds all the bit stream layers and then writes them to
the output bit stream.
|
private float |
estimateLayerThreshold(int targetBytes,
EBCOTLayer lastLayer)
This function attempts to estimate a rate-distortion slope threshold
which will achieve a target number of code bytes close the
`targetBytes' value.
|
void |
finalize()
Prints the timing information, if collected, and calls 'finalize' on
the super class.
|
private void |
findTruncIndices(int layerIdx,
int compIdx,
int lvlIdx,
int tileIdx,
SubbandAn subb,
float fthresh,
int precinctIdx)
This function finds the new truncation points indices for a packet.
|
private void |
getAllCodeBlocks()
This method gets all the coded code-blocks from the EBCOT entropy coder
for every component and every tile.
|
private static int |
getLimitedSIndexFromSlope(float slope)
Returns the index of a slope for the summary table, limiting to the
admissible values.
|
private static float |
getSlopeFromSIndex(int index)
Returns the minimum slope value associated with a summary table
index.
|
void |
initialize()
Initializes the layers array.
|
private float |
optimizeBitstreamLayer(int layerIdx,
float fmaxt,
int maxBytes,
int prevBytes)
This function implements the rate-distortion optimization algorithm.
|
void |
runAndWrite()
Runs the rate allocation algorithm and writes the data to the bit
stream writer object provided to the constructor.
|
void |
writeCompPosResLy(int t,
int rs,
int re,
int cs,
int ce,
int[][] lys,
int lye)
Write a piece of bit stream according to the
COMP_POS_RES_LY_PROG progression mode and between given bounds
|
void |
writeLyResCompPos(int t,
int rs,
int re,
int cs,
int ce,
int[][] lys,
int lye)
Write a piece of bit stream according to the
LY_RES_COMP_POS_PROG progression mode and between given bounds
|
void |
writePosCompResLy(int t,
int rs,
int re,
int cs,
int ce,
int[][] lys,
int lye)
Write a piece of bit stream according to the
COMP_POS_RES_LY_PROG progression mode and between given bounds
|
void |
writeResLyCompPos(int t,
int rs,
int re,
int cs,
int ce,
int[][] lys,
int lye)
Write a piece of bit stream according to the
RES_LY_COMP_POS_PROG progression mode and between given bounds
|
void |
writeResPosCompLy(int t,
int rs,
int re,
int cs,
int ce,
int[][] lys,
int lye)
Write a piece of bit stream according to the
RES_POS_COMP_LY_PROG progression mode and between given bounds
|
createInstance, getNumLayers, getParameterInfo, setHeaderEncoder
getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getCompULX, getCompULY, getImgHeight, getImgULX, getImgULY, getImgWidth, getNomRangeBits, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth, nextTile, setTile
private static final boolean DO_TIMING
private long initTime
private long buildTime
private long writeTime
private CBlkRateDistStats[][][][][] cblks
private int[][][][][][] truncIdxs
private Point[][][] numPrec
private EBCOTLayer[] layers
private static final double LOG2
private static final int RD_SUMMARY_OFF
private static final int RD_SUMMARY_SIZE
private static final float FLOAT_REL_PRECISION
private static final float FLOAT_ABS_PRECISION
private static final int MIN_AVG_PACKET_SZ
private int[] RDSlopesRates
Therefore, the length at entry 'k' is the total number of bytes of code-block data that would be obtained if the truncation slope was chosen as '2*(k-RD_SUMMARY_OFF)', without counting the overhead associated with the packet heads.
This summary is used to estimate the relation of the R-D slope to coded length, and to obtain absolute minimums on the slope given a length.
private PktEncoder pktEnc
private LayersInfo lyrSpec
private float maxSlope
private float minSlope
public EBCOTRateAllocator(CodedCBlkDataSrcEnc src, LayersInfo lyrs, CodestreamWriter writer, J2KImageWriteParamJava wp)
src
- The source of entropy coded data.lyrs
- The layers layout specification.writer
- The bit stream writer.ProgressionType
public void finalize() throws Throwable
public void runAndWrite() throws IOException
runAndWrite
in class PostCompRateAllocator
IOException
PostCompRateAllocator.initialize()
public void initialize() throws IOException
initialize
in class PostCompRateAllocator
IOException
PostCompRateAllocator.runAndWrite()
private void getAllCodeBlocks()
For each code-block, the valid slopes are computed and converted into the mantissa-exponent representation.
private void buildAndWriteLayers() throws IOException
IOException
public void writeResLyCompPos(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws IOException
t
- Tile index.rs
- First resolution level index.re
- Last resolution level index.cs
- First component index.ce
- Last component index.lys
- First layer index for each component and resolution.lye
- Index of the last layer.IOException
public void writeLyResCompPos(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws IOException
t
- Tile index.rs
- First resolution level index.re
- Last resolution level index.cs
- First component index.ce
- Last component index.lys
- First layer index for each component and resolution.lye
- Index of the last layer.IOException
public void writePosCompResLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws IOException
t
- Tile index.rs
- First resolution level index.re
- Last resolution level index.cs
- First component index.ce
- Last component index.lys
- First layer index for each component and resolution.lye
- Index of the last layer.IOException
public void writeCompPosResLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws IOException
t
- Tile index.rs
- First resolution level index.re
- Last resolution level index.cs
- First component index.ce
- Last component index.lys
- First layer index for each component and resolution.lye
- Index of the last layer.IOException
public void writeResPosCompLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws IOException
t
- Tile index.rs
- First resolution level index.re
- Last resolution level index.cs
- First component index.ce
- Last component index.lys
- First layer index for each component and resolution.lye
- Last layer index.IOException
private float optimizeBitstreamLayer(int layerIdx, float fmaxt, int maxBytes, int prevBytes) throws IOException
layerIdx
- The index of the current layerfmaxt
- The maximum admissible slope value. Normally the threshold
slope of the previous layer.maxBytes
- The maximum number of bytes that can be written. It
includes the length of the current layer bistream length and all the
previous layers bit streams.prevBytes
- The number of bytes of all the previous layers.IOException
private float estimateLayerThreshold(int targetBytes, EBCOTLayer lastLayer)
targetBytes
- The target number of bytes for the current layerlastLayer
- The previous layer information.private void findTruncIndices(int layerIdx, int compIdx, int lvlIdx, int tileIdx, SubbandAn subb, float fthresh, int precinctIdx)
layerIdx
- The index of the current layercompIdx
- The index of the current componentlvlIdx
- The index of the current resolution leveltileIdx
- The index of the current tilesubb
- The LL subband in the resolution level lvlIdx, which is
parent of all the subbands in the packet. Except for resolution level 0
this subband is always a node.fthresh
- The value of the rate-distortion thresholdprivate static int getLimitedSIndexFromSlope(float slope)
If the value to return is lower than 0, 0 is returned. If it is larger than the maximum table index, then the maximum is returned.
slope
- The slope valueprivate static float getSlopeFromSIndex(int index)
index
- The summary index value.Copyright © 2016 Open Microscopy Environment