Skip to content

Commit

Permalink
icon generator
Browse files Browse the repository at this point in the history
  • Loading branch information
ObuchiYuki committed Feb 28, 2022
1 parent e39d6a1 commit 5c76f19
Show file tree
Hide file tree
Showing 23 changed files with 865 additions and 130 deletions.
4 changes: 4 additions & 0 deletions CoreUtil/CoreUtil.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
B680A8A027A8DA78007CB707 /* OrderedCollections in Frameworks */ = {isa = PBXBuildFile; productRef = B680A89F27A8DA78007CB707 /* OrderedCollections */; };
B680A8A227A8DA78007CB707 /* DequeModule in Frameworks */ = {isa = PBXBuildFile; productRef = B680A8A127A8DA78007CB707 /* DequeModule */; };
B680A8A427A8DA78007CB707 /* Collections in Frameworks */ = {isa = PBXBuildFile; productRef = B680A8A327A8DA78007CB707 /* Collections */; };
B6A93D2B27CBA2EB003A6D7F /* Zip3Sequence.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6A93D2A27CBA2EB003A6D7F /* Zip3Sequence.swift */; };
B6AC27A327AA6F5C000FD713 /* Reachability+Publisher.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6AC27A127AA6F5B000FD713 /* Reachability+Publisher.swift */; };
B6AC27A427AA6F5C000FD713 /* Reachability.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6AC27A227AA6F5C000FD713 /* Reachability.swift */; };
B6B5727A27AC223A0069DBA7 /* RestorableState.swift in Sources */ = {isa = PBXBuildFile; fileRef = B6B5727927AC223A0069DBA7 /* RestorableState.swift */; };
Expand Down Expand Up @@ -99,6 +100,7 @@
B680A79027A681F8007CB707 /* NSTextField+Combine.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NSTextField+Combine.swift"; sourceTree = "<group>"; };
B680A86427A8C58C007CB707 /* Combine+Peek.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Combine+Peek.swift"; sourceTree = "<group>"; };
B680A89B27A8DA16007CB707 /* Action.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Action.swift; sourceTree = "<group>"; };
B6A93D2A27CBA2EB003A6D7F /* Zip3Sequence.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Zip3Sequence.swift; sourceTree = "<group>"; };
B6AC27A127AA6F5B000FD713 /* Reachability+Publisher.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Reachability+Publisher.swift"; sourceTree = "<group>"; };
B6AC27A227AA6F5C000FD713 /* Reachability.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reachability.swift; sourceTree = "<group>"; };
B6B5727927AC223A0069DBA7 /* RestorableState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestorableState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -218,6 +220,7 @@
B64B1F6D27A4FC9100AC2601 /* Class */ = {
isa = PBXGroup;
children = (
B6A93D2A27CBA2EB003A6D7F /* Zip3Sequence.swift */,
B6AC27A227AA6F5C000FD713 /* Reachability.swift */,
B6AC27A127AA6F5B000FD713 /* Reachability+Publisher.swift */,
B64B201027A50E5200AC2601 /* NSColorView.swift */,
Expand Down Expand Up @@ -382,6 +385,7 @@
B64B1F1827A4F80800AC2601 /* Ex+CGPoint.swift in Sources */,
B680A86527A8C58C007CB707 /* Combine+Peek.swift in Sources */,
B64B1ED027A4F71200AC2601 /* ViewPlaceholder.swift in Sources */,
B6A93D2B27CBA2EB003A6D7F /* Zip3Sequence.swift in Sources */,
B64B1F3127A4F83500AC2601 /* Ex+Image.swift in Sources */,
B64B1ED627A4F72D00AC2601 /* Query.swift in Sources */,
B64B1F2B27A4F83500AC2601 /* Ex+UI.swift in Sources */,
Expand Down
69 changes: 69 additions & 0 deletions CoreUtil/CoreUtil/Class/Zip3Sequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
//
// Zip3Sequence.swift
// CoreUtil
//
// Created by yuki on 2022/01/22.
// Copyright © 2022 yuki. All rights reserved.
//

public func zip<A: Sequence, B: Sequence, C: Sequence>(_ a: A, _ b: B, _ c: C) -> Zip3Sequence<A, B, C> {
Zip3Sequence(a, b, c)
}
public func zip<A: Sequence, B: Sequence, C: Sequence, D: Sequence>(_ a: A, _ b: B, _ c: C, _ d: D) -> Zip4Sequence<A, B, C, D> {
Zip4Sequence(a, b, c, d)
}

public struct Zip3Sequence<A: Sequence, B: Sequence, C: Sequence>: Sequence {
public typealias Element = (A.Element, B.Element, C.Element)

public let a: A
public let b: B
public let c: C

public struct Iterator: IteratorProtocol {
var a: A.Iterator
var b: B.Iterator
var c: C.Iterator

mutating public func next() -> Element? {
if let a = a.next(), let b = b.next(), let c = c.next() { return (a, b, c) }; return nil
}
}

public func makeIterator() -> Iterator { Iterator(a: a.makeIterator(), b: b.makeIterator(), c: c.makeIterator()) }

init(_ a: A, _ b: B, _ c: C) {
self.a = a
self.b = b
self.c = c
}
}

public struct Zip4Sequence<A: Sequence, B: Sequence, C: Sequence, D: Sequence>: Sequence {
public typealias Element = (A.Element, B.Element, C.Element, D.Element)

public let a: A
public let b: B
public let c: C
public let d: D

public struct Iterator: IteratorProtocol {
var a: A.Iterator
var b: B.Iterator
var c: C.Iterator
var d: D.Iterator

mutating public func next() -> Element? {
if let a = a.next(), let b = b.next(), let c = c.next(), let d = d.next() { return (a, b, c, d) }; return nil
}
}

public func makeIterator() -> Iterator { Iterator(a: a.makeIterator(), b: b.makeIterator(), c: c.makeIterator(), d: d.makeIterator()) }

init(_ a: A, _ b: B, _ c: C, _ d: D) {
self.a = a
self.b = b
self.c = c
self.d = d
}
}
14 changes: 14 additions & 0 deletions CoreUtil/CoreUtil/Extensions/UI/Ex+Image.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@ extension NSImage {
return cgImage(forProposedRect: &imageRect, context: nil, hints: nil)
}
}


extension CGImage {
public func convertToGrayscale() -> CGImage {
let imageRect = CGRect(size: CGSize(width: width, height: height))
let context = CGContext(
data: nil, width: self.width, height: self.height,
bitsPerComponent: 8, bytesPerRow: 0,
space: CGColorSpaceCreateDeviceGray(), bitmapInfo: CGImageAlphaInfo.none.rawValue
)!
context.draw(self, in: imageRect)
return context.makeImage()!
}
}
Loading

0 comments on commit 5c76f19

Please sign in to comment.