Skip to content

Instantly share code, notes, and snippets.

View hirohitokato's full-sized avatar

Hirohito Kato hirohitokato

View GitHub Profile
@hirohitokato
hirohitokato / HKLCGImageUtils.swift
Created December 26, 2014 02:57
Create a thumbnail from NSData with required size. It doesn't consume much memory.
//
// HKLCGImageUtils.swift
//
// Created by Hirohito Kato on 2014/12/26.
//
// @see https://developer.apple.com/library/ios/documentation/GraphicsImaging/Conceptual/ImageIOGuide/imageio_source/ikpg_source.html#//apple_ref/doc/uid/TP40005462-CH218-DontLinkElementID_6
import Foundation
import ImageIO
@hirohitokato
hirohitokato / HKLCMTimeUtils.swift
Last active December 1, 2023 14:05
Convenience Methods/Variables/Operators for CMTime
//
// HKLCMTimeUtils.swift
//
// Created by Hirohito Kato on 2015/01/07.
// Copyright © 2020 Kato Hirohito. Licensed under Unlicense(https://unlicense.org). Feel free to use it!
import CoreMedia
// MARK: Initialization
public extension CMTime {
@hirohitokato
hirohitokato / gist:b5557a5771c616814b00
Last active August 29, 2015 14:06
AVSampleBufferDisplayLayer callbacks a block too much...
@interface TestView : UIView
- (void)startPreviewing;
- (void)stopPreviewing;
@property (nonatomic,assign)CMSampleBufferRef sampleBuffer;
@end
////////////////////////////////////////////
#import <AVFoundation/AVFoundation.h>
#import <CoreMedia/CoreMedia.h>
@hirohitokato
hirohitokato / gist:6235b668829313d3478c
Last active November 16, 2018 04:16
How to mute a photo shutter sound.
/*
Mute a shutter sound.
In detail, see http://stackoverflow.com/questions/4401232/avfoundation-how-to-turn-off-the-shutter-sound-when-capturestillimageasynchrono
*/
- (void)becomeSilentModeForCaptureOutput:(AVCaptureStillImageOutput *)imageOutput
{
if (!self.invertedSound) {
NSString *path = [[NSBundle mainBundle] pathForResource:@"photoShutter_inverted"
ofType:@"wav"];
@hirohitokato
hirohitokato / ViewController.m
Created December 17, 2013 05:52
Video capturing with the highest fps.
@import AVFoundation;
#import "ViewController.h"
@interface ViewController ()
@property (nonatomic)AVCaptureSession *session;
@end
@implementation ViewController
- (void)viewDidLoad
@hirohitokato
hirohitokato / A C-Function for dump a CVPixelBuffer
Created September 27, 2013 06:28
I code it in order to understand CVPixelBufferRef defined in CoreVideo.framework. It requires #import <CoreVideo/CoreVideo.h>.
void DumpCVPixelBufferInfo(CVPixelBufferRef buff) {
CVPixelBufferRetain(buff);
CVPixelBufferLockBaseAddress(buff, 0);
union typeUnion {
char c[sizeof(FourCharCode)];
FourCharCode fc;
} type;
type.fc = CVPixelBufferGetPixelFormatType(buff);
size_t w, h, bpr, size;
@hirohitokato
hirohitokato / gist:5966016
Last active December 19, 2015 13:59
error: use of undeclared identifier 'proc' ... why?? -> solved. Required to specify the rvalue of '->*'
// ref: http://okwave.jp/qa/q3884248.html
#include <iostream>
#include <stdio.h>
#include <functional>
class SuperClass {
public:
virtual ~SuperClass() {}
@hirohitokato
hirohitokato / gist:4194090
Created December 3, 2012 10:26
Torch code for iOS6
@property (nonatomic,strong)AVCaptureSession *captureSession;
@property (nonatomic,strong)AVCaptureDevice *device;
@property (weak, nonatomic) IBOutlet UISlider *torchLevelSlider;
- (void)setupTorch
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *d in devices)
if (d.hasTorch && [d isTorchModeSupported:AVCaptureTorchModeOn]) {
self.device = d;
@hirohitokato
hirohitokato / gist:4115565
Created November 20, 2012 02:36
C11の新機能によるNSNumber用マクロ
#define N(x) _Generic((x), \
int: [NSNumber numberWithInt: x], \
float: [NSNumber numberWithFloat: x], \
double: [NSNumber numberWithDouble: x])
require 'coreaudio'
dev = CoreAudio.default_output_device
buf = dev.output_loop(44000)
line = ARGV[0]
puts line
44000.times do |t|
# buf[i] = 0x3FFF * rand()