         self.bytesPerRow = bytesPerRow
         self.startsRow = startsRow
         self.tiff_predictor = tiff_predictor
-        self.channels = channels.sorted { $0.bitRange.lowerBound }
+        self.channels = channels
         self.data = data
-    }
-    
-    public var isCompact: Bool {
-        return channels.first?.bitRange.lowerBound == 0
-            && channels.last?.bitRange.upperBound == bitsPerPixel
-            && zip(channels, channels.dropFirst()).allSatisfy { $0.bitRange.upperBound == $1.bitRange.lowerBound }
     }
 }
 

                
            }
            
        case let colorSpace as ColorSpace<RGBColorModel>:
            
            if bitmaps.allSatisfy({ $0.bitsPerPixel == $0.channels.count * 8 && $0.isCompact && $0.channels.allSatisfy { $0.format == .unsigned } }) {
                
                var image = Image<RGBA32ColorPixel>(width: width, height: height, resolution: resolution, colorSpace: colorSpace, fileBacked: fileBacked)
                
                for bitmap in bitmaps {
                    image._read_compact_pixels(bitmap, is_opaque, UInt8.self)
                }
                
                if premultiplied {
                    image._decode_premultiplied()
                }
                
                return image
                
            } else if bitmaps.allSatisfy({ $0.bitsPerPixel == $0.channels.count * 16 && $0.isCompact && $0.channels.allSatisfy { $0.format == .unsigned } }) {
                
                var image = Image<RGBA64ColorPixel>(width: width, height: height, resolution: resolution, colorSpace: colorSpace, fileBacked: fileBacked)
                
                for bitmap in bitmaps {
                    image._read_compact_pixels(bitmap, is_opaque, UInt16.self)
                }
                
                if premultiplied {
                    image._decode_premultiplied()
                }
                
                return image
                
            }
            
        default: break
        }
        
        if bitmaps.allSatisfy({ ($0.bitsPerPixel == $0.channels.count * 8 && $0.isCompact && $0.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed }) ||
            ($0.bitsPerPixel == $0.channels.count * 16 && $0.isCompact && $0.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed }) ||
            ($0.bitsPerPixel == $0.channels.count * 32 && $0.isCompact && $0.channels.allSatisfy { $0.format == .float }) }) {
            
            var image = Image<FloatColorPixel<Model>>(width: width, height: height, resolution: resolution, colorSpace: self, fileBacked: fileBacked)
            
            for bitmap in bitmaps {
                
                let bitsPerSample = bitmap.bitsPerPixel / bitmap.channels.count
                
                for (channel_idx, channel) in bitmap.channels.enumerated() {
                    switch (bitsPerSample, channel.format) {
                    case (8, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt8.self, Float.self)
                    case (8, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int8.self, Float.self)
                    case (16, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt16.self, Float.self)
                    case (16, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int16.self, Float.self)
                    case (32, .float): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Float.self, Float.self)
                    default: break
                    }
                }
            }
            
            if premultiplied {
                image._decode_premultiplied()
            }
            
            return image
            
        } else {
            
            var image = Image<ColorPixel<Model>>(width: width, height: height, resolution: resolution, colorSpace: self, fileBacked: fileBacked)
            
            for bitmap in bitmaps {
                
                if (bitmap.bitsPerPixel == bitmap.channels.count * 8 && bitmap.isCompact && bitmap.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed }) ||
                    (bitmap.bitsPerPixel == bitmap.channels.count * 16 && bitmap.isCompact && bitmap.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed }) ||
                    (bitmap.bitsPerPixel == bitmap.channels.count * 32 && bitmap.isCompact && bitmap.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed || $0.format == .float }) ||
                    (bitmap.bitsPerPixel == bitmap.channels.count * 64 && bitmap.isCompact && bitmap.channels.allSatisfy { $0.format == .unsigned || $0.format == .signed || $0.format == .float }) {
                    
                    let bitsPerSample = bitmap.bitsPerPixel / bitmap.channels.count
                    
                    for (channel_idx, channel) in bitmap.channels.enumerated() {
                        switch (bitsPerSample, channel.format) {
                        case (8, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt8.self, Double.self)
                        case (8, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int8.self, Double.self)
                        case (16, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt16.self, Double.self)
                        case (16, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int16.self, Double.self)
                        case (32, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt32.self, Double.self)
                        case (32, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int32.self, Double.self)
                        case (32, .float): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Float.self, Double.self)
                        case (64, .unsigned): image._read_compact_pixels(bitmap, channel_idx, is_opaque, UInt64.self, Double.self)
                        case (64, .signed): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Int64.self, Double.self)
                        case (64, .float): image._read_compact_pixels(bitmap, channel_idx, is_opaque, Double.self, Double.self)
                        default: break
                        }
                    }
                    
                } else {
                    
                    for channel in bitmap.channels {
                        
                    }
                }
            }
            
            if premultiplied {
                image._decode_premultiplied()
            }
            
            return image
            
        }
    }
}

        
        self.withUnsafeMutableBytes {
            
            guard var dest = $0.baseAddress?.bindMemory(to: R.self, capacity: Pixel.numberOfComponents * $0.count) else { return }
            
            let row = Pixel.numberOfComponents * width
            
            dest += bitmap.startsRow * row
            
            var data = bitmap.data
            
            for _ in bitmap.startsRow..<height {
                
                let _length = min(bitmap.bytesPerRow, data.count)
                guard _length != 0 else { return }
                
                data.popFirst(bitmap.bytesPerRow).withUnsafeBytes { (bytes: UnsafePointer<UInt8>) in
                    
                    var destination = dest
                    var source = UnsafeRawPointer(bytes)
                    let source_end = source + _length
                    
                    for _ in 0..<width {
                        
                        guard source + bytesPerPixel <= source_end else { return }
                        
                        let _destination = destination + channel.index
                        let _source = source + byteOffset
                        
                        switch channel.endianness {
                        case .big: _destination.pointee = _denormalized(R(T(bitPattern: T.BitPattern(bigEndian: _source.bindMemory(to: T.BitPattern.self, capacity: 1).pointee))))
                        case .little: _destination.pointee = _denormalized(R(T(bitPattern: T.BitPattern(littleEndian: _source.bindMemory(to: T.BitPattern.self, capacity: 1).pointee))))
                        }
                        
                        source += bytesPerPixel
                        
                        if is_opaque {
                            destination[Pixel.numberOfComponents - 1] = 1
                        }
                        
                        destination += Pixel.numberOfComponents
                    }
                    
                    dest += row
                }
            }
        }
