             guard let data = context.data else { return nil }
             let rgba = data.assumingMemoryBound(to: UInt8.self)
 
-            return SimpleColor(red: rgba[0], green: rgba[1], blue: rgba[2], alpha: rgba[3]).uiColor
+            return SimpleColor(rawValues: .init(red: rgba[0], green: rgba[1], blue: rgba[2], alpha: rgba[3])).uiColor
         }
         return storedValue(for: &UIImage_averageColorKey, generatedBy: getAverageColor)
     }


public extension UIImage {
    private struct SimpleColor<Val: UnsignedInteger>: Hashable {
        let raw: (red: Val, green: Val, blue: Val, alpha: Val)

        let rgba: Ref<Lazy<RGBA>>
        let hsba: Ref<Lazy<HSBA>>

        var uiColor: UIColor { return rgba.nestedValue.color }
        var intensity: CGFloat { return hsba.nestedValue.saturation + hsba.nestedValue.brightness }

        func hash(into hasher: inout Hasher) {
            hasher.combine(raw.red)
            hasher.combine(raw.green)
            hasher.combine(raw.blue)
            hasher.combine(raw.alpha)
        }

        init(red: Val, green: Val, blue: Val, alpha: Val) {
            raw = (red, green, blue, alpha)

            let rgbaRef = Ref(value: Lazy({
                return RGBA(
                    red: CGFloat(red) / 255.0,
                    green: CGFloat(green) / 255.0,
                    blue: CGFloat(blue) / 255.0,
                    alpha: CGFloat(alpha) / 255.0
                )
            }))
            rgba = rgbaRef
            hsba = Ref(value: Lazy({ rgbaRef.nestedValue.toHSBA() }))
        }

        public static func ==(lhs: SimpleColor, rhs: SimpleColor) -> Bool {
            return lhs.raw == rhs.raw
        }
    }

            // translate/flip the graphics context (for transforming from CG* coords to UI* coordinates)
            context.translateBy(x: 0.0, y: -1.0)
            context.scaleBy(x: 1.0, y: -1.0)

            context.setBlendMode(.colorBurn)
            context.draw(cgImage, in: rect)
            context.clip(to: rect, mask: cgImage)
            context.addRect(rect)
            context.drawPath(using: .fill)
        }

        guard let cgImage = cgImage else { return nil }
        let rect = CGRect(origin: .zero, size: size)

        if #available(iOS 10, *) {
            let renderer = UIGraphicsImageRenderer(size: size)
            return renderer.image {
