Skip to content

Commit 78a55cb

Browse files
authored
Merge pull request #1 from TrueMax/testbranch
Testbranch to main
2 parents 2c587c1 + 666253b commit 78a55cb

File tree

10 files changed

+100
-25
lines changed

10 files changed

+100
-25
lines changed

Package.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ let package = Package(
2020
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2121
.target(
2222
name: "iOSIntPackage",
23-
dependencies: []),
24-
.testTarget(
25-
name: "iOSIntPackageTests",
26-
dependencies: ["iOSIntPackage"])
23+
dependencies: [])
2724
]
2825
)

Sources/iOSIntPackage/ImageProcessor.swift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public struct ImageProcessor {
1313

1414
public init() {}
1515

16+
// применение фильтра к изображению в главном потоке, не требует явного вызова DispatchQueue.main при работе с UI
1617
public func processImage(
1718
sourceImage: UIImage,
1819
filter: ColorFilter,
@@ -24,6 +25,18 @@ public struct ImageProcessor {
2425
handler: completion)
2526
}
2627

28+
// применение фильтра к изображению в параллельном потоке, требует явного вызова DispatchQueue.main при работе с UI
29+
public func processImageAsync(
30+
sourceImage: UIImage,
31+
filter: ColorFilter,
32+
completion: @escaping (CGImage?) -> Void
33+
) {
34+
applyFilterAsync(
35+
filter: filter,
36+
image: sourceImage,
37+
handler: completion)
38+
}
39+
2740
private func applyFilter(
2841
filter: ColorFilter,
2942
image: UIImage,
@@ -46,4 +59,29 @@ public struct ImageProcessor {
4659
) else { fatalError("Error creating output image") }
4760
handler(UIImage(cgImage: outputImage))
4861
}
62+
63+
private func applyFilterAsync(
64+
filter: ColorFilter,
65+
image: UIImage,
66+
handler: @escaping (CGImage?) -> Void
67+
) {
68+
DispatchQueue.global(qos: .userInitiated).async {
69+
let context = CIContext()
70+
guard let source = CIImage(image: image) else { fatalError("Error creating source image") }
71+
var params = filter.parameters
72+
params[ColorFilter.imageKey] = source
73+
guard let filter = CIFilter(
74+
name: filter.filterName,
75+
parameters: params
76+
) else { fatalError("Error creating filter") }
77+
78+
guard let filteredImage = filter.outputImage else { fatalError("Error filtering image") }
79+
80+
guard let outputImage = context.createCGImage(
81+
filteredImage,
82+
from: filteredImage.extent
83+
) else { fatalError("Error creating output image") }
84+
handler(outputImage)
85+
}
86+
}
4987
}

Sources/iOSIntPackage/Images.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Maxim Abakumov on 2021. 01. 04.
6+
//
7+
// Copyright © 2020, Maxim Abakumov. MIT License.
8+
//
9+
10+
import UIKit
11+
12+
public struct Images {
13+
14+
public static var checkmark: UIImage {
15+
return getPdfImage(by: "checkmark")
16+
}
17+
18+
public static var sunset: UIImage {
19+
return getPdfImage(by: "sunset")
20+
}
21+
22+
public static var mountain: UIImage {
23+
return getPdfImage(by: "mountain")
24+
}
25+
26+
private static func getPdfImage(by name: String) -> UIImage {
27+
28+
guard let image = UIImage(
29+
named: name,
30+
in: Bundle.module,
31+
compatibleWith: nil
32+
) else {
33+
fatalError("Error retrieving image from path")
34+
}
35+
return image
36+
}
37+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "matterhorn_sm.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Binary file not shown.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"images" : [
3+
{
4+
"filename" : "sunset.pdf",
5+
"idiom" : "universal"
6+
}
7+
],
8+
"info" : {
9+
"author" : "xcode",
10+
"version" : 1
11+
}
12+
}
Binary file not shown.

Tests/LinuxMain.swift

Lines changed: 0 additions & 7 deletions
This file was deleted.

Tests/iOSIntPackageTests/XCTestManifests.swift

Lines changed: 0 additions & 9 deletions
This file was deleted.

Tests/iOSIntPackageTests/iOSIntPackageTests.swift

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)