void getSamplesAsBytes(final BitInputStream bis, final int[] result) throws IOException {
        for (int i = 0; i < bitsPerSample.length; i++) {
            final int bits = bitsPerSample[i];
            int sample = bis.readBits(bits);
            if (bits < 8) {
                final int sign = sample & 1;
                sample = sample << 8 - bits; // scale to byte.
                if (sign > 0) {
                    sample = sample | (1 << 8 - bits) - 1; // extend to byte
                }
            } else if (bits > 8) {
                sample = sample >> bits - 8; // extend to byte.
            }
            result[i] = sample;
        }
    }
Reads samples and returns them in an int array.

@param bis    the stream to read from
@param result the samples array to populate, must be the same length as bitsPerSample.length
@throws IOException
src/main/java/org/apache/commons/imaging/formats/tiff/datareaders/AbstractImageDataReader.java