Skip to content

Commit

Permalink
(#3) [Refactor] Added setters to PixelWand.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Minakov committed Nov 22, 2016
1 parent abfd683 commit 19aad33
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 36 deletions.
107 changes: 75 additions & 32 deletions Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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? {
Expand All @@ -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)
}
}
}

Expand All @@ -101,6 +139,11 @@ extension PixelWand {
}

public var index: Quantum {
return PixelGetIndex(self.pointer)
get {
return PixelGetIndex(self.pointer)
}
set {
PixelSetIndex(self.pointer, newValue)
}
}
}
21 changes: 21 additions & 0 deletions Sources/MagickWand/WandTypes/MagickWand+ColorInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions Sources/MagickWand/WandTypes/MagickWand+Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

0 comments on commit 19aad33

Please sign in to comment.