public class StdEntropyCoder extends EntropyCoder implements StdEntropyCoderOptions
The number of threads used by this entropy coder is specified by the "jj2000.j2k.entropy.encoder.StdEntropyCoder.nthreads" Java system property. If set to "0" the single threaded implementation is used. If set to 'n' ('n' larger than 0) then 'n' extra threads are started by this class which are used to encode the code-blocks in parallel (i.e. ideally 'n' code-blocks will be encoded in parallel at a time). On multiprocessor machines under a "native threads" Java Virtual Machine implementation each one of these threads can run on a separate processor speeding up the encoding time. By default the single-threaded implementation is used. The multi-threaded implementation currently assumes that the vast majority of consecutive calls to 'getNextCodeBlock()' will be done on the same component. If this is not the case, the speed-up that can be expected on multiprocessor machines might be significantly decreased.
The code-blocks are rectangular, with dimensions which must be powers of 2. Each dimension has to be no smaller than 4 and no larger than 256. The product of the two dimensions (i.e. area of the code-block) may not exceed 4096.
Context 0 of the MQ-coder is used as the uniform one (uniform, non-adaptive probability distribution). Context 1 is used for RLC coding. Contexts 2-10 are used for zero-coding (ZC), contexts 11-15 are used for sign-coding (SC) and contexts 16-18 are used for magnitude-refinement (MR).
This implementation buffers the symbols and calls the MQ coder only once per stripe and per coding pass, to reduce the method call overhead.
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.
The source module must implement the CBlkQuantDataSrcEnc interface and code-block's data is received in a CBlkWTData instance. This modules sends code-block's information in a CBlkRateDistStats instance.
CBlkQuantDataSrcEnc
,
CBlkWTData
,
CBlkRateDistStats
Modifier and Type | Class and Description |
---|---|
private class |
StdEntropyCoder.Compressor
Class that takes care of running the 'compressCodeBlock()' method with
thread local arguments.
|
Modifier and Type | Field and Description |
---|---|
StringSpec |
bms
By-pass mode specifications
|
private BitToByteOutput[] |
boutT
The raw bit output used, for each thread
|
private CBlkSizeSpec |
cblks
The code-block size specifications
|
private Stack[] |
completedComps
The queue of completed compressors, for each component.
|
StringSpec |
css
Causal stripes specifications
|
private int[][] |
ctxtbufT
Buffer for the contexts to use when sending buffered symbols to the
MQ-coder, for each thread.
|
static String |
DEF_THREADS_NUM
The default value for the property in THREADS_PROP_NAME: 0
|
private double[][] |
distbufT
The buffer for distortion values (avoids reallocation for each
code-block), for each thread.
|
private static boolean |
DO_TIMING
Whether to collect timing information or not: false.
|
private boolean[] |
finishedTileComponent
A flag indicating for each component if all the code-blocks of the *
current tile have been returned.
|
private static int[] |
FM_LOSSLESS
Distortion estimation lookup table for bits coded using the
magnitude-refinement (MR) primative, for lossless coding and last
bit-plane.
|
private static int[] |
FM_LOSSY
Distortion estimation lookup table for bits coded using the
magnitude-refinement (MR) primative, for lossy coding (i.e.
|
private static int[] |
FS_LOSSLESS
Distortion estimation lookup table for bits coded using the sign-code
(SC) primative, for lossless coding and last bit-plane.
|
private static int[] |
FS_LOSSY
Distortion estimation lookup table for bits coded using the sign-code
(SC) primative, for lossy coding (i.e.
|
private Stack |
idleComps
The queue of idle compressors.
|
private static int |
INT_SIGN_BIT
The sign bit for int data
|
private boolean[][] |
istermbufT
The buffer for indicating terminated passes (avoids reallocation for
each code-block), for each thread.
|
StringSpec |
lcs
The length calculation specifications
|
private int[][] |
lenCalc
The length calculation type for each tile-component
|
private static int[] |
MQ_INIT
The initial states for the MQ coder
|
StringSpec |
mqrs
MQ reset specifications
|
private MQCoder[] |
mqT
The MQ coder used, for each thread
|
private static int[] |
MR_LUT
Magnitude Refinement context lookup table
|
private static int |
MR_LUT_BITS
The number of bits used for the Magnitude Refinement lookup table
|
private static int |
MR_MASK
The mask to obtain the MR index to 'MR_LUT' from the 'state'
information.
|
private static int |
MSE_LKP_BITS
The number of bits used to index in the 'fm' lookup table, 7.
|
private static int |
MSE_LKP_FRAC_BITS
The number of fractional bits used to store data in the 'fm' and 'fs'
lookup tables.
|
private int[] |
nBusyComps
The number of busy compressors, for each component.
|
private static int |
NUM_CTXTS
The number of contexts used
|
private int[][] |
opts
The options that are turned on, as flag bits.
|
private ByteOutputBuffer[] |
outT
The output stream used, for each thread
|
private boolean[][] |
precinctPartition
boolean used to signal if the precinct partition is used for
each component and each tile.
|
private PrecinctSizeSpec |
pss
The precinct partition specifications
|
private int[][] |
ratebufT
The buffer for rate values (avoids reallocation for each
code-block), for each thread.
|
private static int |
RLC_CTXT
The RLC context
|
private static int |
RLC_MASK_R1R2
The mask to isolate the bits necessary to identify RLC coding state
(significant, visited and non-zero context, for row 1 and 2).
|
StringSpec |
rts
Regular termination specifications
|
private static int[] |
SC_LUT
Sign Coding context lookup table.
|
private static int |
SC_LUT_BITS
Number of bits used for the Sign Coding lookup table
|
private static int |
SC_LUT_MASK
The mask to obtain the context index from the 'SC_LUT'
|
private static int |
SC_MASK
The bit mask to isolate the state bits relative to the sign coding
lookup table ('SC_LUT').
|
private static int |
SC_SHIFT_R1
The shift to obtain the SC index to 'SC_LUT' from the state
information, for row 1.
|
private static int |
SC_SHIFT_R2
The shift to obtain the SC index to 'SC_LUT' from the state
information, for row 2.
|
private static int |
SC_SPRED_SHIFT
The shift to obtain the sign predictor from the 'SC_LUT'.
|
private static int[] |
SEG_SYMB_CTXTS
The 4 contexts for the segmentation marker (always the UNIFORM context,
UNIF_CTXT)
|
private static int[] |
SEG_SYMBOLS
The 4 symbol segmentation marker (1010)
|
private static int |
SIG_MASK_R1R2
The mask to isolate the significance bits for row 1 and 2 of the state
array.
|
private CBlkWTData[] |
srcblkT
The source code-block to entropy code (avoids reallocation for each
code-block), for each thread.
|
StringSpec |
sss
Error resilience segment symbol use specifications
|
private static int |
STATE_D_DL_R1
The flag bit for the diagonal down-left significance in the state
array, for row 1.
|
private static int |
STATE_D_DL_R2
The flag bit for the diagonal down-left significance in the state
array, for row 2.
|
private static int |
STATE_D_DR_R1
The flag bit for the diagonal down-right significance in the state
array , for row 1.
|
private static int |
STATE_D_DR_R2
The flag bit for the diagonal down-right significance in the state
array , for row 2.
|
private static int |
STATE_D_UL_R1
The flag bit for the diagonal up-left significance in the state array,
for row 1.
|
private static int |
STATE_D_UL_R2
The flag bit for the diagonal up-left significance in the state array,
for row 2.
|
private static int |
STATE_D_UR_R1
The flag bit for the diagonal up-right significance in the state
array, for row 1.
|
private static int |
STATE_D_UR_R2
The flag bit for the diagonal up-right significance in the state
array, for row 2.
|
private static int |
STATE_H_L_R1
The flag bit for the horizontal-left significance in the state array,
for row 1.
|
private static int |
STATE_H_L_R2
The flag bit for the horizontal-left significance in the state array,
for row 2.
|
private static int |
STATE_H_L_SIGN_R1
The flag bit for the horizontal-left sign in the state array, for row
1.
|
private static int |
STATE_H_L_SIGN_R2
The flag bit for the horizontal-left sign in the state array, for row
2.
|
private static int |
STATE_H_R_R1
The flag bit for the horizontal-right significance in the state array,
for row 1.
|
private static int |
STATE_H_R_R2
The flag bit for the horizontal-right significance in the state array,
for row 2.
|
private static int |
STATE_H_R_SIGN_R1
The flag bit for the horizontal-right sign in the state array, for
row 1.
|
private static int |
STATE_H_R_SIGN_R2
The flag bit for the horizontal-right sign in the state array, for
row 2.
|
private static int |
STATE_NZ_CTXT_R1
The flag bit for the "not zero context" bit in the state array, for
row 1.
|
private static int |
STATE_NZ_CTXT_R2
The flag bit for the "not zero context" bit in the state array, for
row 2.
|
private static int |
STATE_PREV_MR_R1
The flag bit for the previous MR primitive applied in the state array,
for row 1.
|
private static int |
STATE_PREV_MR_R2
The flag bit for the previous MR primitive applied in the state array,
for row 2.
|
private static int |
STATE_SEP |
private static int |
STATE_SIG_R1
The flag bit for the significance in the state array, for row 1.
|
private static int |
STATE_SIG_R2
The flag bit for the significance in the state array, for row 2.
|
private static int |
STATE_V_D_R1
The flag bit for the vertical-down significance in the state array,
for row 1.
|
private static int |
STATE_V_D_R2
The flag bit for the vertical-down significance in the state array,
for row 2.
|
private static int |
STATE_V_D_SIGN_R1
The flag bit for the vertical-down sign in the state array, for row
1.
|
private static int |
STATE_V_D_SIGN_R2
The flag bit for the vertical-down sign in the state array, for row
2.
|
private static int |
STATE_V_U_R1
The flag bit for the vertical-up significance in the state array, for
row 1.
|
private static int |
STATE_V_U_R2
The flag bit for the vertical-up significance in the state array, for
row 2.
|
private static int |
STATE_V_U_SIGN_R1
The flag bit for the vertical-up sign in the state array, for row
1.
|
private static int |
STATE_V_U_SIGN_R2
The flag bit for the vertical-up sign in the state array, for row
2.
|
private static int |
STATE_VISITED_R1
The flag bit for the "visited" bit in the state array, for row 1.
|
private static int |
STATE_VISITED_R2
The flag bit for the "visited" bit in the state array, for row 2.
|
private int[][] |
stateT
The state array for each thread.
|
private int[][] |
symbufT
Buffer for symbols to send to the MQ-coder, for each thread.
|
static int |
THREADS_PRIORITY_INC
The increase in priority for the compressor threads, currently 3.
|
static String |
THREADS_PROP_NAME
The Java system property name for the number of threads to use:
jj2000.j2k.entropy.encoder.StdEntropyCoder.nthreads
|
private long[] |
time
The cumulative wall time for the entropy coding engine, for each
component.
|
private ThreadPool |
tPool
The pool of threads, for the threaded implementation.
|
StringSpec |
tts
The termination type specifications
|
private int[][] |
tType
The termination type for each tile-component
|
private static int |
UNIF_CTXT
The UNIFORM context (with a uniform probability distribution which
does not adapt)
|
private static int |
VSTD_MASK_R1R2
The mask to isolate the visited bits for row 1 and 2 of the state
array.
|
private static int |
ZC_LUT_BITS
Number of bits used for the Zero Coding lookup table
|
private static int[] |
ZC_LUT_HH
Zero Coding context lookup tables for the HH global orientation
|
private static int[] |
ZC_LUT_HL
Zero Coding context lookup tables for the HL global orientation
|
private static int[] |
ZC_LUT_LH
Zero Coding context lookup tables for the LH global orientation
|
private static int |
ZC_MASK
The mask to obtain the ZC_LUT index from the state information
|
OPT_PREFIX, src
imgdatasrc, tIdx
FIRST_BYPASS_PASS_IDX, MAX_CB_AREA, MAX_CB_DIM, MIN_CB_DIM, NUM_EMPTY_PASSES_IN_MS_BP, NUM_NON_BYPASS_MS_BP, NUM_PASSES, OPT_BYPASS, OPT_PRED_TERM, OPT_RESET_MQ, OPT_SEG_SYMBOLS, OPT_TERM_PASS, OPT_VERT_STR_CAUSAL, STRIPE_HEIGHT
Constructor and Description |
---|
StdEntropyCoder(CBlkQuantDataSrcEnc src,
CBlkSizeSpec cblks,
PrecinctSizeSpec pss,
StringSpec bms,
StringSpec mqrs,
StringSpec rts,
StringSpec css,
StringSpec sss,
StringSpec lcs,
StringSpec tts)
Instantiates a new entropy coder engine, with the specified source of
data, nominal block width and height.
|
Modifier and Type | Method and Description |
---|---|
private static int |
calcSkipMSBP(CBlkWTData cblk,
int lmb)
Calculates the number of magnitude bit-planes that are to be skipped,
because they are non-significant.
|
private static void |
checkEndOfPassFF(byte[] data,
int[] rates,
boolean[] isterm,
int n)
Ensures that at the end of a non-terminated coding pass there is not a
0xFF byte, modifying the stored rates if necessary.
|
private static int |
cleanuppass(CBlkWTData srcblk,
MQCoder mq,
boolean doterm,
int bp,
int[] state,
int[] fs,
int[] zc_lut,
int[] symbuf,
int[] ctxtbuf,
int[] ratebuf,
int pidx,
int ltpidx,
int options)
Performs the cleanup pass on the specified data and bit-plane.
|
private static void |
compressCodeBlock(int c,
CBlkRateDistStats ccb,
CBlkWTData srcblk,
MQCoder mq,
BitToByteOutput bout,
ByteOutputBuffer out,
int[] state,
double[] distbuf,
int[] ratebuf,
boolean[] istermbuf,
int[] symbuf,
int[] ctxtbuf,
int options,
boolean rev,
int lcType,
int tType)
Compresses the code-block in 'srcblk' and puts the results in 'ccb',
using the specified options and temporary storage.
|
void |
finalize()
Prints the timing information, if collected, and calls 'finalize' on
the super class.
|
int |
getCBlkHeight(int t,
int c)
Returns the code-block height for the specified tile and component.
|
int |
getCBlkWidth(int t,
int c)
Returns the code-block width for the specified tile and component.
|
CBlkRateDistStats |
getNextCodeBlock(int c,
CBlkRateDistStats ccb)
Returns the next coded code-block in the current tile for the specified
component, as a copy (see below).
|
int |
getPPX(int t,
int c,
int rl)
Returns the precinct partition width for the specified
component, tile and resolution level.
|
int |
getPPY(int t,
int c,
int rl)
Returns the precinct partition height for the specified
component, tile and resolution level.
|
void |
initTileComp(int nt,
int nc)
Load options, length calculation type and termination type for
each tile-component.
|
private static int |
magRefPass(CBlkWTData srcblk,
MQCoder mq,
boolean doterm,
int bp,
int[] state,
int[] fm,
int[] symbuf,
int[] ctxtbuf,
int[] ratebuf,
int pidx,
int ltpidx,
int options)
Performs the magnitude refinement pass on the specified data and
bit-plane.
|
void |
nextTile()
Advances to the next tile, in standard scan-line order (by rows
then columns).
|
boolean |
precinctPartitionUsed(int c,
int t)
Returns true if precinct partition is used for the specified
component and tile, returns false otherwise.
|
private static int |
rawMagRefPass(CBlkWTData srcblk,
BitToByteOutput bout,
boolean doterm,
int bp,
int[] state,
int[] fm,
int[] ratebuf,
int pidx,
int ltpidx,
int options)
Performs the magnitude refinement pass on the specified data and
bit-plane, without using the arithmetic coder.
|
private static int |
rawSigProgPass(CBlkWTData srcblk,
BitToByteOutput bout,
boolean doterm,
int bp,
int[] state,
int[] fs,
int[] ratebuf,
int pidx,
int ltpidx,
int options)
Performs the significance propagation pass on the specified data and
bit-plane, without using the arithmetic coder.
|
void |
setTile(int x,
int y)
Changes the current tile, given the new indexes.
|
private static int |
sigProgPass(CBlkWTData srcblk,
MQCoder mq,
boolean doterm,
int bp,
int[] state,
int[] fs,
int[] zc_lut,
int[] symbuf,
int[] ctxtbuf,
int[] ratebuf,
int pidx,
int ltpidx,
int options)
Performs the significance propagation pass on the specified data and
bit-plane.
|
createInstance, getAnSubbandTree, getCbULX, getCbULY, getParameterInfo, isReversible
getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getCompULX, getCompULY, getImgHeight, getImgULX, getImgULY, getImgWidth, getNomRangeBits, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCompImgHeight, getCompImgWidth, getCompSubsX, getCompSubsY, getCompULX, getCompULY, getImgHeight, getImgULX, getImgULY, getImgWidth, getNomRangeBits, getNomTileHeight, getNomTileWidth, getNumComps, getNumTiles, getNumTiles, getTile, getTileCompHeight, getTileCompWidth, getTileHeight, getTileIdx, getTilePartULX, getTilePartULY, getTileWidth
private static final boolean DO_TIMING
private long[] time
public static final String THREADS_PROP_NAME
public static final String DEF_THREADS_NUM
public static final int THREADS_PRIORITY_INC
private ThreadPool tPool
private Stack idleComps
private Stack[] completedComps
private int[] nBusyComps
private boolean[] finishedTileComponent
private MQCoder[] mqT
private BitToByteOutput[] boutT
private ByteOutputBuffer[] outT
private CBlkSizeSpec cblks
private PrecinctSizeSpec pss
public StringSpec bms
public StringSpec mqrs
public StringSpec rts
public StringSpec css
public StringSpec sss
public StringSpec lcs
public StringSpec tts
private int[][] opts
StdEntropyCoderOptions
private int[][] lenCalc
private int[][] tType
private static final int ZC_LUT_BITS
private static final int[] ZC_LUT_LH
private static final int[] ZC_LUT_HL
private static final int[] ZC_LUT_HH
private static final int SC_LUT_BITS
private static final int[] SC_LUT
private static final int SC_LUT_MASK
private static final int SC_SPRED_SHIFT
private static final int INT_SIGN_BIT
private static final int MR_LUT_BITS
private static final int[] MR_LUT
private static final int NUM_CTXTS
private static final int RLC_CTXT
private static final int UNIF_CTXT
private static final int[] MQ_INIT
private static final int[] SEG_SYMBOLS
private static final int[] SEG_SYMB_CTXTS
private int[][] stateT
The state of a coefficient is stored in the following way in the lower 16 bits, where bit 0 is the least significant bit. Bit 15 is the significance of a coefficient (0 if non-significant, 1 otherwise). Bit 14 is the visited state (i.e. if a coefficient has been coded in the significance propagation pass of the current bit-plane). Bit 13 is the "non zero-context" state (i.e. if one of the eight immediate neighbors is significant it is 1, otherwise is 0). Bits 12 to 9 store the sign of the already significant left, right, up and down neighbors (1 for negative, 0 for positive or not yet significant). Bit 8 indicates if the magnitude refinement has already been applied to the coefficient. Bits 7 to 4 store the significance of the left, right, up and down neighbors (1 for significant, 0 for non significant). Bits 3 to 0 store the significance of the diagonal coefficients (up-left, up-right, down-left and down-right; 1 for significant, 0 for non significant).
The upper 16 bits the state is stored as in the lower 16 bits, but with the bits shifted up by 16.
The lower 16 bits are referred to as "row 1" ("R1") while the upper 16 bits are referred to as "row 2" ("R2").
private static final int STATE_SEP
private static final int STATE_SIG_R1
private static final int STATE_VISITED_R1
private static final int STATE_NZ_CTXT_R1
private static final int STATE_H_L_SIGN_R1
private static final int STATE_H_R_SIGN_R1
private static final int STATE_V_U_SIGN_R1
private static final int STATE_V_D_SIGN_R1
private static final int STATE_PREV_MR_R1
private static final int STATE_H_L_R1
private static final int STATE_H_R_R1
private static final int STATE_V_U_R1
private static final int STATE_V_D_R1
private static final int STATE_D_UL_R1
private static final int STATE_D_UR_R1
private static final int STATE_D_DL_R1
private static final int STATE_D_DR_R1
private static final int STATE_SIG_R2
private static final int STATE_VISITED_R2
private static final int STATE_NZ_CTXT_R2
private static final int STATE_H_L_SIGN_R2
private static final int STATE_H_R_SIGN_R2
private static final int STATE_V_U_SIGN_R2
private static final int STATE_V_D_SIGN_R2
private static final int STATE_PREV_MR_R2
private static final int STATE_H_L_R2
private static final int STATE_H_R_R2
private static final int STATE_V_U_R2
private static final int STATE_V_D_R2
private static final int STATE_D_UL_R2
private static final int STATE_D_UR_R2
private static final int STATE_D_DL_R2
private static final int STATE_D_DR_R2
private static final int SIG_MASK_R1R2
private static final int VSTD_MASK_R1R2
private static final int RLC_MASK_R1R2
private static final int ZC_MASK
private static final int SC_SHIFT_R1
private static final int SC_SHIFT_R2
private static final int SC_MASK
private static final int MR_MASK
private static final int MSE_LKP_BITS
private static final int MSE_LKP_FRAC_BITS
private static final int[] FS_LOSSY
private static final int[] FM_LOSSY
private static final int[] FS_LOSSLESS
private static final int[] FM_LOSSLESS
private double[][] distbufT
private int[][] ratebufT
private boolean[][] istermbufT
private CBlkWTData[] srcblkT
private int[][] symbufT
private int[][] ctxtbufT
private boolean[][] precinctPartition
public StdEntropyCoder(CBlkQuantDataSrcEnc src, CBlkSizeSpec cblks, PrecinctSizeSpec pss, StringSpec bms, StringSpec mqrs, StringSpec rts, StringSpec css, StringSpec sss, StringSpec lcs, StringSpec tts)
If the 'OPT_PRED_TERM' option is given then the MQ termination must be 'TERM_PRED_ER' or an exception is thrown.
src
- The source of datacblks
- Code-block size specificationspss
- Precinct partition specificationsbms
- By-pass mode specificationsmqrs
- MQ-reset specificationsrts
- Regular termination specificationscss
- Causal stripes specificationssss
- Error resolution segment symbol use specificationslcs
- Length computation specificationstts
- Termination type specificationsMQCoder
public void finalize() throws Throwable
public int getCBlkWidth(int t, int c)
getCBlkWidth
in class EntropyCoder
t
- The tile indexc
- the component indexpublic int getCBlkHeight(int t, int c)
getCBlkHeight
in class EntropyCoder
t
- The tile indexc
- The component indexpublic CBlkRateDistStats getNextCodeBlock(int c, CBlkRateDistStats ccb)
When changing the current tile (through 'setTile()' or 'nextTile()') this method will always return the first code-block, as if this method was never called before for the new current tile.
The data returned by this method is always a copy of the internal data of this object, if any, and it can be modified "in place" without any problems after being returned.
getNextCodeBlock
in interface CodedCBlkDataSrcEnc
c
- The component for which to return the next code-block.ccb
- If non-null this object might be used in returning the coded
code-block in this or any subsequent call to this method. If null a new
one is created and returned. If the 'data' array of 'cbb' is not null
it may be reused to return the compressed data.CBlkRateDistStats
public void setTile(int x, int y)
This default implementation just changes the tile in the source.
setTile
in interface ImgData
setTile
in class ImgDataAdapter
x
- The horizontal index of the tile.y
- The vertical index of the new tile.public void nextTile()
This default implementation just advances to the next tile in the source.
nextTile
in interface ImgData
nextTile
in class ImgDataAdapter
private static void compressCodeBlock(int c, CBlkRateDistStats ccb, CBlkWTData srcblk, MQCoder mq, BitToByteOutput bout, ByteOutputBuffer out, int[] state, double[] distbuf, int[] ratebuf, boolean[] istermbuf, int[] symbuf, int[] ctxtbuf, int options, boolean rev, int lcType, int tType)
c
- The component for which to return the next code-block.ccb
- The object where the compressed data will be stored. If the
'data' array of 'cbb' is not null it may be reused to return the
compressed data.srcblk
- The code-block data to codemq
- The MQ-coder to usebout
- The bit level output to use. Used only if 'OPT_BYPASS' is
turned on in the 'options' argument.out
- The byte buffer trough which the compressed data is stored.state
- The state information for the code-blockdistbuf
- The buffer where to store the distortion at
the end of each coding pass.ratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of each coding pass.istermbuf
- The buffer where to store the terminated flag for each
coding pass.symbuf
- The buffer to hold symbols to send to the MQ coderctxtbuf
- A buffer to hold the contexts to use in sending the
buffered symbols to the MQ coder.options
- The options to use when coding this code-blockrev
- The reversible flag. Should be true if the source of this
code-block's data is reversible.lcType
- The type of length calculation to use with the MQ coder.tType
- The type of termination to use with the MQ coder.getNextCodeBlock(int, jj2000.j2k.entropy.encoder.CBlkRateDistStats)
private static int calcSkipMSBP(CBlkWTData cblk, int lmb)
cblk
- The code-block of data to scanlmb
- The least significant magnitude bit in the dataprivate static int sigProgPass(CBlkWTData srcblk, MQCoder mq, boolean doterm, int bp, int[] state, int[] fs, int[] zc_lut, int[] symbuf, int[] ctxtbuf, int[] ratebuf, int pidx, int ltpidx, int options)
srcblk
- The code-block data to codemq
- The MQ-coder to usedoterm
- If true it performs an MQ-coder termination after the end
of the passbp
- The bit-plane to codestate
- The state information for the code-blockfs
- The distortion estimation lookup table for SCzc_lut
- The ZC lookup table to use in ZC.symbuf
- The buffer to hold symbols to send to the MQ coderctxtbuf
- A buffer to hold the contexts to use in sending the
buffered symbols to the MQ coder.ratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of this coding pass.pidx
- The coding pass index. Is the index in the 'ratebuf' array
where to store the coded length after this coding pass.ltpidx
- The index of the last pass that was terminated, or
negative if none.options
- The bitmask of entropy coding options to apply to the
code-blockprivate static int rawSigProgPass(CBlkWTData srcblk, BitToByteOutput bout, boolean doterm, int bp, int[] state, int[] fs, int[] ratebuf, int pidx, int ltpidx, int options)
In this method, the arithmetic coder is bypassed, and raw bits are directly written in the bit stream (useful when distribution are close to uniform, for intance, at high bit-rates and at lossless compression).
srcblk
- The code-block data to codebout
- The bit based outputdoterm
- If true the bit based output is byte aligned after the
end of the pass.bp
- The bit-plane to codestate
- The state information for the code-blockfs
- The distortion estimation lookup table for SCratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of this coding pass.pidx
- The coding pass index. Is the index in the 'ratebuf' array
where to store the coded length after this coding pass.ltpidx
- The index of the last pass that was terminated, or
negative if none.options
- The bitmask of entropy coding options to apply to the
code-blockprivate static int magRefPass(CBlkWTData srcblk, MQCoder mq, boolean doterm, int bp, int[] state, int[] fm, int[] symbuf, int[] ctxtbuf, int[] ratebuf, int pidx, int ltpidx, int options)
srcblk
- The code-block data to codemq
- The MQ-coder to usedoterm
- If true it performs an MQ-coder termination after the end
of the passbp
- The bit-plane to codestate
- The state information for the code-blockfm
- The distortion estimation lookup table for MRsymbuf
- The buffer to hold symbols to send to the MQ coderctxtbuf
- A buffer to hold the contexts to use in sending the
buffered symbols to the MQ coder.ratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of this coding pass.pidx
- The coding pass index. Is the index in the 'ratebuf' array
where to store the coded length after this coding pass.ltpidx
- The index of the last pass that was terminated, or
negative if none.options
- The bitmask of entropy coding options to apply to the
code-blockprivate static int rawMagRefPass(CBlkWTData srcblk, BitToByteOutput bout, boolean doterm, int bp, int[] state, int[] fm, int[] ratebuf, int pidx, int ltpidx, int options)
In this method, the arithmetic coder is bypassed, and raw bits are directly written in the bit stream (useful when distribution are close to uniform, for intance, at high bit-rates and at lossless compression). The 'STATE_PREV_MR_R1' and 'STATE_PREV_MR_R2' bits are not set because they are used only when the arithmetic coder is not bypassed.
srcblk
- The code-block data to codebout
- The bit based outputdoterm
- If true the bit based output is byte aligned after the
end of the pass.bp
- The bit-plane to codestate
- The state information for the code-blockfm
- The distortion estimation lookup table for MRratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of this coding pass.pidx
- The coding pass index. Is the index in the 'ratebuf' array
where to store the coded length after this coding pass.ltpidx
- The index of the last pass that was terminated, or
negative if none.options
- The bitmask of entropy coding options to apply to the
code-blockprivate static int cleanuppass(CBlkWTData srcblk, MQCoder mq, boolean doterm, int bp, int[] state, int[] fs, int[] zc_lut, int[] symbuf, int[] ctxtbuf, int[] ratebuf, int pidx, int ltpidx, int options)
srcblk
- The code-block data to codemq
- The MQ-coder to usedoterm
- If true it performs an MQ-coder termination after the end
of the passbp
- The bit-plane to codestate
- The state information for the code-blockfs
- The distortion estimation lookup table for SCzc_lut
- The ZC lookup table to use in ZC.symbuf
- The buffer to hold symbols to send to the MQ coderctxtbuf
- A buffer to hold the contexts to use in sending the
buffered symbols to the MQ coder.ratebuf
- The buffer where to store the rate (i.e. coded lenth) at
the end of this coding pass.pidx
- The coding pass index. Is the index in the 'ratebuf' array
where to store the coded length after this coding pass.ltpidx
- The index of the last pass that was terminated, or
negative if none.options
- The bitmask of entropy coding options to apply to the
code-blockprivate static void checkEndOfPassFF(byte[] data, int[] rates, boolean[] isterm, int n)
Due to error resiliance reasons, a coding pass should never have its last byte be a 0xFF, since that can lead to the emulation of a resync marker. This method checks if that is the case, and reduces the rate for a given pass if necessary. The ommitted 0xFF will be synthetized by the decoder if necessary, as required by JPEG 2000. This method should only be called once that the entire code-block is coded.
Passes that are terminated are not checked for the 0xFF byte, since it is assumed that the termination procedure does not output any trailing 0xFF. Checking the terminated segments would involve much more than just modifying the stored rates.
NOTE: It is assumed by this method that the coded data does not contain consecutive 0xFF bytes, as is the case with the MQ and 'arithemetic coding bypass' bit stuffing policy. However, the termination policies used should also respect this requirement.
data
- The coded data for the code-blockrates
- The rate (i.e. accumulated number of bytes) for each
coding passisterm
- An array of flags indicating, for each pass, if it is
terminated or not. If null it is assumed that no pass is terminated,
except the last one.n
- The number of coding passespublic void initTileComp(int nt, int nc)
nt
- The number of tilesnc
- The number of componentspublic int getPPX(int t, int c, int rl)
getPPX
in interface CodedCBlkDataSrcEnc
t
- the tile indexc
- the componentrl
- the resolution levelpublic int getPPY(int t, int c, int rl)
getPPY
in interface CodedCBlkDataSrcEnc
t
- the tile indexc
- the componentrl
- the resolution levelpublic boolean precinctPartitionUsed(int c, int t)
precinctPartitionUsed
in interface CodedCBlkDataSrcEnc
c
- The componentt
- The tileCopyright © 2015 Open Microscopy Environment