         }
         
         @inline(__always)
-        func read_channel(_ source: UnsafePointer<UInt8>, _ offset: Int, _ i: Int) -> UInt8 {
+        func read_channel(_ source: UnsafePointer<UInt8>, _ offset: Int, _ i: Int, _ bits_count: 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 .big: return channelBitsShift + bits_count <= 8 ? read_pixel(source, offset, i + channelBytesOffset) << channelBitsShift : (read_pixel(source, offset, i + channelBytesOffset) << channelBitsShift) | (read_pixel(source, offset, i + 1 + channelBytesOffset) >> (8 - channelBitsShift))
             case .little: return read_pixel(source, offset, bytesPerChannel - i - 1 + channelBytesOffset)
             }
         }

                                
                                var bitPattern: UInt64 = 0
                                for i in 0..<8 {
                                    bitPattern = (bitPattern << 8) | UInt64(read_channel(source + _bitsOffset >> 3, _bitsOffset & 7, i))
                                }
                                
                                _d = bitPattern

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