Skip to content

Commit

Permalink
(#3) started refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Sergey Minakov committed Nov 22, 2016
1 parent 28b4ba6 commit 0705dbe
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 17 deletions.
17 changes: 8 additions & 9 deletions Sources/MagickWand/MagickWand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

public struct MagickWand {

public typealias Size = (width: Int, height: Int)
public typealias Resolution = (width: Double, height: Double)

public typealias HSL = (hue: Double, saturation: Double, lightness: Double)
Expand All @@ -44,11 +43,7 @@ public struct MagickWand {
}

public static var isInstantiated: Bool {
#if os(Linux)
return IsMagickInstantiated().bool
#else
return IsMagickWandInstantiated().bool
#endif
return IsMagickWandInstantiated().bool
}

public static var version: String {
Expand All @@ -58,16 +53,20 @@ public struct MagickWand {

return String(cString: pointer)
}
}

internal static func getString(from wandPointer: OpaquePointer, using method: (OpaquePointer!) -> (UnsafeMutablePointer<Int8>!)) -> String? {
extension MagickWand {

internal static func getString(from wandPointer: OpaquePointer?,
using method: (OpaquePointer!) -> (UnsafeMutablePointer<Int8>!)) -> String? {
guard let pointer = method(wandPointer) else {
return nil
}

defer {
MagickRelinquishMemory(pointer)
}

return String(cString: pointer)
}
}
6 changes: 3 additions & 3 deletions Sources/MagickWand/Wand/ImageWand/ImageWand+Size.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ extension ImageWand {
Int(MagickGetImageHeight(self.pointer))
)

return (width, height)
return MagickWand.Size(width: width, height: height)
}

public var resolution: MagickWand.Resolution {
Expand All @@ -50,11 +50,11 @@ extension ImageWand {

public func size(for dimension: Int) -> MagickWand.Size {
let size = self.size
var result = (width: 0, height: 0)
var result = MagickWand.Size(width: 0, height: 0)

if size.width == 0
|| size.height == 0 {
return (0, 0)
return .zero
}

let ratio = Double(size.height) / Double(size.width)
Expand Down
4 changes: 2 additions & 2 deletions Sources/MagickWand/Wand/PixelWand/PixelWand+Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public struct Colors {
self.pointer = pointer
}

public var rgb: MagickWand.RGB {
public var rgb: MagickWand.RGBA {
let red = PixelGetRed(self.pointer)
let green = PixelGetGreen(self.pointer)
let blue = PixelGetBlue(self.pointer)
let alpha = PixelGetAlpha(self.pointer)

return MagickWand.RGB(red, green, blue, alpha)
return MagickWand.RGBA(red, green, blue, alpha)
}

public var hsl: MagickWand.HSL {
Expand Down
4 changes: 2 additions & 2 deletions Sources/MagickWand/WandTypes/MagickWand+Colors.swift
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,8 @@ transparent transparent rgba( 0, 0, 0, 0.0) #00000000
return ""
}

var rgb: MagickWand.RGB {
return MagickWand.RGB(0, 0, 0)
var rgb: MagickWand.RGBA {
return MagickWand.RGBA(0, 0, 0)
}

var hex: String {
Expand Down
2 changes: 1 addition & 1 deletion Sources/MagickWand/WandTypes/MagickWand+RGB.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extension MagickWand {

public struct RGB {
public struct RGBA {

private(set) var red: Double
private(set) var green: Double
Expand Down
45 changes: 45 additions & 0 deletions Sources/MagickWand/WandTypes/MagickWand+Size.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// MagickWand+Orientation.swift
//
// Copyright (c) 2016 Sergey Minakov
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

#if os(Linux)
import CMagickWandLinux
#else
import CMagickWandOSX
#endif

extension MagickWand {

public struct Size {

static let zero = Size()

var width: Int = 0
var height: Int = 0

init() { }

init(width: Int, height: Int) {
self.width = width
self.height = height
}
}
}
Binary file added Tests/MagickWandTests/rect.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0705dbe

Please sign in to comment.