java.lang.Object
nom.tam.fits.compression.algorithm.hcompress.HDecompress

public class HDecompress extends 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:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    private static class 
     
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final byte
     
    private static final byte
     
    private static final byte
     
    private static final byte
     
    private int
    Number of bits still in buffer
    private int
    Bits waiting to be input
    private static final byte[]
     
    private static final int[]
     
    private static final int
    these N constants are obscuring the algorithm and should get some explaining javadoc if somebody understands the algorithm.
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private static final int
     
    private int
     
    private int
     
    private int
     
    private static final byte
     
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    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
    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(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(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
    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
     
    private int
     
    private int
    inputNbits(ByteBuffer infile, int n)
     
    private int
    inputNnybble(ByteBuffer infile, int n, byte[] array)
     
    private int
     
    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(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 (invalid input: '<'=n) int nbitplanes; number of bitplanes to decode
    private void
    qtreeExpand(ByteBuffer infile, byte[] a, int nx2, int ny2, byte[] b)
     
    private void
    readBdirect64(ByteBuffer infile, HDecompress.LongArrayPointer a, int n, int nqx, int nqy, byte[] scratch, int bit)
     
    private void
     
    private void
     
    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
  • Field Details

  • Constructor Details

    • HDecompress

      public HDecompress()
  • Method Details

    • calculateLog2N

      private int calculateLog2N(int nmax)
      log2n is log2 of max(nx,ny) rounded up to next power of 2
    • decode64

      private void decode64(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(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(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(ByteBuffer infile)
    • inputHuffman

      private int inputHuffman(ByteBuffer infile)
    • inputNbits

      private int inputNbits(ByteBuffer infile, int n)
    • inputNnybble

      private int inputNnybble(ByteBuffer infile, int n, byte[] array)
    • inputNybble

      private int inputNybble(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(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 (invalid input: '<'=n) int nbitplanes; number of bitplanes to decode
    • qtreeExpand

      private void qtreeExpand(ByteBuffer infile, byte[] a, int nx2, int ny2, byte[] b)
    • readBdirect64

      private void readBdirect64(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