|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--jj2000.j2k.image.ImgDataAdapter | +--jj2000.j2k.entropy.encoder.PostCompRateAllocator | +--jj2000.j2k.entropy.encoder.EBCOTRateAllocator
This implements the EBCOT post compression rate allocation algorithm. This algorithm finds the most suitable truncation points for the set of code-blocks, for each layer target bitrate. It works by first collecting the rate distortion info from all code-blocks, in all tiles and all components, and then running the rate-allocation on the whole image at once, for each layer.
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.
PostCompRateAllocator
,
CodedCBlkDataSrcEnc
,
CodestreamWriter
Field Summary | |
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 Coord[][][] |
numPrec
Number of precincts in each resolution level: 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. |
Fields inherited from class jj2000.j2k.entropy.encoder.PostCompRateAllocator |
bsWriter, encSpec, headEnc, numLayers, OPT_PREFIX, src |
Fields inherited from class jj2000.j2k.image.ImgDataAdapter |
imgdatasrc, tIdx |
Constructor Summary | |
EBCOTRateAllocator(CodedCBlkDataSrcEnc src,
LayersInfo lyrs,
CodestreamWriter writer,
EncoderSpecs encSpec,
ParameterList pl)
Initializes the EBCOT rate allocator of entropy coded data. |
Method Summary | |
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 |
Methods inherited from class jj2000.j2k.entropy.encoder.PostCompRateAllocator |
createInstance, getNumLayers, getParameterInfo, setHeaderEncoder |
Methods inherited from class jj2000.j2k.image.ImgDataAdapter |
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 |
Methods inherited from class java.lang.Object |
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final boolean DO_TIMING
private long initTime
private long buildTime
private long writeTime
private CBlkRateDistStats[][][][][] cblks
private int[][][][][][] truncIdxs
private Coord[][][] 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
Constructor Detail |
public EBCOTRateAllocator(CodedCBlkDataSrcEnc src, LayersInfo lyrs, CodestreamWriter writer, EncoderSpecs encSpec, ParameterList pl)
src
- The source of entropy coded data.lyrs
- The layers layout specification.writer
- The bit stream writer.ProgressionType
Method Detail |
public void finalize() throws java.lang.Throwable
finalize
in class java.lang.Object
java.lang.Throwable
public void runAndWrite() throws java.io.IOException
runAndWrite
in class PostCompRateAllocator
java.io.IOException
PostCompRateAllocator.initialize()
public void initialize() throws java.io.IOException
initialize
in class PostCompRateAllocator
java.io.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 java.io.IOException
java.io.IOException
public void writeResLyCompPos(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws java.io.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.
java.io.IOException
public void writeLyResCompPos(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws java.io.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.
java.io.IOException
public void writePosCompResLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws java.io.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.
java.io.IOException
public void writeCompPosResLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws java.io.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.
java.io.IOException
public void writeResPosCompLy(int t, int rs, int re, int cs, int ce, int[][] lys, int lye) throws java.io.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.
java.io.IOException
private float optimizeBitstreamLayer(int layerIdx, float fmaxt, int maxBytes, int prevBytes) throws java.io.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.
java.io.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 value
private static float getSlopeFromSIndex(int index)
index
- The summary index value.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |