                                 let channelShift = channel.bitRange.lowerBound & 7
                                 let bytesPerChannel = channel.bitRange.count >> 3
                                 
+                                @inline(__always)
                                 func channelByte(_ i: Int) -> UInt8 {
                                     switch channel.endianness {
                                     case .big: return channelShift == 0 ? pixelByte(i + channelBytesOffset) : (pixelByte(i + channelBytesOffset) << channelShift) | (pixelByte(i + 1 + channelBytesOffset) >> (8 - channelShift))


        var data = [Data]()
        
        func encode(_ value: Double, _ data: inout Data) {
            switch format {
            case .unsigned:

                                
                                switch channel.format {
                                case .unsigned:
                                    
                                    if channel.bitRange.count > 64 {
                                        for (i, slice) in channel.bitRange.slice(by: 8).enumerated() {
                                            value = Double(sign: value.sign, exponentBitPattern: value.exponentBitPattern + UInt(slice.count), significandBitPattern: value.significandBitPattern) + Double(channelByte(i) & UInt8((1 << slice.count) - 1))
                                        }
                                    } else {
                                        var bitPattern: UInt64 = 0
                                        for (i, slice) in channel.bitRange.slice(by: 8).enumerated() {
                                            bitPattern = (bitPattern << slice.count) | UInt64(channelByte(i))
                                        }
                                        value = Double(bitPattern)
                                    }
                                    
                                    value /= Double(sign: .plus, exponent: channel.bitRange.count, significand: 1) - 1
                                    
                                case .signed:
                                    
                                    var signed = false
                                    
                                    if channel.bitRange.count > 64 {
                                        for (i, slice) in channel.bitRange.slice(by: 8).enumerated() {
                                            let byte = channelByte(i)
                                            if i == 0 && byte & 0x80 != 0 {
                                                signed = true
                                            }
                                            value = Double(sign: value.sign, exponentBitPattern: value.exponentBitPattern + UInt(slice.count), significandBitPattern: value.significandBitPattern) + Double(byte & UInt8((1 << slice.count) - 1))
                                        }
                                    } else {
                                        var bitPattern: UInt64 = 0
                                        for (i, slice) in channel.bitRange.slice(by: 8).enumerated() {
                                            let byte = channelByte(i)
                                            if i == 0 && byte & 0x80 != 0 {
                                                signed = true
                                            }
                                            bitPattern = (bitPattern << slice.count) | UInt64(byte)
                                        }
                                        value = Double(bitPattern)
                                    }
                                    
                                    value = Double(sign: value.sign, exponentBitPattern: value.exponentBitPattern - UInt(channel.bitRange.count), significandBitPattern: value.significandBitPattern)
