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
@implementation UIImage (Grayscale) | |
UIImage *grayscaleImageFromCIImage(CIImage *image, CGFloat scale) { | |
CIImage *blackAndWhite = [CIFilter filterWithName:@"CIColorControls" keysAndValues:kCIInputImageKey, image, @"inputBrightness", @0.0, @"inputContrast", @1.1, @"inputSaturation", @0.0, nil].outputImage; | |
CIImage *output = [CIFilter filterWithName:@"CIExposureAdjust" keysAndValues:kCIInputImageKey, blackAndWhite, @"inputEV", @0.7, nil].outputImage; | |
CGImageRef ref = [[CIContext contextWithOptions:nil] createCGImage:output fromRect:output.extent]; | |
UIImage *result = [UIImage imageWithCGImage:ref scale:scale orientation:UIImageOrientationUp]; | |
CGImageRelease(ref); | |
return result; | |
} |
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
@interface UIImage (ResizeableFallback) | |
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets; | |
@end | |
@implementation | |
- (UIImage *)resizableImageWithInsets:(UIEdgeInsets *)insets | |
{ | |
if ([UIImage respondsToSelector:@selector(resizableImageWithCapInsets:)]) | |
return [self resizableImageWithCapInsets: insets]; | |
return [self stretchableImageWithLeftCapWidth:insets.left topCapWidth:insets.top]; | |
} |
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
// Copyright 2013 (c) Anton Bukov - https://github.com/k06a | |
// Inspired by http://graphics.stanford.edu/~seander/bithacks.html | |
#define P0(a) (a) | |
#define P1(a) (((P0(a) & 0x55555555) << 1) | ((P0(a) & 0xAAAAAAAA) >> 1)) | |
#define P2(a) (((P1(a) & 0x33333333) << 2) | ((P1(a) & 0xCCCCCCCC) >> 2)) | |
#define P3(a) (((P2(a) & 0x0F0F0F0F) << 4) | ((P2(a) & 0xF0F0F0F0) >> 4)) | |
#define P4(a) (((P3(a) & 0x00FF00FF) << 8) | ((P3(a) & 0xFF00FF00) >> 8)) | |
#define P5(a) (((P4(a) & 0x0000FFFF) << 16) | ((P4(a) & 0xFFFF0000) >> 16)) |
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
template<typename TI, typename TV> | |
int BinSearch(TI begin, TI end, TV value) | |
{ | |
int minIndex = 0; | |
int maxIndex = end - begin - 1; | |
while (minIndex <= maxIndex) | |
{ | |
int midIndex = (minIndex + maxIndex) / 2; | |
TI comparison = begin + midIndex; |
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
// | |
// Here is some illustration of central kick: | |
// https://commons.wikimedia.org/wiki/File:Elastischer_stoß3.gif | |
// | |
// V -V | |
// [m = 2]---> <---[m = 1] | |
// [m = 2] [m = 1] | |
// [m = 2][m = 1] | |
// [m = 2] [m = 1] | |
// <-[m = 2] [m = 1]-----> |
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
// | |
// Usage: `[item.self anyMethod]` is valid for `item` equals to `[NSNull null]` | |
// | |
@interface NSNull (SelfOrNil) | |
@end |
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
#import <Foundation/Foundation.h> | |
namespace cv { | |
class Mat; | |
} | |
@interface NSValue (CVMat) | |
+ (instancetype)valueWithCVMat:(cv::Mat)mat; | |
@property (readonly) cv::Mat CVMatValue; |
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
# | |
# Reorder property attributes in one possible way | |
# | |
# @property (nullable, readonly, assign, nonatomic, getter=isReady) BOOL ready; | |
# | |
# 1. Move readonly to the BEGIN of attribute list | |
# 2. Move nullable to the BEGIN of attribute list | |
# 3. Move null_resettable to the BEGIN of attribute list | |
# 4. Move nonatomic to the END of attribute list | |
# 5. Move getter to the END of attribute list |
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
#import <QuartzCore/QuartzCore.h> | |
#import "Bike.h" | |
@implementation Bike { | |
} | |
- (id)initWithFrame:(CGRect)frame { | |
self = [super initWithFrame:frame]; |