Class HCompress


  • public class HCompress
    extends java.lang.Object
    The original compression code was written by Richard 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
    • Constructor Summary

      Constructors 
      Constructor Description
      HCompress()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private int b2i​(boolean b)  
      private int bufcopy​(byte[] a, int n, byte[] buffer, int b, long bmax)  
      protected void compress​(long[] aa, int ny, int nx, int scale, java.nio.ByteBuffer output)  
      private java.nio.LongBuffer copy​(java.nio.LongBuffer a, int i)  
      private void digitize​(java.nio.LongBuffer a, int aOffset, int nx, int ny, long scale)  
      private void doEncode​(java.nio.ByteBuffer compressedBytes, java.nio.LongBuffer pixels, int nx, int ny, byte[] nbitplanes)
      encode pixels.
      private void doneOutputtingBits​(java.nio.ByteBuffer outfile)  
      private int encode​(java.nio.ByteBuffer compressedBytes, java.nio.LongBuffer a, int nx, int ny, int scale)  
      private int htrans​(long[] a, int nx, int ny)  
      private int log2n​(int nqmax)  
      private void outputNbits​(java.nio.ByteBuffer outfile, int bits, int n)  
      private void outputNnybble​(java.nio.ByteBuffer outfile, int n, byte[] array)  
      private void outputNybble​(java.nio.ByteBuffer outfile, int bits)  
      private int qtreeEncode​(java.nio.ByteBuffer outfile, java.nio.LongBuffer a, int n, int nqx, int nqy, int nbitplanes)
      macros to write out 4-bit nybble, Huffman code for this value
      private void qtreeOnebit​(java.nio.LongBuffer a, int n, int nx, int ny, byte[] b, int bit)  
      private void qtreeReduce​(byte[] a, int n, int nx, int ny, byte[] b)  
      private void shuffle​(long[] a, int aOffset, int n, int n2, long[] tmp)  
      private void startOutputtingBits()  
      private void writeBdirect​(java.nio.ByteBuffer outfile, java.nio.LongBuffer a, int n, int nqx, int nqy, byte[] scratch, int bit)  
      • Methods inherited from class java.lang.Object

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

      • BITS_MASK

        private static final int[] BITS_MASK
      • CODE

        private static final int[] CODE
      • CODE_MAGIC

        private static final byte[] CODE_MAGIC
      • NCODE

        private static final int[] NCODE
      • bitbuffer

        private int bitbuffer
        variables for bit output to buffer when Huffman coding
      • bitsToGo2

        private int bitsToGo2
        Number of bits free in buffer
      • bitsToGo3

        private int bitsToGo3
      • buffer2

        private int buffer2
        Bits buffered for output
    • Constructor Detail

      • HCompress

        public HCompress()
    • Method Detail

      • b2i

        private int b2i​(boolean b)
      • bufcopy

        private int bufcopy​(byte[] a,
                            int n,
                            byte[] buffer,
                            int b,
                            long bmax)
      • compress

        protected void compress​(long[] aa,
                                int ny,
                                int nx,
                                int scale,
                                java.nio.ByteBuffer output)
      • copy

        private java.nio.LongBuffer copy​(java.nio.LongBuffer a,
                                         int i)
      • digitize

        private void digitize​(java.nio.LongBuffer a,
                              int aOffset,
                              int nx,
                              int ny,
                              long scale)
      • doEncode

        private void doEncode​(java.nio.ByteBuffer compressedBytes,
                              java.nio.LongBuffer pixels,
                              int nx,
                              int ny,
                              byte[] nbitplanes)
        encode pixels.
        Parameters:
        compressedBytes - compressed data
        pixels - pixels to compress
        nx - image width dimension
        ny - image height dimension
        nbitplanes - Number of bit planes in quadrants
      • doneOutputtingBits

        private void doneOutputtingBits​(java.nio.ByteBuffer outfile)
      • encode

        private int encode​(java.nio.ByteBuffer compressedBytes,
                           java.nio.LongBuffer a,
                           int nx,
                           int ny,
                           int scale)
      • htrans

        private int htrans​(long[] a,
                           int nx,
                           int ny)
      • log2n

        private int log2n​(int nqmax)
      • outputNbits

        private void outputNbits​(java.nio.ByteBuffer outfile,
                                 int bits,
                                 int n)
      • outputNnybble

        private void outputNnybble​(java.nio.ByteBuffer outfile,
                                   int n,
                                   byte[] array)
      • outputNybble

        private void outputNybble​(java.nio.ByteBuffer outfile,
                                  int bits)
      • qtreeEncode

        private int qtreeEncode​(java.nio.ByteBuffer outfile,
                                java.nio.LongBuffer a,
                                int n,
                                int nqx,
                                int nqy,
                                int nbitplanes)
        macros to write out 4-bit nybble, Huffman code for this value
      • qtreeOnebit

        private void qtreeOnebit​(java.nio.LongBuffer a,
                                 int n,
                                 int nx,
                                 int ny,
                                 byte[] b,
                                 int bit)
      • qtreeReduce

        private void qtreeReduce​(byte[] a,
                                 int n,
                                 int nx,
                                 int ny,
                                 byte[] b)
      • shuffle

        private void shuffle​(long[] a,
                             int aOffset,
                             int n,
                             int n2,
                             long[] tmp)
      • startOutputtingBits

        private void startOutputtingBits()
      • writeBdirect

        private void writeBdirect​(java.nio.ByteBuffer outfile,
                                  java.nio.LongBuffer a,
                                  int n,
                                  int nqx,
                                  int nqy,
                                  byte[] scratch,
                                  int bit)