forked from jathu/UIImageColors
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
aa4a713
commit 026fbd6
Showing
6 changed files
with
433 additions
and
2 deletions.
There are no files selected for viewing
105 changes: 105 additions & 0 deletions
105
.swiftpm/xcode/xcshareddata/xcschemes/UIImageColors-Package.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1310" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColors" | ||
BuildableName = "UIImageColors" | ||
BlueprintName = "UIImageColors" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColorsObjc" | ||
BuildableName = "UIImageColorsObjc" | ||
BlueprintName = "UIImageColorsObjc" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "NO" | ||
buildForArchiving = "NO" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColorsTests" | ||
BuildableName = "UIImageColorsTests" | ||
BlueprintName = "UIImageColorsTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColorsTests" | ||
BuildableName = "UIImageColorsTests" | ||
BlueprintName = "UIImageColorsTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColors" | ||
BuildableName = "UIImageColors" | ||
BlueprintName = "UIImageColors" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
52 changes: 52 additions & 0 deletions
52
.swiftpm/xcode/xcshareddata/xcschemes/UIImageColorsTests.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1300" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "UIImageColorsTests" | ||
BuildableName = "UIImageColorsTests" | ||
BlueprintName = "UIImageColorsTests" | ||
ReferencedContainer = "container:"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// | ||
// Helpers.swift | ||
// UIImageColors | ||
// | ||
// Created by Felix Herrmann on 26.10.21. | ||
// | ||
|
||
#if canImport(UIKit) | ||
import UIKit | ||
#elseif canImport(AppKit) | ||
import AppKit | ||
#endif | ||
|
||
|
||
// MARK: - Color + rgb | ||
|
||
#if canImport(UIKit) | ||
|
||
extension UIColor { | ||
|
||
internal var rgb: (Int, Int, Int) { | ||
var red: CGFloat = 0 | ||
var green: CGFloat = 0 | ||
var blue: CGFloat = 0 | ||
getRed(&red, green: &green, blue: &blue, alpha: nil) | ||
return (Int((red * 255).rounded()), Int((green * 255).rounded()), Int((blue * 255).rounded())) | ||
} | ||
} | ||
|
||
#elseif canImport(AppKit) | ||
|
||
extension NSColor { | ||
|
||
internal var rgb: (Int, Int, Int) { | ||
var red: CGFloat = 0 | ||
var green: CGFloat = 0 | ||
var blue: CGFloat = 0 | ||
getRed(&red, green: &green, blue: &blue, alpha: nil) | ||
return (Int((red * 255).rounded()), Int((green * 255).rounded()), Int((blue * 255).rounded())) | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// UIImageColorsObjcTests.swift | ||
// UIImageColors | ||
// | ||
// Created by Felix Herrmann on 24.10.21. | ||
// | ||
|
||
import XCTest | ||
@testable import UIImageColorsObjc | ||
#if canImport(UIKit) | ||
import UIKit | ||
#elseif canImport(AppKit) | ||
import AppKit | ||
#endif | ||
|
||
final class UIImageColorsObjcTests: XCTestCase { | ||
|
||
private var examplePath: String { | ||
var url = URL(fileURLWithPath: #filePath) | ||
url.deleteLastPathComponent() | ||
url.deleteLastPathComponent() | ||
url.deleteLastPathComponent() | ||
url.appendPathComponent("Example") | ||
url.appendPathComponent("Shared") | ||
url.appendPathComponent("Assets.xcassets") | ||
url.appendPathComponent("Calvin Klein - Kaws.imageset/Calvin Klein - Kaws.jpg") | ||
return url.path | ||
} | ||
|
||
#if canImport(UIKit) | ||
var image: UIImage! | ||
#elseif canImport(AppKit) | ||
var image: NSImage! | ||
#endif | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
#if canImport(UIKit) | ||
image = UIImage(contentsOfFile: examplePath) | ||
#elseif canImport(AppKit) | ||
image = NSImage(contentsOfFile: examplePath) | ||
#endif | ||
|
||
if image == nil { | ||
fatalError("Test-Image could not be loaded") | ||
} | ||
} | ||
|
||
func testSynchronousResults() throws { | ||
let colors = try XCTUnwrap(image.getColorsObjc(quality: .full)) | ||
let primary = try XCTUnwrap(colors.primary) | ||
let secondary = try XCTUnwrap(colors.secondary) | ||
let detail = try XCTUnwrap(colors.detail) | ||
|
||
XCTAssertTrue(colors.background.rgb == (231, 231, 231)) | ||
XCTAssertTrue(primary.rgb == (0, 0, 0)) | ||
XCTAssertTrue(secondary.rgb == (255, 84, 126)) | ||
XCTAssertTrue(detail.rgb == (115, 110, 106) || detail.rgb == (127, 120, 114)) // detail value is not consistent | ||
} | ||
|
||
func testAsynchronousResults() throws { | ||
let expectation = XCTestExpectation(description: "Test asynchronous Objective-C results") | ||
|
||
image.getColorsObjc(quality: .full) { colors in | ||
|
||
do { | ||
let colors = try XCTUnwrap(colors) | ||
let primary = try XCTUnwrap(colors.primary) | ||
let secondary = try XCTUnwrap(colors.secondary) | ||
let detail = try XCTUnwrap(colors.detail) | ||
|
||
XCTAssertTrue(colors.background.rgb == (231, 231, 231)) | ||
XCTAssertTrue(primary.rgb == (0, 0, 0)) | ||
XCTAssertTrue(secondary.rgb == (255, 84, 126)) | ||
XCTAssertTrue(detail.rgb == (115, 110, 106) || detail.rgb == (127, 120, 114)) // detail value is not consistent | ||
} catch { | ||
XCTFail(error.localizedDescription) | ||
} | ||
|
||
expectation.fulfill() | ||
} | ||
|
||
wait(for: [expectation], timeout: 10) | ||
} | ||
} |
Oops, something went wrong.