Skip to content

Instantly share code, notes, and snippets.

View randomsequence's full-sized avatar

Johnnie Walker randomsequence

View GitHub Profile
@randomsequence
randomsequence / MPS.swift
Last active June 12, 2020 11:38
Use BlitCommandEncoder to sync destination
import MetalPerformanceShaders
struct Pixel {
var red: UInt8
var green: UInt8
var blue: UInt8
var alpha: UInt8
}
let count = 64
/*
The MIT License (MIT)
Copyright (c) 2014-2015 Russel Lindsay
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
#import <Foundation/Foundation.h>
#include <pthread.h>
@interface Getty : NSObject {
@protected
id _object;
}
@property (nonatomic, strong, readonly) id object;
@end
@randomsequence
randomsequence / CompareImages.swift
Last active November 27, 2023 21:23 — forked from ralfebert/CompareImages.swift
A couple of swift functions for comparing two CGImage using CIImage in OS X
//
// Thanks Kevin!
// https://gist.github.com/SheffieldKevin/566dc048dd6f36716bcd
//
import CoreGraphics
import CoreImage
extension CGImage {

Keybase proof

I hereby claim:

  • I am randomsequence on github.
  • I am mrwalker (https://keybase.io/mrwalker) on keybase.
  • I have a public key ASD3MgjS87gY-zIZHwDSc4NFHchTH8etjXtHFArSk8gGVQo

To claim this, I am signing this object:

@randomsequence
randomsequence / pixels.swift
Created November 22, 2017 07:26
Poking at Pixels in Swift 4
import Cocoa
struct Pixel {
var alpha: UInt8
var red: UInt8
var green: UInt8
var blue: UInt8
init(red: UInt8, green: UInt8, blue: UInt8, alpha: UInt8) {
self.alpha = alpha
@randomsequence
randomsequence / quartz-drawing.swift
Created March 30, 2016 19:47
Drawing to NSImage using Quartz in Swift
import Cocoa
// helper function which takes a size and a drawing function.
// returns an image
public func drawItems(bounds: CGRect, block: (bounds: CGRect, context: CGContextRef) -> () ) -> NSImage? {
var outputImage: NSImage? = nil
let insetSize = CGSizeMake(-20, -20)
let insetBounds = CGRectInset(bounds, insetSize.width, insetSize.height)
let colorSpace = CGColorSpaceCreateDeviceRGB()
@randomsequence
randomsequence / cocoa-drawing.swift
Created July 14, 2015 15:25
Drawing images with CGContext and NSGraphicsContext in Swift
//: Playground - noun: a place where people can play
import Cocoa
let bounds = CGRectMake(0, 0, 100, 100);
func DrawImageInCGContext(#size: CGSize, #drawFunc: (context: CGContextRef) -> ()) -> NSImage {
let colorSpace = CGColorSpaceCreateDeviceRGB()
let bitmapInfo = CGBitmapInfo(CGImageAlphaInfo.PremultipliedLast.rawValue)
let context = CGBitmapContextCreate(
@randomsequence
randomsequence / CIContext+IntermediateImage.m
Created May 12, 2014 12:20
CoreImage - Render a CIImage to an Intermediate CVPixelBuffer Backed Image
@implementation CIContext (IntermediateImage)
- (CIImage *)rsq_renderToIntermediateImage:(CIImage *)image {
CIImage *intermediateImage = nil;
CGSize size = image.extent.size;
CVPixelBufferRef pixelBuffer = NULL;
CVReturn status = CVPixelBufferCreate(kCFAllocatorDefault,
size.width,
size.height,
kCVPixelFormatType_32ARGB,
@randomsequence
randomsequence / UIImage+Scramble.m
Created April 24, 2014 13:57
UIImage - Mirror every other row & every other column. This produces an image with the same histogram as the source.
//
// UIImage+Scramble.m
//
// Created by Johnnie Walker on 24/04/2014.
//
#import "UIImage+Scramble.h"
@import Accelerate;