private short[] uncompressHRD(byte[] compressedData, int nCells)
            throws DescriptorException {
        short[] svalues = new short[nCells];

        int cPos = 0; // position in the compressed data, in bytes

        int nextCell = 0;
        int runLength;
        for (;; nextCell += runLength) {
            //
            // Each run begins with a 16-bin run descriptor.  The
            // high order bit is set if the run consists of bad flags.
            // The remaining 15 bits tell the length of the run.
            // A run length of 1 indicates the end of compressed data.
            //
            short runDescriptor = grabShort(compressedData, cPos);
            cPos += 2;

            boolean runHasGoodValues = ((runDescriptor & 0x8000) != 0);
            runLength = runDescriptor & 0x7fff;

            if (runLength == 1)
                break;
            //
            // Sanity check on run length
            //
            if ((nextCell + runLength) > nCells)
                throw new DescriptorException("attempt to unpack " +
                                                    "too many cells");
            //
            // If the run contains good values, then the next runLength
            // values in the compressed data stream are real values.  Otherwise
            // we need to fill with runLength bad value flags.
            //
            for (int cell = nextCell; cell < nextCell + runLength; cell++) {
                if (runHasGoodValues) {
                    svalues[cell] = grabShort(compressedData, cPos);
                    cPos += 2;
                } else {
                    svalues[cell] = (short)badDataFlag;
                }
            }
        }
        //
        // Fill the remainder of the array (if any) with bad value flags
        //
        for (int cell = nextCell; cell < nCells; cell++)
            svalues[cell] = (short)badDataFlag;

        return svalues;
    }
private short [ ] uncompressHRD ( byte [ ] compressedData , int nCells ) throws DescriptorException { short [ ] svalues = new short [ nCells ] ; int cPos = 0 ; int nextCell = 0 ; int runLength ; for ( ; ; nextCell += runLength ) { short runDescriptor = grabShort ( compressedData , cPos ) ; cPos += 2 ; boolean runHasGoodValues = ( ( runDescriptor & 0x8000 ) != 0 ) ; runLength = runDescriptor & 0x7fff ; if ( runLength == 1 ) break ; if ( ( nextCell + runLength ) > nCells ) throw new DescriptorException ( "attempt to unpack " + "too many cells" ) ; for ( int cell = nextCell ; cell < nextCell + runLength ; cell ++ ) { if ( runHasGoodValues ) { svalues [ cell ] = grabShort ( compressedData , cPos ) ; cPos += 2 ; } else { svalues [ cell ] = ( short ) badDataFlag ; } } } for ( int cell = nextCell ; cell < nCells ; cell ++ ) svalues [ cell ] = ( short ) badDataFlag ; return svalues ; }
Unpack MIT/HRD-compressed data into an array of exactly nCells shorts.
@param compressedData the raw HRD-compressed data array
@return an array of nCells unpacked short values
@throws DescriptorException