Class HDecompress
- java.lang.Object
-
- nom.tam.fits.compression.algorithm.hcompress.HDecompress
-
public class HDecompress extends java.lang.ObjectThe original decompression code was written by R. White at the STScI and included (ported to c and adapted) in cfitsio by William Pence, NASA/GSFC. That code was then ported to java by R. van Nieuwenhoven. Later it was massively refactored to harmonize the different compression algorithms and reduce the duplicate code pieces without obscuring the algorithm itself as far as possible. The original site for the algorithm is
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classHDecompress.LongArrayPointer
-
Field Summary
Fields Modifier and Type Field Description private static byteBIT_FOURprivate static byteBIT_ONEprivate static byteBIT_THREEprivate static byteBIT_TWOprivate intbitsToGoNumber of bits still in bufferprivate intbuffer2Bits waiting to be inputprivate static byte[]CODE_MAGICprivate static int[]MASKSprivate static intN03these N constants are obscuring the algorithm and should get some explaining javadoc if somebody understands the algorithm.private static intN04private static intN05private static intN06private static intN07private static intN08private static intN09private static intN10private static intN11private static intN12private static intN13private static intN14private static intN15private static intN26private static intN27private static intN28private static intN29private static intN30private static intN31private static intN62private static intN63private intnxprivate intnyprivate intscaleprivate static byteZERO
-
Constructor Summary
Constructors Constructor Description HDecompress()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private intcalculateLog2N(int nmax)log2n is log2 of max(nx,ny) rounded up to next power of 2private voiddecode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a)char *infile; input file long *a; address of output tiledImageOperation [nx][ny] int *nx,*ny; size of output tiledImageOperation int *scale; scale factor for digitizationvoiddecompress(java.nio.ByteBuffer input, boolean smooth, long[] aa)decompress the input byte stream using the H-compress algorithm input - input tiledImageOperation of compressed bytes a - pre-allocated tiledImageOperation to hold the output uncompressed image nx - returned X axis size ny - returned Y axis size NOTE: the nx and ny dimensions as defined within this code are reversed from the usual FITS notation.private intdodecode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, byte[] nbitplanes)long a[]; int nx,ny; Array dimensions are [nx][ny] unsigned char nbitplanes[3]; Number of bit planes in quadrantsprivate inthinv64(HDecompress.LongArrayPointer a, boolean smooth)int smooth; 0 for no smoothing, else smooth during inversion int scale; used if smoothing is specifiedprivate voidhsmooth64(HDecompress.LongArrayPointer a, int nxtop, int nytop)long a[]; tiledImageOperation of H-transform coefficients int nxtop,nytop; size of coefficient block to use int ny; actual 1st dimension of tiledImageOperation int scale; truncation scale factor that was usedprivate intinputBit(java.nio.ByteBuffer infile)private intinputHuffman(java.nio.ByteBuffer infile)private intinputNbits(java.nio.ByteBuffer infile, int n)private intinputNnybble(java.nio.ByteBuffer infile, int n, byte[] array)private intinputNybble(java.nio.ByteBuffer infile)private voidqtreeBitins64(byte[] a, int lnx, int lny, HDecompress.LongArrayPointer b, int n, int bit)Copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding each value to 2x2 pixels and inserting into bitplane BIT of B.private voidqtreeCopy(byte[] a, int lnx, int lny, byte[] b, int n)copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding each value to 2x2 pixels a,b may be same tiledImageOperationprivate intqtreeDecode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, int nbitplanes)char *infile; long a[]; a is 2-D tiledImageOperation with dimensions (n,n) int n; length of full row in a int nqx; partial length of row to decode int nqy; partial length of column (<=n) int nbitplanes; number of bitplanes to decodeprivate voidqtreeExpand(java.nio.ByteBuffer infile, byte[] a, int nx2, int ny2, byte[] b)private voidreadBdirect64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, byte[] scratch, int bit)private voidstartInputingBits()private voidundigitize64(HDecompress.LongArrayPointer a)private voidunshuffle64(HDecompress.LongArrayPointer a, int n, int n2, long[] tmp)long a[]; tiledImageOperation to shuffle int n; number of elements to shuffle int n2; second dimension long tmp[]; scratch storage
-
-
-
Field Detail
-
CODE_MAGIC
private static final byte[] CODE_MAGIC
-
MASKS
private static final int[] MASKS
-
ZERO
private static final byte ZERO
- See Also:
- Constant Field Values
-
BIT_ONE
private static final byte BIT_ONE
- See Also:
- Constant Field Values
-
BIT_TWO
private static final byte BIT_TWO
- See Also:
- Constant Field Values
-
BIT_THREE
private static final byte BIT_THREE
- See Also:
- Constant Field Values
-
BIT_FOUR
private static final byte BIT_FOUR
- See Also:
- Constant Field Values
-
N03
private static final int N03
these N constants are obscuring the algorithm and should get some explaining javadoc if somebody understands the algorithm.- See Also:
- Constant Field Values
-
N04
private static final int N04
- See Also:
- Constant Field Values
-
N05
private static final int N05
- See Also:
- Constant Field Values
-
N06
private static final int N06
- See Also:
- Constant Field Values
-
N07
private static final int N07
- See Also:
- Constant Field Values
-
N08
private static final int N08
- See Also:
- Constant Field Values
-
N09
private static final int N09
- See Also:
- Constant Field Values
-
N10
private static final int N10
- See Also:
- Constant Field Values
-
N11
private static final int N11
- See Also:
- Constant Field Values
-
N12
private static final int N12
- See Also:
- Constant Field Values
-
N13
private static final int N13
- See Also:
- Constant Field Values
-
N14
private static final int N14
- See Also:
- Constant Field Values
-
N15
private static final int N15
- See Also:
- Constant Field Values
-
N26
private static final int N26
- See Also:
- Constant Field Values
-
N27
private static final int N27
- See Also:
- Constant Field Values
-
N28
private static final int N28
- See Also:
- Constant Field Values
-
N29
private static final int N29
- See Also:
- Constant Field Values
-
N30
private static final int N30
- See Also:
- Constant Field Values
-
N31
private static final int N31
- See Also:
- Constant Field Values
-
N62
private static final int N62
- See Also:
- Constant Field Values
-
N63
private static final int N63
- See Also:
- Constant Field Values
-
bitsToGo
private int bitsToGo
Number of bits still in buffer
-
buffer2
private int buffer2
Bits waiting to be input
-
nx
private int nx
-
ny
private int ny
-
scale
private int scale
-
-
Method Detail
-
calculateLog2N
private int calculateLog2N(int nmax)
log2n is log2 of max(nx,ny) rounded up to next power of 2
-
decode64
private void decode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a)char *infile; input file long *a; address of output tiledImageOperation [nx][ny] int *nx,*ny; size of output tiledImageOperation int *scale; scale factor for digitization- Parameters:
infile-a-
-
decompress
public void decompress(java.nio.ByteBuffer input, boolean smooth, long[] aa)decompress the input byte stream using the H-compress algorithm input - input tiledImageOperation of compressed bytes a - pre-allocated tiledImageOperation to hold the output uncompressed image nx - returned X axis size ny - returned Y axis size NOTE: the nx and ny dimensions as defined within this code are reversed from the usual FITS notation. ny is the fastest varying dimension, which is usually considered the X axis in the FITS image display- Parameters:
input- the input buffer to decompresssmooth- should the image be smoothedaa- the resulting long tiledImageOperation
-
dodecode64
private int dodecode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, byte[] nbitplanes)long a[]; int nx,ny; Array dimensions are [nx][ny] unsigned char nbitplanes[3]; Number of bit planes in quadrants
-
hinv64
private int hinv64(HDecompress.LongArrayPointer a, boolean smooth)
int smooth; 0 for no smoothing, else smooth during inversion int scale; used if smoothing is specified
-
hsmooth64
private void hsmooth64(HDecompress.LongArrayPointer a, int nxtop, int nytop)
long a[]; tiledImageOperation of H-transform coefficients int nxtop,nytop; size of coefficient block to use int ny; actual 1st dimension of tiledImageOperation int scale; truncation scale factor that was used
-
inputBit
private int inputBit(java.nio.ByteBuffer infile)
-
inputHuffman
private int inputHuffman(java.nio.ByteBuffer infile)
-
inputNbits
private int inputNbits(java.nio.ByteBuffer infile, int n)
-
inputNnybble
private int inputNnybble(java.nio.ByteBuffer infile, int n, byte[] array)
-
inputNybble
private int inputNybble(java.nio.ByteBuffer infile)
-
qtreeBitins64
private void qtreeBitins64(byte[] a, int lnx, int lny, HDecompress.LongArrayPointer b, int n, int bit)Copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding each value to 2x2 pixels and inserting into bitplane BIT of B. A,B may NOT be same tiledImageOperation (it wouldn't make sense to be inserting bits into the same tiledImageOperation anyway.)
-
qtreeCopy
private void qtreeCopy(byte[] a, int lnx, int lny, byte[] b, int n)copy 4-bit values from a[(nx+1)/2,(ny+1)/2] to b[nx,ny], expanding each value to 2x2 pixels a,b may be same tiledImageOperation
-
qtreeDecode64
private int qtreeDecode64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, int nbitplanes)char *infile; long a[]; a is 2-D tiledImageOperation with dimensions (n,n) int n; length of full row in a int nqx; partial length of row to decode int nqy; partial length of column (<=n) int nbitplanes; number of bitplanes to decode
-
qtreeExpand
private void qtreeExpand(java.nio.ByteBuffer infile, byte[] a, int nx2, int ny2, byte[] b)
-
readBdirect64
private void readBdirect64(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, byte[] scratch, int bit)
-
startInputingBits
private void startInputingBits()
-
undigitize64
private void undigitize64(HDecompress.LongArrayPointer a)
-
unshuffle64
private void unshuffle64(HDecompress.LongArrayPointer a, int n, int n2, long[] tmp)
long a[]; tiledImageOperation to shuffle int n; number of elements to shuffle int n2; second dimension long tmp[]; scratch storage
-
-