Skip to content

Instantly share code, notes, and snippets.

View AllanChen's full-sized avatar

AllanChan AllanChen

View GitHub Profile
#import "AppDelegate.h"
#include <stdio.h>
@interface AppDelegate ()
@end
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// [self namolData];
// [self test];
// [self test2];
//
// ViewController.m
// compare
//
// Created by Allan on 27/7/2019.
// Copyright © 2019 Allan. All rights reserved.
//
#import "ViewController.h"
#include <arm_neon.h>
@AllanChen
AllanChen / Upscale_yuv.c
Created July 12, 2018 06:42 — forked from abhishekmurthy/Upscale_yuv.c
Upscaling a YUV image using Bilinear or Nearest scale algorithms
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/stat.h>
typedef unsigned char uint8_t;
/**
* @param src input nv12 raw data array
/****************************************************************************
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2013-2017 Chukong Technologies Inc.
http://www.cocos2d-x.org
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
@AllanChen
AllanChen / ViewController.m
Created June 26, 2018 02:41
write data to documents folder
+ (void)writeDataToFile:(NSString *)fileName wirteData:(NSData*)data{
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:fileName];
BOOL fileExists = [self fileExists:fileName];
if(fileExists){
NSFileHandle *fileHandle = [NSFileHandle fileHandleForWritingAtPath:filePath];
[fileHandle seekToEndOfFile];
[fileHandle writeData:data];
[fileHandle closeFile];
}
else{
@AllanChen
AllanChen / rgba2yuv.m
Last active May 20, 2024 08:53
UIImage to YUV420f NV12 (iOS)
-(CVPixelBufferRef)imageToYUVPixelBuffer:(UIImage *)image{
// convert to CGImage & dump to bitmapData
CGImageRef imageRef = [image CGImage];
int width = (int)CGImageGetWidth(imageRef);
int height = (int)CGImageGetHeight(imageRef);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
NSUInteger bytesPerPixel = 4;
NSUInteger bytesPerRow = ((bytesPerPixel*width+255)/256)*256;
@AllanChen
AllanChen / OpenGLToCVPixelBuffer.m
Created June 1, 2018 07:12 — forked from caojianhua/OpenGLToCVPixelBuffer.m
Create CVPixelBufferRef from OpenGL
@interface SREAGLContext : NSObject
+ (EAGLContext*)sharedContext;
+ (EAGLContext*)newContext: (EAGLRenderingAPI) api;
@end
@implementation SREAGLContext
@AllanChen
AllanChen / CMSampleBufferRef_to_vImage.m
Created May 30, 2018 11:57 — forked from podkovyrin/CMSampleBufferRef_to_vImage.m
CMSampleBufferRef to vImage and resize
CVImageBufferRef imageBuffer = CMSampleBufferGetImageBuffer(sampleBuffer);
CVPixelBufferLockBaseAddress(imageBuffer,0);
size_t height = CVPixelBufferGetHeight(imageBuffer);
size_t width = CVPixelBufferGetWidth(imageBuffer);
size_t bytesPerRow = CVPixelBufferGetBytesPerRow(imageBuffer);
void *sourceData = CVPixelBufferGetBaseAddress(imageBuffer);
// Set a bunch of variables we need. The "radius" for the blur kernel needs to be positive and odd. The permute map maps the BGRA channels of the buffer to the ARGB that vImage needs.
@AllanChen
AllanChen / gist:236879333be296ac75aa3dea3c07cba8
Created June 8, 2016 02:02 — forked from Bouke/gist:11261620
Multiple Python installations on OS X

Previous versions used homebrew to install the various versions. As suggested in the comments, it's better to use pyenv instead. If you are looking for the previous version of this document, see the revision history.

$ brew update
$ brew install pyenv
$ pyenv install 3.5.0
$ pyenv install 3.4.3
$ pyenv install 3.3.6
$ pyenv install 3.2.6
$ pyenv install 2.7.10

$ pyenv install 2.6.9