Class HDecompress


  • public class HDecompress
    extends java.lang.Object
    The 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
    See Also:
    http://www.stsci.edu/software/hcompress.html
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte BIT_FOUR  
      private static byte BIT_ONE  
      private static byte BIT_THREE  
      private static byte BIT_TWO  
      private int bitsToGo
      Number of bits still in buffer
      private int buffer2
      Bits waiting to be input
      private static byte[] CODE_MAGIC  
      private static int[] MASKS  
      private static int N03
      these N constants are obscuring the algorithm and should get some explaining javadoc if somebody understands the algorithm.
      private static int N04  
      private static int N05  
      private static int N06  
      private static int N07  
      private static int N08  
      private static int N09  
      private static int N10  
      private static int N11  
      private static int N12  
      private static int N13  
      private static int N14  
      private static int N15  
      private static int N26  
      private static int N27  
      private static int N28  
      private static int N29  
      private static int N30  
      private static int N31  
      private static int N62  
      private static int N63  
      private int nx  
      private int ny  
      private int scale  
      private static byte ZERO  
    • Constructor Summary

      Constructors 
      Constructor Description
      HDecompress()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int calculateLog2N​(int nmax)
      log2n is log2 of max(nx,ny) rounded up to next power of 2
      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
      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.
      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
      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
      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
      private int inputBit​(java.nio.ByteBuffer infile)  
      private int inputHuffman​(java.nio.ByteBuffer infile)  
      private int inputNbits​(java.nio.ByteBuffer infile, int n)  
      private int inputNnybble​(java.nio.ByteBuffer infile, int n, byte[] array)  
      private int inputNybble​(java.nio.ByteBuffer infile)  
      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.
      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
      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
      private void qtreeExpand​(java.nio.ByteBuffer infile, byte[] a, int nx2, int ny2, byte[] b)  
      private void readBdirect64​(java.nio.ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, byte[] scratch, int bit)  
      private void startInputingBits()  
      private void undigitize64​(HDecompress.LongArrayPointer a)  
      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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HDecompress

        public HDecompress()
    • 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 decompress
        smooth - should the image be smoothed
        aa - 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()
      • 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