Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:HalfdanJ/ViljensTriumfPerformance

Conflicts:
	ViljensTriumf.xcodeproj/project.pbxproj
	ViljensTriumf/Plugins/BlackMagic.h
	ViljensTriumf/Plugins/BlackMagic.mm
	ViljensTriumf/Plugins/DecklinkCallback.mm
  • Loading branch information...
commit be596c84ab1f090c3d81b7b220db9f68240c2665 2 parents 45a8a4e + 34327bf
@HalfdanJ authored
View
66 ViljensTriumf.xcodeproj/project.pbxproj
@@ -19,14 +19,16 @@
84AFDC1E15209A0A00DB5DEF /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84AFDC1C15209A0A00DB5DEF /* MainMenu.xib */; };
84AFDC2D15209B3400DB5DEF /* Project.xcconfig in Resources */ = {isa = PBXBuildFile; fileRef = 84AFDC2C15209B3400DB5DEF /* Project.xcconfig */; };
DD03972C161C4F9000D0D629 /* DeckLinkAPIDispatch.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD039725161C4F9000D0D629 /* DeckLinkAPIDispatch.cpp */; };
- DD039737161C591400D0D629 /* DecklinkCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD039736161C591400D0D629 /* DecklinkCallback.cpp */; };
- DD03973A161C94A100D0D629 /* colorCorrectShader.vert in Sources */ = {isa = PBXBuildFile; fileRef = DD039739161C94A100D0D629 /* colorCorrectShader.vert */; };
- DD03973C161C94B000D0D629 /* colorCorrectShader.frag in Sources */ = {isa = PBXBuildFile; fileRef = DD03973B161C94B000D0D629 /* colorCorrectShader.frag */; };
- DD03973D161C94D500D0D629 /* colorCorrectShader.vert in Resources */ = {isa = PBXBuildFile; fileRef = DD039739161C94A100D0D629 /* colorCorrectShader.vert */; };
- DD03973E161C94D700D0D629 /* colorCorrectShader.frag in Resources */ = {isa = PBXBuildFile; fileRef = DD03973B161C94B000D0D629 /* colorCorrectShader.frag */; };
+ DD039737161C591400D0D629 /* DecklinkCallback.mm in Sources */ = {isa = PBXBuildFile; fileRef = DD039736161C591400D0D629 /* DecklinkCallback.mm */; };
DD03974C161C96EF00D0D629 /* ofxShader.cpp in Sources */ = {isa = PBXBuildFile; fileRef = DD03974A161C96EF00D0D629 /* ofxShader.cpp */; };
- DD2B4CB0161CE153003FC9EF /* GLUT.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD2B4CAF161CE153003FC9EF /* GLUT.framework */; };
- DDDCF64A161EB5AC00E8E368 /* BlackMagicController.mm in Sources */ = {isa = PBXBuildFile; fileRef = DDDCF649161EB5AC00E8E368 /* BlackMagicController.mm */; };
+ DD4CC1E8161DEA13000E459D /* bwShader.frag in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E2161DEA13000E459D /* bwShader.frag */; };
+ DD4CC1E9161DEA13000E459D /* bwShader.vert in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E3161DEA13000E459D /* bwShader.vert */; };
+ DD4CC1EA161DEA13000E459D /* colorCorrectShader.frag in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E4161DEA13000E459D /* colorCorrectShader.frag */; };
+ DD4CC1EB161DEA13000E459D /* colorCorrectShader.vert in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E5161DEA13000E459D /* colorCorrectShader.vert */; };
+ DD4CC1EC161DEA13000E459D /* deinterlace.frag in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E6161DEA13000E459D /* deinterlace.frag */; };
+ DD4CC1ED161DEA13000E459D /* deinterlace.vert in Sources */ = {isa = PBXBuildFile; fileRef = DD4CC1E7161DEA13000E459D /* deinterlace.vert */; };
+ DD4CC1EF161DF194000E459D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD4CC1EE161DF194000E459D /* QuartzCore.framework */; };
+ DD4CC1F1161DF6D3000E459D /* deinterlaceFilter.cikernel in Resources */ = {isa = PBXBuildFile; fileRef = DD4CC1F0161DF6D3000E459D /* deinterlaceFilter.cikernel */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -64,14 +66,19 @@
DD03971A161C4F9000D0D629 /* DeckLinkAPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DeckLinkAPI.h; sourceTree = "<group>"; };
DD039725161C4F9000D0D629 /* DeckLinkAPIDispatch.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DeckLinkAPIDispatch.cpp; sourceTree = "<group>"; };
DD039735161C591400D0D629 /* DecklinkCallback.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DecklinkCallback.h; sourceTree = "<group>"; };
- DD039736161C591400D0D629 /* DecklinkCallback.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DecklinkCallback.cpp; sourceTree = "<group>"; };
- DD039739161C94A100D0D629 /* colorCorrectShader.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = colorCorrectShader.vert; sourceTree = "<group>"; };
- DD03973B161C94B000D0D629 /* colorCorrectShader.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; path = colorCorrectShader.frag; sourceTree = "<group>"; };
+ DD039736161C591400D0D629 /* DecklinkCallback.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DecklinkCallback.mm; sourceTree = "<group>"; };
DD03974A161C96EF00D0D629 /* ofxShader.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ofxShader.cpp; sourceTree = "<group>"; };
DD03974B161C96EF00D0D629 /* ofxShader.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ofxShader.h; sourceTree = "<group>"; };
- DD2B4CAF161CE153003FC9EF /* GLUT.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = GLUT.framework; path = ../../../../../System/Library/Frameworks/GLUT.framework; sourceTree = "<group>"; };
- DDDCF648161EB5AC00E8E368 /* BlackMagicController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BlackMagicController.h; sourceTree = "<group>"; };
- DDDCF649161EB5AC00E8E368 /* BlackMagicController.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = BlackMagicController.mm; sourceTree = "<group>"; };
+ DD4CC1E2161DEA13000E459D /* bwShader.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = bwShader.frag; path = shaders/bwShader.frag; sourceTree = "<group>"; };
+ DD4CC1E3161DEA13000E459D /* bwShader.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = bwShader.vert; path = shaders/bwShader.vert; sourceTree = "<group>"; };
+ DD4CC1E4161DEA13000E459D /* colorCorrectShader.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = colorCorrectShader.frag; path = shaders/colorCorrectShader.frag; sourceTree = "<group>"; };
+ DD4CC1E5161DEA13000E459D /* colorCorrectShader.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = colorCorrectShader.vert; path = shaders/colorCorrectShader.vert; sourceTree = "<group>"; };
+ DD4CC1E6161DEA13000E459D /* deinterlace.frag */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = deinterlace.frag; path = shaders/deinterlace.frag; sourceTree = "<group>"; };
+ DD4CC1E7161DEA13000E459D /* deinterlace.vert */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.glsl; name = deinterlace.vert; path = shaders/deinterlace.vert; sourceTree = "<group>"; };
+ DD4CC1EE161DF194000E459D /* QuartzCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = QuartzCore.framework; path = System/Library/Frameworks/QuartzCore.framework; sourceTree = SDKROOT; };
+ DD4CC1F0161DF6D3000E459D /* deinterlaceFilter.cikernel */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = deinterlaceFilter.cikernel; sourceTree = "<group>"; };
+ DDDCF659161EB93500E8E368 /* BlackMagicController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BlackMagicController.h; sourceTree = "<group>"; };
+ DDDCF65A161EB93500E8E368 /* BlackMagicController.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.objcpp; path = BlackMagicController.mm; sourceTree = "<group>"; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
@@ -79,10 +86,10 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
+ DD4CC1EF161DF194000E459D /* QuartzCore.framework in Frameworks */,
845FB20D1520A77400FAB093 /* OpenGL.framework in Frameworks */,
84AFDC0815209A0A00DB5DEF /* Cocoa.framework in Frameworks */,
84A64CB3152492B3004B2050 /* ofxCocoaPlugins.framework in Frameworks */,
- DD2B4CB0161CE153003FC9EF /* GLUT.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -101,6 +108,7 @@
84AFDBF815209A0A00DB5DEF = {
isa = PBXGroup;
children = (
+ DD4CC1EE161DF194000E459D /* QuartzCore.framework */,
84DF2EE315385C49001F3C62 /* Assets */,
84A64CB2152492B3004B2050 /* ofxCocoaPlugins.framework */,
84AFDC2C15209B3400DB5DEF /* Project.xcconfig */,
@@ -123,7 +131,6 @@
84AFDC0615209A0A00DB5DEF /* Frameworks */ = {
isa = PBXGroup;
children = (
- DD2B4CAF161CE153003FC9EF /* GLUT.framework */,
845FB20C1520A77400FAB093 /* OpenGL.framework */,
84AFDC0715209A0A00DB5DEF /* Cocoa.framework */,
84AFDC0915209A0A00DB5DEF /* Other Frameworks */,
@@ -191,13 +198,13 @@
DD039731161C4FE000D0D629 /* BlackMagic */ = {
isa = PBXGroup;
children = (
+ DDDCF659161EB93500E8E368 /* BlackMagicController.h */,
+ DDDCF65A161EB93500E8E368 /* BlackMagicController.mm */,
DD039719161C4F9000D0D629 /* include */,
8429C0DA156A7943000ADD56 /* BlackMagic.h */,
8429C0DB156A7943000ADD56 /* BlackMagic.mm */,
- DDDCF648161EB5AC00E8E368 /* BlackMagicController.h */,
- DDDCF649161EB5AC00E8E368 /* BlackMagicController.mm */,
DD039735161C591400D0D629 /* DecklinkCallback.h */,
- DD039736161C591400D0D629 /* DecklinkCallback.cpp */,
+ DD039736161C591400D0D629 /* DecklinkCallback.mm */,
8429C0DC156A7943000ADD56 /* BlackMagic.xib */,
DD039738161C948C00D0D629 /* shaders */,
);
@@ -207,8 +214,13 @@
DD039738161C948C00D0D629 /* shaders */ = {
isa = PBXGroup;
children = (
- DD039739161C94A100D0D629 /* colorCorrectShader.vert */,
- DD03973B161C94B000D0D629 /* colorCorrectShader.frag */,
+ DD4CC1E2161DEA13000E459D /* bwShader.frag */,
+ DD4CC1E3161DEA13000E459D /* bwShader.vert */,
+ DD4CC1E4161DEA13000E459D /* colorCorrectShader.frag */,
+ DD4CC1E5161DEA13000E459D /* colorCorrectShader.vert */,
+ DD4CC1E6161DEA13000E459D /* deinterlace.frag */,
+ DD4CC1E7161DEA13000E459D /* deinterlace.vert */,
+ DD4CC1F0161DF6D3000E459D /* deinterlaceFilter.cikernel */,
);
name = shaders;
sourceTree = "<group>";
@@ -278,8 +290,7 @@
84AFDC1E15209A0A00DB5DEF /* MainMenu.xib in Resources */,
84AFDC2D15209B3400DB5DEF /* Project.xcconfig in Resources */,
8429C0DE156A7943000ADD56 /* BlackMagic.xib in Resources */,
- DD03973D161C94D500D0D629 /* colorCorrectShader.vert in Resources */,
- DD03973E161C94D700D0D629 /* colorCorrectShader.frag in Resources */,
+ DD4CC1F1161DF6D3000E459D /* deinterlaceFilter.cikernel in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
@@ -294,11 +305,14 @@
84AFDC1B15209A0A00DB5DEF /* AppDelegate.mm in Sources */,
8429C0DD156A7943000ADD56 /* BlackMagic.mm in Sources */,
DD03972C161C4F9000D0D629 /* DeckLinkAPIDispatch.cpp in Sources */,
- DD039737161C591400D0D629 /* DecklinkCallback.cpp in Sources */,
- DD03973A161C94A100D0D629 /* colorCorrectShader.vert in Sources */,
- DD03973C161C94B000D0D629 /* colorCorrectShader.frag in Sources */,
+ DD039737161C591400D0D629 /* DecklinkCallback.mm in Sources */,
DD03974C161C96EF00D0D629 /* ofxShader.cpp in Sources */,
- DDDCF64A161EB5AC00E8E368 /* BlackMagicController.mm in Sources */,
+ DD4CC1E8161DEA13000E459D /* bwShader.frag in Sources */,
+ DD4CC1E9161DEA13000E459D /* bwShader.vert in Sources */,
+ DD4CC1EA161DEA13000E459D /* colorCorrectShader.frag in Sources */,
+ DD4CC1EB161DEA13000E459D /* colorCorrectShader.vert in Sources */,
+ DD4CC1EC161DEA13000E459D /* deinterlace.frag in Sources */,
+ DD4CC1ED161DEA13000E459D /* deinterlace.vert in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
View
22 ViljensTriumf/Plugins/BlackMagic.h
@@ -1,6 +1,7 @@
#pragma once
#import <ofxCocoaPlugins/Plugin.h>
#import "BlackMagicController.h"
+#define MOVIE_LENGTH 7200
class DeckLinkController;
@interface BlackMagic : ofPlugin {
@@ -11,7 +12,26 @@ class DeckLinkController;
int outSelector;
-// ofImage
+ ofImage movieRecording[MOVIE_LENGTH];
+
+ int playbackIndex;
+ int millisAtLastFramePlayback;
+
+/* ofxShader * bwShader;
+ ofxShader * deinterlace;
+ */
+
+ bool recordMovie;
+ int millisAtLastFrameRecord;
+ int recordIndex;
+
+ CIContext * ciContextMain;
+ CIContext * ciContextControl;
+ CIContext * ciContext;
+
+ CIFilter * blurFilter;
+ CIFilter * deinterlaceFilter;
+
}
@end
View
168 ViljensTriumf/Plugins/BlackMagic.mm
@@ -1,17 +1,18 @@
#import "BlackMagic.h"
#import <ofxCocoaPlugins/Keystoner.h>
-#import "ofxShader.h"
#import <OpenGL/CGLRenderers.h>
@implementation BlackMagic
-(void)initPlugin{
- [self addPropF:@"whiteBack"];
- [self addPropF:@"whiteFront"];
- [self addPropF:@"grovKalibrering"];
+ [self addPropF:@"min"];
+ [self addPropF:@"max"];
+ [self addPropF:@"blur"];
+
blackMagicController = [[BlackMagicController alloc] init];
[blackMagicController initDecklink];
+
}
@@ -21,9 +22,39 @@ -(void)initPlugin{
-(void)setup{
-/* [[NSBundle mainBundle] pathForResource:@"colorCorrectShader" ofType:@"vert"];
- ofxShader * shader = new ofxShader();
- shader->setup("test"); */
+
+ glewInit();
+
+/* bwShader = new ofxShader();
+ bwShader->setup("/Users/jonas/Development/ViljensTriumf/ViljensTriumf/Plugins/shaders/bwShader");
+
+ deinterlace = new ofxShader();
+ deinterlace->setup("/Users/jonas/Development/ViljensTriumf/ViljensTriumf/Plugins/shaders/deinterlace");
+*/
+
+ for(int i=0;i<MOVIE_LENGTH;i++){
+
+ }
+
+
+
+ blurFilter = [[CIFilter filterWithName:@"CIGaussianBlur"] retain];
+ [blurFilter setDefaults];
+
+ NSBundle *bundle = [NSBundle bundleForClass: [self class]];// 2
+ NSString *code = [NSString stringWithContentsOfFile: [bundle// 3
+ pathForResource: @"deinterlaceFilter"
+ ofType: @"cikernel"]];
+ NSArray *kernels = [CIKernel kernelsWithString: code];// 4
+ hazeRemovalKernel = [kernels objectAtIndex:0];
+
+ deinterlaceFilter = [CIFilter fil]
+
+
+ CGLContextObj contextGl = CGLContextObj([[[[[globalController viewManager] glViews] objectAtIndex:0] openGLContext] CGLContextObj]);
+ CGLPixelFormatObj pixelformatGl = CGLPixelFormatObj([[[[[globalController viewManager] glViews] objectAtIndex:0] pixelFormat] CGLPixelFormatObj]);
+ ciContextMain = [CIContext contextWithCGLContext:contextGl pixelFormat:pixelformatGl colorSpace:CGColorSpaceCreateDeviceRGB() options:nil];
+
}
//
@@ -33,20 +64,62 @@ -(void)setup{
+
+
+
+
+-(ofImage*) imageForSelector:(int)selector{
+ if(selector == 0){
+ return nil;
+ }
+ if(selector > 0 && selector <= 3){
+ return &currentFrames[selector-1];
+ }
+ if(selector == 4){
+ if(millisAtLastFramePlayback < ofGetElapsedTimeMillis() - 40){
+ millisAtLastFramePlayback = ofGetElapsedTimeMillis();
+ playbackIndex++;
+ if(recordIndex <= playbackIndex){
+ playbackIndex = recordIndex-1;
+ }
+ }
+ return &movieRecording[playbackIndex];
+ }
+}
+
-(void)update:(NSDictionary *)drawingInformation{
for(int i=0;i<3;i++){
DecklinkCallback * callback = [blackMagicController callbacks:i];
if(callback->newFrame){
+ pthread_mutex_lock(&callbacks[i]->mutex);
callback->newFrame = false;
int w = callback->w;
int h = callback->h;
+
- if(currentFrames[i].width != w){
+ /* if(currentFrames[i].width != w){
currentFrames[i].allocate(w, h, OF_IMAGE_COLOR);
}
-
- unsigned char * bytes = callback->bytes;
+*/
+ unsigned char * bytes = callbacks[i]->bytes;
currentFrames[i].setFromPixels(bytes, w, h, OF_IMAGE_COLOR);
+ pthread_mutex_unlock(&callbacks[i]->mutex);
+ }
+ }
+
+ if(recordMovie){
+ if(millisAtLastFrameRecord < ofGetElapsedTimeMillis() - 40){
+ millisAtLastFrameRecord = ofGetElapsedTimeMillis();
+ ofImage * img = [self imageForSelector:outSelector];
+ if(img != nil && outSelector != 4){
+ // movieRecording[recordIndex]
+ movieRecording[recordIndex++] = *img;
+
+ NSLog(@"Rec... %i",int( (float)100.0*recordIndex/MOVIE_LENGTH) );
+ if(recordIndex == MOVIE_LENGTH)
+ recordMovie = false;
+
+ }
}
}
}
@@ -55,21 +128,68 @@ -(void)update:(NSDictionary *)drawingInformation{
//
//----------------
//
+-(CIImage*) createCIImageFromTexture:(GLint)tex size:(NSSize)size{
+ // NSLog(@"Create CI Image");
+ CIImage * image = [CIImage imageWithTexture:tex size:CGSizeMake(size.width, size.height) flipped:NO colorSpace:CGColorSpaceCreateDeviceRGB()];
+ // NSURL * url = [[NSURL alloc] initFileURLWithPath:[NSString stringWithFormat:@"%@%@", [engine assetDir],[self assetString]] isDirectory:NO];
+ // CIImage * image = [CIImage imageWithContentsOfURL:url];
+ return image;
+}
+
+-(CIImage*) filterCIImage:(CIImage*)inputImage{
+ // [resizeFilter setValue:inputImage forKey:@"inputImage"];
+ // [depthBlurFilter setValue:[resizeFilter valueForKey:@"outputImage"] forKey:@"inputImage"];
+ [blurFilter setValue:[NSNumber numberWithFloat:PropF(@"blur")] forKey:@"inputRadius"];
+ [blurFilter setValue:inputImage forKey:@"inputImage"];
+ CIImage * _outputImage = [blurFilter valueForKey:@"outputImage"];
+ return _outputImage;
+}
+
-(void) render{
+
+
+
+
+
ofFill();
ofSetColor(255, 255, 255);
+
+ /* bwShader->begin();
+ bwShader->setUniform("min", PropF(@"min"));
+ bwShader->setUniform("max", PropF(@"max"));*/
+
+ // deinterlace->begin();
+ // deinterlace->setUniform("texcoord0", ofGetFrameNum()%2, 0);
+ // deinterlace->setUniform("texdim0", 720, 576);
+
if(outSelector == 0){
ofSetColor(0, 0, 0);
ofRect(0, 0, 1, 1);
}
- if(outSelector > 0 && outSelector <= 3){
- currentFrames[outSelector-1].draw(0,0,1,1);
+ /* if(outSelector == 2){
+ glScaled(1.333,1,1);
+ [self imageForSelector:outSelector]->draw(0,0,1,1);
}
+ else */
+ if(outSelector > 0 && outSelector <= 4){
+ CIImage * outputImage = [self createCIImageFromTexture:[self imageForSelector:outSelector]->getTextureReference().getTextureData().textureID size:NSMakeSize([self imageForSelector:outSelector]->getWidth(), [self imageForSelector:outSelector]->getHeight())];
+
+ outputImage = [self filterCIImage:outputImage];
+ glScaled(1.0/[outputImage extent].size.width, 1.0/[outputImage extent].size.height, 1);
+ //glScaled(1.0/720, 10/576.0, 1);
+ [ciContext drawImage:outputImage
+ atPoint:CGPointMake(0,0) // use integer coordinates to avoid interpolation
+ fromRect:[outputImage extent]];
+
+ //[self imageForSelector:outSelector]->draw(0,0,1,1);
+ }
+// bwShader->end();
+ // deinterlace->end();
}
-(void)draw:(NSDictionary *)drawingInformation{
-
+ ciContext = ciContextMain;
// shader->begin();
[self render];
@@ -83,7 +203,18 @@ -(void)draw:(NSDictionary *)drawingInformation{
//
-(void)controlDraw:(NSDictionary *)drawingInformation{
+ if(!ciContextControl){
+ CGLContextObj contextGl = CGLGetCurrentContext();
+ CGLPixelFormatObj pixelformatGl = CGLPixelFormatObj([[[[[globalController viewManager] glViews] objectAtIndex:0] pixelFormat] CGLPixelFormatObj]);
+ ciContextControl = [CIContext contextWithCGLContext:contextGl pixelFormat:pixelformatGl colorSpace:CGColorSpaceCreateDeviceRGB() options:nil];
+ }
+ ciContext = ciContextControl;
+
+
+
ofBackground(255, 255, 255);
+ ofSetColor(255, 255, 255);
+
float w = ofGetWidth();
float h = ofGetHeight();
@@ -100,6 +231,8 @@ -(void)controlDraw:(NSDictionary *)drawingInformation{
}
+
+
-(void)controlKeyPressed:(int)key modifier:(int)modifier{
// NSLog(@"%i",key);
switch (key) {
@@ -116,6 +249,15 @@ -(void)controlKeyPressed:(int)key modifier:(int)modifier{
case 85:
outSelector = 3;
break;
+ case 86:
+ recordMovie = !recordMovie;
+ recordIndex = 0;
+ break;
+ case 87:
+ recordMovie = false;
+ outSelector = 4;
+ playbackIndex = 0;
+ break;
default:
break;
View
4 ViljensTriumf/Plugins/DecklinkCallback.h
@@ -37,5 +37,9 @@ class DecklinkCallback : public IDeckLinkInputCallback{
void CreateLookupTables();
void YuvToRgbChunk(unsigned char *yuv, unsigned char * rgb, unsigned int offset, unsigned int chunk_size);
unsigned char * YuvToRgb(IDeckLinkVideoInputFrame* pArrivedFrame);
+
+ pthread_mutex_t mutex;
+
+ unsigned char * rgb;
};
View
92 ViljensTriumf/Plugins/DecklinkCallback.cpp → ViljensTriumf/Plugins/DecklinkCallback.mm
@@ -142,22 +142,47 @@ unsigned char * DecklinkCallback::YuvToRgb(IDeckLinkVideoInputFrame* pArrivedFra
pArrivedFrame->GetBytes((void**)&yuv);
// allocate space for the rgb image
- unsigned char * rgb = (unsigned char *) malloc(pArrivedFrame->GetWidth() * pArrivedFrame->GetHeight()*3*sizeof(unsigned char));
+ if(rgb == nil){
+ int size = pArrivedFrame->GetWidth() * pArrivedFrame->GetHeight()*3*sizeof(unsigned char);
+ rgb = (unsigned char *) malloc(size);
+ }
// shared_ptr<DLFrame> rgb(new DLFrame(mCaptureWidth, mCaptureHeight, mRgbRowBytes, DLFrame::DL_RGB));
- // int num_workers = conversion_workers.size() - 1;
+ int num_workers = 8;
+
+ int a;
+ unsigned t0=clock(),t1;
// split up the image into memory-aligned chunks so they take advantage of
// the CPU cache
- int mConversionChunkSize = pArrivedFrame->GetRowBytes() * (long)ceil(pArrivedFrame->GetHeight() / 1.0);
+ int mConversionChunkSize = pArrivedFrame->GetRowBytes() * (long)ceil(pArrivedFrame->GetHeight() /(float) num_workers);
- YuvToRgbChunk(yuv,rgb, mConversionChunkSize*0, mConversionChunkSize);
+ dispatch_queue_t queue = dispatch_get_global_queue(0,0);
+ dispatch_group_t group = dispatch_group_create();
+
+ for(int i=0;i<num_workers;i++){
+ dispatch_group_async(group,queue,^{
+ YuvToRgbChunk(yuv,rgb, mConversionChunkSize*i, mConversionChunkSize);
+ });
+ }
+ dispatch_group_wait(group, sizeof(int));
+
+ t1=clock()-t0;
+ //printf("%i\n",t1);
return rgb;
}
-
+void bwFrames(unsigned char * bytes, int size){
+ for(int i=0;i<size;i++){
+ unsigned char * r = bytes + i*3;
+ unsigned char * g = bytes + i*3+1;
+ unsigned char * b = bytes + i*3+2;
+ int c = (*r + *g + *b)/3.0;
+ bytes[i] = c;
+ }
+}
@@ -165,6 +190,9 @@ unsigned char * DecklinkCallback::YuvToRgb(IDeckLinkVideoInputFrame* pArrivedFra
DecklinkCallback::DecklinkCallback(){
bytes = 0;
CreateLookupTables();
+
+ pthread_mutex_init(&mutex, NULL);
+
};
@@ -208,40 +236,42 @@ HRESULT DecklinkCallback::VideoInputFormatChanged (/* in */ BMDVideoInputFormat
break;
}
modeIndex++;
- }
-
-
-bail:
- [pool release];
- return S_OK;*/
+ }
+
+
+ bail:
+ [pool release];
+ return S_OK;*/
}
HRESULT DecklinkCallback::VideoInputFrameArrived (/* in */ IDeckLinkVideoInputFrame* videoFrame, /* in */ IDeckLinkAudioInputPacket* audioPacket)
{
- // BMDPixelFormat pixelFormat = videoFrame->GetPixelFormat();
-
-
-
- w = videoFrame->GetWidth();
- h = videoFrame->GetHeight();
- size = w * h * 3;
-
-
- if(bytes){
- delete bytes;
+ if(pthread_mutex_trylock(&mutex) == 0){
+ BMDPixelFormat pixelFormat = videoFrame->GetPixelFormat();
+
+
+
+ w = videoFrame->GetWidth();
+ h = videoFrame->GetHeight();
+ size = w * h * 3;
+
+
+ /* if(bytes){
+ delete bytes;
+ }*/
+ bytes = YuvToRgb(videoFrame);
+ // bwFrames(bytes,w*h);
+
+ newFrame = true;
+ pthread_mutex_unlock(&mutex);
}
- bytes = YuvToRgb(videoFrame);
-
-
- newFrame = true;
-
- // videoFrame->get
+ // videoFrame->get
/* BOOL hasValidInputSource = (videoFrame->GetFlags() & bmdFrameHasNoInputSource) != 0 ? NO : YES;
- AncillaryDataStruct ancillaryData;
-
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ AncillaryDataStruct ancillaryData;
+
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
// Update input source label
[uiDelegate updateInputSourceState:hasValidInputSource];
View
34 ViljensTriumf/Plugins/deinterlaceFilter.cikernel
@@ -0,0 +1,34 @@
+/*
+
+ v002 brute force, stupid stupid line averaging deinterlacer
+
+ we have to average like so:
+ scanline 0 and 1 are (0 + 1) / 2.
+ scanline 2 and 3 are (2 + 3) / 2.
+
+ we need to not do
+ scanline 0 and 1 are (0 + 1) / 2.
+ scanline 1 and 2 are (1 + 2) / 2.
+
+ p.s. short cow goes moo.
+*/
+
+kernel vec4 v002SimpleDeinterlace(sampler image)
+{
+ vec2 texcoord0 = samplerCoord(image);
+ float isodd = mod(samplerCoord(image).y, 2.0); // returns 0 or 1.
+
+ // unfortunately this niave approach requires us to sample a bit more often than we would like
+ // our odd sampling
+ vec4 oddevenfield = sample(image, vec2(texcoord0.x, texcoord0.y + 1.0));
+ vec4 oddoddfield = sample(image, texcoord0);
+ vec4 oddresult = mix(oddevenfield, oddoddfield, 0.5);
+
+ // our even sampling
+ vec4 evenevenfield = sample(image, texcoord0);
+ vec4 evenoddfield = sample(image, vec2(texcoord0.x, texcoord0.y - 1.0));
+ vec4 evenresult = mix(evenevenfield, evenoddfield, 0.5);
+
+ // final output
+ return mix(oddresult, evenresult, isodd);
+}
View
34 ViljensTriumf/Plugins/shaders/bwShader.frag
@@ -0,0 +1,34 @@
+uniform sampler2DRect src_tex_unit0;
+uniform float min;
+uniform float max;
+
+uniform vec2 start;
+uniform vec2 middle;
+uniform vec2 end;
+
+vec2 bezier(float t){
+ return (1.0-t)*(1.0-t)*start + 2.0*t*(1.0-t)*middle + t*t*end;
+}
+
+void main( void )
+{
+ vec2 st = gl_TexCoord[0].st;
+
+ vec4 color = texture2DRect(src_tex_unit0, st );
+ /*
+ vec2 ret = bezier(color.r);
+ color.r = ret.y;
+
+ ret = bezier(color.g);
+ color.g = ret.y;
+
+ ret = bezier(color.b);
+ color.b = ret.y;
+ */
+
+ float size = max - min;
+ color.rgb -= vec3(min);
+ color.rgb /= vec3(size);
+
+ gl_FragColor = color;
+}
View
0  ViljensTriumf/Plugins/colorCorrectShader.vert → ViljensTriumf/Plugins/shaders/bwShader.vert
File renamed without changes
View
0  ViljensTriumf/Plugins/colorCorrectShader.frag → ...ensTriumf/Plugins/shaders/colorCorrectShader.frag
File renamed without changes
View
4 ViljensTriumf/Plugins/shaders/colorCorrectShader.vert
@@ -0,0 +1,4 @@
+void main() {
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_Position = ftransform();
+}
View
44 ViljensTriumf/Plugins/shaders/deinterlace.frag
@@ -0,0 +1,44 @@
+// define our rectangular texture samplers
+uniform sampler2DRect tex0;
+
+// define our varying texture coordinates
+//varying vec2 texcoord0;
+//varying vec2 texdim0;
+
+void main (void)
+{ /*
+// we have to average like so:
+// scanline 0 and 1 are (0 + 1) / 2.
+// scanline 2 and 3 are (2 + 3) / 2.
+
+// we need to not do
+// scanline 0 and 1 are (0 + 1) / 2.
+// scanline 1 and 2 are (1 + 2) / 2.
+
+float isodd = mod(texcoord0.y, 2.0); // returns 0 or 1.
+
+vec4 result;
+
+if(bool(isodd))
+{
+vec4 evenfield = texture2DRect(tex0, vec2(texcoord0.x, texcoord0.y + 1.0));
+vec4 oddfield = texture2DRect(tex0, texcoord0);
+
+result = mix(evenfield, oddfield, 0.5);
+}
+
+else
+{
+vec4 evenfield = texture2DRect(tex0, texcoord0);
+vec4 oddfield = texture2DRect(tex0, vec2(texcoord0.x, texcoord0.y - 1.0));
+
+result = mix(evenfield, oddfield, 0.5);
+}
+*/
+//gl_FragColor = result;
+ vec2 st = gl_TexCoord[0].st;
+
+ gl_FragColor = gl_Color * texture2DRect(tex0, st );
+
+// moo : short cow !
+}
View
10 ViljensTriumf/Plugins/shaders/deinterlace.vert
@@ -0,0 +1,10 @@
+//varying vec2 texcoord0;
+//varying vec2 texdim0;
+
+void main() {
+ gl_TexCoord[0] = gl_MultiTexCoord0;
+ gl_Position = ftransform();
+
+ // texcoord0 = vec2(0,0);
+ // texdim0 = vec2(720,576);
+}
View
4 ViljensTriumf/ofxShader/ofxShader.cpp
@@ -13,8 +13,8 @@ void ofxShader::setup(string shaderName) {
}
void ofxShader::setup(string vertexName, string fragmentName) {
-// vertexName += ".vert";
-// fragmentName += ".frag";
+ vertexName += ".vert";
+ fragmentName += ".frag";
setupInline(loadTextFile(vertexName), loadTextFile(fragmentName));
}
Please sign in to comment.
Something went wrong with that request. Please try again.