                         
                         var bitPattern: UInt64 = 0
                         for (i, slice) in _slices.enumerated() {
-                            var byte = read_channel(source + _bitsOffset >> 3, _bitsOffset & 7, i)
+                            var byte = read_channel(source + _bitsOffset >> 3, _bitsOffset & 7, i, slice.count)
                             if slice.count != 8 {
                                 byte >>= 8 - slice.count
                             }

        }
        
        @inline(__always)
        func read_channel(_ source: UnsafePointer<UInt8>, _ offset: Int, _ i: Int) -> UInt8 {
            switch channel.endianness {
            case .big: return channelShift == 0 ? read_pixel(source, offset, i + channelBytesOffset) : (read_pixel(source, offset, i + channelBytesOffset) << channelShift) | (read_pixel(source, offset, i + 1 + channelBytesOffset) >> (8 - channelShift))
            case .little: return read_pixel(source, offset, bytesPerChannel - i - 1 + channelBytesOffset)
            }
        }

                                    let byte: UInt8
                                    if i == 0 && channel.bitRange.count & 7 != 0 {
                                        let mask = ~((0xFF as UInt8) >> (channel.bitRange.count & 7))
                                        byte = read_channel(source + _bitsOffset >> 3, _bitsOffset & 7, tiff_predictor_record.count - i - 1, channel.bitRange.count & 7) & mask
                                    } else {
                                        byte = read_channel(source + _bitsOffset >> 3, _bitsOffset & 7, tiff_predictor_record.count - i - 1, 8)
                                    }
                                    if overflow {
                                        let (_add, _overflow) = tiff_predictor_record[i].addingReportingOverflow(1)
