This file contains hidden or 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
let monalisa = NSImage(named: "monalisa.jpg")! | |
let tiffData = monalisa.TIFFRepresentation! | |
let bitmap = NSBitmapImageRep(data: tiffData) | |
let image = CIImage(bitmapImageRep: bitmap!)! |
This file contains hidden or 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
func imageOrientationToTiffOrientation(value: UIImageOrientation) -> Int32 | |
{ | |
switch (value) | |
{ | |
case UIImageOrientation.Up: | |
return 1 | |
case UIImageOrientation.Down: | |
return 3 | |
case UIImageOrientation.Left: | |
return 8 |
This file contains hidden or 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
void drawLine(texture2d<float, access::write> targetTexture, uint2 start, uint2 end); | |
void drawLine(texture2d<float, access::write> targetTexture, uint2 start, uint2 end) | |
{ | |
int x = int(start.x); | |
int y = int(start.y); | |
int dx = abs(x - int(end.x)); | |
int dy = abs(y - int(end.y)); | |
This file contains hidden or 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
extension CIVector | |
{ | |
func normalize() -> CIVector | |
{ | |
var sum: CGFloat = 0 | |
for i in 0 ..< self.count | |
{ | |
sum += self.valueAtIndex(i) | |
} |
This file contains hidden or 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
extension CIVector | |
{ | |
func multiply(value: CGFloat) -> CIVector | |
{ | |
let n = self.count | |
var targetArray = [CGFloat]() | |
for i in 0 ..< n | |
{ | |
targetArray.append(self.valueAtIndex(i) * value) |
This file contains hidden or 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
class UnrolledKuwaharaFilter: CIFilter | |
{ | |
var inputImage: CIImage? | |
var inputRadius: CGFloat = 15 | |
{ | |
didSet | |
{ | |
if Int(inputRadius) != Int(oldValue) | |
{ |
This file contains hidden or 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
extension CGFloat | |
{ | |
func saturate() -> CGFloat | |
{ | |
return self < 0 ? 0 : self > 1 ? 1 : self | |
} | |
func smootherStep() -> CGFloat | |
{ | |
let x = self.saturate() |
This file contains hidden or 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
// Could benefit from some defensive coding :) | |
import Photos | |
let url = info[UIImagePickerControllerReferenceURL] as! NSURL | |
let fetchResult = PHAsset.fetchAssetsWithALAssetURLs([url], options: nil) | |
let asset = fetchResult.firstObject as! PHAsset |
This file contains hidden or 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
func UIImageEqualToImage(image1: UIImage, _ image2: UIImage, ciContext: CIContext? = nil) -> Bool | |
{ | |
guard let | |
ciImage1 = CIImage(image: image1), | |
ciImage2 = CIImage(image: image2) where image1.size == image2.size else | |
{ | |
return false | |
} | |
let ctx = ciContext ?? CIContext() |
This file contains hidden or 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
extension CGRect | |
{ | |
/// Return corners in order of top left, top right, bottom left, bottom right | |
var corners: [CGPoint] | |
{ | |
return [ | |
CGPoint(x: minX, y: minY), | |
CGPoint(x: maxX, y: minY), | |
CGPoint(x: minX, y: maxY), |
NewerOlder