             guard self.bitsPerSample[0] == 8 else { throw ImageRep.Error.Unsupported("Unsupported bits per sample.") }
             if let colorMap = tags.first(where: { $0.tag == .ColorMap }) {
                 let offset = colorMap.offset
-                let length = 3 << self.bitsPerSample[0]
-                self.palette = data.dropFirst(offset).prefix(length)
+                let _count = 1 << self.bitsPerSample[0]
+                let _size = _count << 1
+                let _red = data.dropFirst(offset).prefix(_size) as Data
+                let _green = data.dropFirst(offset + _size).prefix(_size) as Data
+                let _blue = data.dropFirst(offset + _size << 1).prefix(_size) as Data
+                
+                guard _red.count == _size && _green.count == _size && _blue.count == _size else { throw ImageRep.Error.Unsupported("Unexpected end of palette data.") }
+                
+                self.palette.reserveCapacity(_count)
+                
+                switch self.endianness {
+                case .BIG:
+                    _red.withUnsafeBytes { (_red: UnsafePointer<BEUInt16>) in _green.withUnsafeBytes { (_green: UnsafePointer<BEUInt16>) in _blue.withUnsafeBytes { (_blue: UnsafePointer<BEUInt16>) in
+                        
+                        var _red = _red
+                        var _green = _green
+                        var _blue = _blue
+                        for _ in 0..<_count {
+                            self.palette.append((_red.pointee.representingValue, _green.pointee.representingValue, _blue.pointee.representingValue))
+                            _red += 1
+                            _green += 1
+                            _blue += 1
+                        }
+                        
+                        } } }
+                case .LITTLE:
+                    _red.withUnsafeBytes { (_red: UnsafePointer<LEUInt16>) in _green.withUnsafeBytes { (_green: UnsafePointer<LEUInt16>) in _blue.withUnsafeBytes { (_blue: UnsafePointer<LEUInt16>) in
+                        
+                        var _red = _red
+                        var _green = _green
+                        var _blue = _blue
+                        for _ in 0..<_count {
+                            self.palette.append((_red.pointee.representingValue, _green.pointee.representingValue, _blue.pointee.representingValue))
+                            _red += 1
+                            _green += 1
+                            _blue += 1
+                        }
+                        
+                        } } }
+                default: fatalError()
+                }
             }
         case 4: guard self.samplesPerPixel == 1 else { throw ImageRep.Error.InvalidFormat("Invalid samples count.") }
         default: guard self.samplesPerPixel >= self.colorSpace.numberOfComponents else { throw ImageRep.Error.InvalidFormat("Invalid samples count.") }

        case 1:
            if photometric == 3 {
                
                var image = Image<ARGB32ColorPixel>(width: width, height: height, colorSpace: colorSpace.base as! ColorSpace<RGBColorModel>)
                
                image.withUnsafeMutableBufferPointer { uncompressedPalettePixelReader($0.baseAddress) }
                

            }
        }
        
        palette.withUnsafeBufferPointer {
            
            guard let palette = $0.baseAddress else { return }
            
            let palette_count = self.palette.count
            
            var remain = height
            let rowSize = width
