private SubFrameResidual(int partitionOrder, int bits, int escapeCode, BitsReader data) throws IOException {
            this.partitionOrder = partitionOrder;
            numPartitions = 1<<partitionOrder;
            riceParams = new int[numPartitions];

            int numSamples = 0;
            if (partitionOrder > 0) {
                numSamples = blockSize >> partitionOrder;
            } else {
                numSamples = blockSize - predictorOrder;
            }

            for (int pn=0; pn<numPartitions; pn++) {
                int riceParam = data.read(bits);

                int partitionSamples = 0;
                if (partitionOrder == 0 || pn > 0) {
                    partitionSamples = numSamples;
                } else {
                    partitionSamples = numSamples - predictorOrder;
                }

                if (riceParam == escapeCode) {
                    // Partition holds un-encoded binary form
                    riceParam = data.read(5);
                    for (int i=0; i<partitionSamples; i++) {
                        data.read(riceParam);
                    }
                } else {
                    // Partition holds Rice encoded data
                    for (int sn=0; sn<numSamples; sn++) {
                        // Q value stored as zero-based unary
                        data.bitsToNextOne();
                        // R value stored as truncated binary
                        data.read(riceParam);
                    }
                }

                // Record the Rice Parameter for use in unit tests etc
                riceParams[pn] = riceParam;
            }
        }