Skip to content

Instantly share code, notes, and snippets.

@zapsleep
zapsleep / vImageBlurTest.mm
Last active September 6, 2016 06:12
Creating blur image from given with vImage
- (UIImage *)blurryImage:(UIImage *)image withBlurLevel:(CGFloat)blur {
if (blur < 0.f || blur > 1.f) {
blur = 0.5f;
}
int boxSize = (int)(blur * 100);
boxSize = boxSize - (boxSize % 2) + 1;
CGImageRef img = image.CGImage;
vImage_Buffer inBuffer, outBuffer;
- (UIImage *)blurryGPUImage:(UIImage *)image
withBlurLevel:(NSInteger)blur {
GPUImageFastBlurFilter *blurFilter =
[[GPUImageFastBlurFilter alloc] init];
blurFilter.blurSize = blur;
UIImage *result = [blurFilter imageByFilteringImage:image];
return result;
}
@zapsleep
zapsleep / BlurCI.mm
Last active December 10, 2015 21:09
- (UIImage *)blurryImage:(UIImage *)image
withBlurLevel:(CGFloat)blur {
CIImage *inputImage = [CIImage imageWithCGImage:image.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"
keysAndValues:kCIInputImageKey, inputImage,
@"inputRadius", @(blur),
nil];
CIImage *outputImage = filter.outputImage;
@zapsleep
zapsleep / DVPlaylistPlayer.m
Last active December 19, 2015 13:59
DVPlaylistPlayer creation, setting and usage.
DVPlaylistPlayer *player = [[DVPlaylistPlayer alloc] init];
[self.view addSubview:player.playerView];
player.delegate = someDelegate;
player.dataSource = someDataSource;
[player playMediaAtIndex:0];
@zapsleep
zapsleep / DeviceMotionTest.m
Last active December 20, 2015 01:49
Source of main view controller in DeviceMotionTest project
#import "DVViewController.h"
#import <CoreMotion/CoreMotion.h>
#define kCMDeviceMotionUpdateFrequency (1.f/30.f)
@interface DVViewController ()
@property (weak, nonatomic) IBOutlet UILabel *accelerationXVal;
@property (weak, nonatomic) IBOutlet UILabel *accelerationYVal;
@property (weak, nonatomic) IBOutlet UILabel *accelerationZVal;
@zapsleep
zapsleep / UpdateMotionData.m
Last active December 20, 2015 01:49
Gist for updateMotionData method
- (void)updateMotionData {
//1
CMAcceleration acceleration = self.motionManager.deviceMotion.userAcceleration;
self.accelerationXVal.text = [NSString stringWithFormat:@"%.3f", acceleration.x];
self.accelerationYVal.text = [NSString stringWithFormat:@"%.3f", acceleration.y];
self.accelerationZVal.text = [NSString stringWithFormat:@"%.3f", acceleration.z];
//
//2
CMAcceleration gravity = self.motionManager.deviceMotion.gravity;
@zapsleep
zapsleep / DVParallaxViewHeader.m
Created July 29, 2013 07:49
Interface of DVParallaxView (w/o gyro)
#import <UIKit/UIKit.h>
@interface DVParallaxView : UIView
@property (nonatomic, strong) UIImage *backgroundImage;
@property (nonatomic, strong) UIView *frontView;
@property (nonatomic) float parallaxDistanceFactor;
@property (nonatomic) float parallaxFrontFactor;
@property (nonatomic) CGPoint contentOffset;
@zapsleep
zapsleep / DVParallaxViewPrivateInterface.m
Created July 29, 2013 07:54
Private interface of DVParallaxView (w/o gyro)
@interface DVParallaxView()
@property (nonatomic, strong) UIImageView *backgroundImageView;
@end
@zapsleep
zapsleep / DVParallaxViewInitWithFrame.m
Created July 29, 2013 08:00
Init method of DVParallaxView class
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.parallaxDistanceFactor = 2.f;
self.parallaxFrontFactor = 20.f;
self.backgroundColor = [UIColor clearColor];
[self addSubview:self.backgroundImageView];
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panHandler:)];
@zapsleep
zapsleep / DVParallaxViewPanHandler.m
Created July 29, 2013 08:09
Gesture Handler for DVParallaxView
#pragma mark - Gesture handler
- (void)panHandler:(UIPanGestureRecognizer *)pan {
CGPoint translation = [pan translationInView:self];
[self setContentOffset:CGPointMake(self.contentOffset.x + translation.x,
self.contentOffset.y - translation.y)];
[pan setTranslation:CGPointZero inView:self];
}