-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
fad3087
commit cf4ee3b
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
Sources/CodeEditTextView/Extensions/NSColor+Greyscale.swift
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,17 @@ | ||
// | ||
// NSColor+Greyscale.swift | ||
// CodeEditTextView | ||
// | ||
// Created by Khan Winter on 2/2/24. | ||
// | ||
|
||
import AppKit | ||
|
||
extension NSColor { | ||
var grayscale: NSColor { | ||
guard let color = self.usingColorSpace(.deviceRGB) else { return self } | ||
// linear relative weights for grayscale: https://en.wikipedia.org/wiki/Grayscale | ||
let gray = 0.299 * color.redComponent + 0.587 * color.greenComponent + 0.114 * color.blueComponent | ||
return NSColor(white: gray, alpha: color.alphaComponent) | ||
} | ||
} |
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