diff --git a/Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift b/Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift index 9b2fc8a..f659863 100644 --- a/Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift +++ b/Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift @@ -41,33 +41,61 @@ public struct Colors { } public var rgba: MagickWand.RGBA { - let red = PixelGetRed(self.pointer) - let green = PixelGetGreen(self.pointer) - let blue = PixelGetBlue(self.pointer) - let alpha = PixelGetAlpha(self.pointer) - - return MagickWand.RGBA(red, green, blue, alpha) + get { + let red = PixelGetRed(self.pointer) + let green = PixelGetGreen(self.pointer) + let blue = PixelGetBlue(self.pointer) + let alpha = PixelGetAlpha(self.pointer) + + return MagickWand.RGBA(red, green, blue, alpha) + } + set { + PixelSetRed(self.pointer, newValue.red) + PixelSetGreen(self.pointer, newValue.green) + PixelSetBlue(self.pointer, newValue.blue) + PixelSetAlpha(self.pointer, newValue.alpha) + } } public var hsl: MagickWand.HSL { - var hue: Double = 0 - var saturation: Double = 0 - var lightness: Double = 0 - - PixelGetHSL(self.pointer, &hue, &saturation, &lightness) - - return MagickWand.HSL(hue, saturation, lightness) + get { + var hue: Double = 0 + var saturation: Double = 0 + var lightness: Double = 0 + + PixelGetHSL(self.pointer, &hue, &saturation, &lightness) + + return MagickWand.HSL(hue, saturation, lightness) + } + set { + PixelSetHSL(self.pointer, newValue.hue, newValue.saturation, newValue.lightness) + } } - public var cmyk: MagickWand.CMYK { - let (cyan, magenta, yellow, key) = ( - PixelGetCyan(self.pointer), - PixelGetMagenta(self.pointer), - PixelGetYellow(self.pointer), - PixelGetBlack(self.pointer) - ) - - return MagickWand.CMYK(cyan, magenta, yellow: yellow, key: key) + public var cmy: MagickWand.CMY { + get { + let (cyan, magenta, yellow) = ( + PixelGetCyan(self.pointer), + PixelGetMagenta(self.pointer), + PixelGetYellow(self.pointer) + ) + + return MagickWand.CMY(cyan, magenta, yellow: yellow) + } + set { + PixelSetCyan(self.pointer, newValue.cyan) + PixelSetMagenta(self.pointer, newValue.magenta) + PixelSetYellow(self.pointer, newValue.yellow) + } + } + + public var black: Double { + get { + return PixelGetBlack(self.pointer) + } + set { + PixelSetBlack(self.pointer, newValue) + } } public var string: String? { @@ -79,18 +107,28 @@ public struct Colors { } public var count: Int { - - return PixelGetColorCount(self.pointer) + get { + return PixelGetColorCount(self.pointer) + } + set { + PixelSetColorCount(self.pointer, newValue) + } } public var info: MagickWand.ColorInfo { - var infoPacket = MagickPixelPacket() - -#if !os(Linux) - PixelGetMagickColor(self.pointer, &infoPacket) -#endif - - return MagickWand.ColorInfo(infoPacket) + get { + var infoPacket = MagickPixelPacket() + + #if !os(Linux) + PixelGetMagickColor(self.pointer, &infoPacket) + #endif + + return MagickWand.ColorInfo(infoPacket) + } + set { + var packet = newValue.info + PixelSetMagickColor(self.pointer, &packet) + } } } @@ -101,6 +139,11 @@ extension PixelWand { } public var index: Quantum { - return PixelGetIndex(self.pointer) + get { + return PixelGetIndex(self.pointer) + } + set { + PixelSetIndex(self.pointer, newValue) + } } } diff --git a/Sources/MagickWand/WandTypes/MagickWand+ColorInfo.swift b/Sources/MagickWand/WandTypes/MagickWand+ColorInfo.swift index f82e7e1..f222339 100644 --- a/Sources/MagickWand/WandTypes/MagickWand+ColorInfo.swift +++ b/Sources/MagickWand/WandTypes/MagickWand+ColorInfo.swift @@ -39,6 +39,27 @@ extension MagickWand { private(set) public var blue: Double private(set) public var opacity: Double private(set) public var index: Double + + internal var info: MagickPixelPacket { + var result = MagickPixelPacket() + + result.colorspace = self.colorspace.type + + result.matte = MagickBooleanType.init(self.isMatte ? 1 : 0) + + result.fuzz = self.fuzz + + result.depth = self.depth + + result.red = MagickRealType(self.red) + result.green = MagickRealType(self.green) + result.blue = MagickRealType(self.blue) + result.opacity = MagickRealType(self.opacity) + + result.index = MagickRealType(self.index) + + return result + } init(_ info: MagickPixelPacket) { self.colorspace = MagickWand.Colorspace(info.colorspace) diff --git a/Sources/MagickWand/WandTypes/MagickWand+Colors.swift b/Sources/MagickWand/WandTypes/MagickWand+Colors.swift index 20c1a9f..c3b4271 100644 --- a/Sources/MagickWand/WandTypes/MagickWand+Colors.swift +++ b/Sources/MagickWand/WandTypes/MagickWand+Colors.swift @@ -60,18 +60,16 @@ extension MagickWand { } } - public struct CMYK { + public struct CMY { public var cyan: Double public var magenta: Double public var yellow: Double - public var key: Double - public init (_ cyan: Double, _ magenta: Double, yellow: Double, key: Double) { + public init (_ cyan: Double, _ magenta: Double, yellow: Double) { self.cyan = cyan self.magenta = magenta self.yellow = yellow - self.key = key } } }