Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: HalfdanJ/ViljensTriumfPerformance
base: 8ea3bd5884
...
head fork: HalfdanJ/ViljensTriumfPerformance
compare: a61a7a681d
  • 2 commits
  • 10 files changed
  • 0 commit comments
  • 1 contributor
View
6 ViljensTriumf.xcodeproj/project.pbxproj
@@ -30,6 +30,7 @@
DD4CC1EF161DF194000E459D /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DD4CC1EE161DF194000E459D /* QuartzCore.framework */; };
DDDCF65F161EBC0700E8E368 /* DeinterlaceFilter.m in Sources */ = {isa = PBXBuildFile; fileRef = DDDCF65E161EBC0700E8E368 /* DeinterlaceFilter.m */; };
DDDCF661161EBC1700E8E368 /* deinterlaceFilter.cikernel in Resources */ = {isa = PBXBuildFile; fileRef = DDDCF660161EBC1700E8E368 /* deinterlaceFilter.cikernel */; };
+ DDE64735161EC97E0007E490 /* BlackMagicController.mm in Sources */ = {isa = PBXBuildFile; fileRef = DDDCF65A161EB93500E8E368 /* BlackMagicController.mm */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
@@ -201,12 +202,12 @@
DD039731161C4FE000D0D629 /* BlackMagic */ = {
isa = PBXGroup;
children = (
+ 8429C0DA156A7943000ADD56 /* BlackMagic.h */,
+ 8429C0DB156A7943000ADD56 /* BlackMagic.mm */,
DDDCF65C161EBBF900E8E368 /* filters */,
DDDCF659161EB93500E8E368 /* BlackMagicController.h */,
DDDCF65A161EB93500E8E368 /* BlackMagicController.mm */,
DD039719161C4F9000D0D629 /* include */,
- 8429C0DA156A7943000ADD56 /* BlackMagic.h */,
- 8429C0DB156A7943000ADD56 /* BlackMagic.mm */,
DD039735161C591400D0D629 /* DecklinkCallback.h */,
DD039736161C591400D0D629 /* DecklinkCallback.mm */,
8429C0DC156A7943000ADD56 /* BlackMagic.xib */,
@@ -324,6 +325,7 @@
DD4CC1E9161DEA13000E459D /* bwShader.vert in Sources */,
DD4CC1EA161DEA13000E459D /* colorCorrectShader.frag in Sources */,
DD4CC1EB161DEA13000E459D /* colorCorrectShader.vert in Sources */,
+ DDE64735161EC97E0007E490 /* BlackMagicController.mm in Sources */,
DD4CC1EC161DEA13000E459D /* deinterlace.frag in Sources */,
DD4CC1ED161DEA13000E459D /* deinterlace.vert in Sources */,
DDDCF65F161EBC0700E8E368 /* DeinterlaceFilter.m in Sources */,
View
10 ViljensTriumf/Plugins/BlackMagic.h
@@ -12,7 +12,7 @@ class DeckLinkController;
int outSelector;
- ofImage currentFrames[3];
+ CIImage * currentFrames[3];
ofImage movieRecording[MOVIE_LENGTH];
int playbackIndex;
@@ -27,14 +27,16 @@ class DeckLinkController;
ofxShader * deinterlace;
*/
-
+
CIContext * ciContextMain; //Context for main output
CIContext * ciContextControl; //Context for control gl view
CIContext * ciContext; //Dynamic switched context (main/control)
CIFilter * blurFilter;
- CIFilter * deinterlaceFilter;
-
+ DeinterlaceFilter * deinterlaceFilter;
+ CIFilter * colorControlsFilter;
+ CIFilter * gammaAdjustFilter;
+ CIFilter * toneCurveFilter;
}
@end
View
157 ViljensTriumf/Plugins/BlackMagic.mm
@@ -5,9 +5,21 @@
@implementation BlackMagic
-(void)initPlugin{
- [self addPropF:@"min"];
- [self addPropF:@"max"];
- [self addPropF:@"blur"];
+ [self addPropF:@"saturation"];
+ [self addPropF:@"brightness"];
+ [[self addPropF:@"contrast"] setMaxValue:1.5];
+
+ [[self addPropF:@"gamma"] setMaxValue:1.5];
+
+/*[self addPropF:@"curvep1"];
+ [self addPropF:@"curvep2"];
+ [self addPropF:@"curvep3"];
+ [self addPropF:@"curvep4"];
+ [self addPropF:@"curvep5"];*/
+
+
+ // [self addPropF:@"blur"];
+ [self addPropB:@"deinterlace"];
blackMagicController = [[BlackMagicController alloc] init];
@@ -40,16 +52,19 @@ -(void)setup{
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];
+ colorControlsFilter = [[CIFilter filterWithName:@"CIColorControls"] retain];
+ [colorControlsFilter setDefaults];
+
+ gammaAdjustFilter = [[CIFilter filterWithName:@"CIGammaAdjust"] retain];
+ [gammaAdjustFilter setDefaults];
- deinterlaceFilter = [CIFilter fil]
+ toneCurveFilter = [[CIFilter filterWithName:@"CIToneCurve"] retain];
+ [toneCurveFilter setDefaults];
+ deinterlaceFilter = [[DeinterlaceFilter alloc] init];
+ [deinterlaceFilter setDefaults];
CGLContextObj contextGl = CGLContextObj([[[[[globalController viewManager] glViews] objectAtIndex:0] openGLContext] CGLContextObj]);
CGLPixelFormatObj pixelformatGl = CGLPixelFormatObj([[[[[globalController viewManager] glViews] objectAtIndex:0] pixelFormat] CGLPixelFormatObj]);
@@ -68,14 +83,14 @@ -(void)setup{
--(ofImage*) imageForSelector:(int)selector{
+-(CIImage*) imageForSelector:(int)selector{
if(selector == 0){
return nil;
}
if(selector > 0 && selector <= 3){
- return &currentFrames[selector-1];
+ return currentFrames[selector-1];
}
- if(selector == 4){
+ /* if(selector == 4){
if(millisAtLastFramePlayback < ofGetElapsedTimeMillis() - 40){
millisAtLastFramePlayback = ofGetElapsedTimeMillis();
playbackIndex++;
@@ -84,30 +99,41 @@ -(ofImage*) imageForSelector:(int)selector{
}
}
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;
+ callback->newFrame = false;
+ int w = callback->w;
+ int h = callback->h;
+
+
+
+ if(currentFrames[i]){
+ [currentFrames[i] release];
+ }
+
+ pthread_mutex_lock(&callback->mutex);
+ unsigned char * bytes = callback->bytes;
+ NSData * data = [[NSData dataWithBytes:bytes length:w*h*4] autorelease];
+ // NSLog(@"%i",[data retainCount]);
- /* if(currentFrames[i].width != w){
- currentFrames[i].allocate(w, h, OF_IMAGE_COLOR);
- }
-*/
- unsigned char * bytes = callbacks[i]->bytes;
- currentFrames[i].setFromPixels(bytes, w, h, OF_IMAGE_COLOR);
- pthread_mutex_unlock(&callbacks[i]->mutex);
+ pthread_mutex_unlock(&callback->mutex);
+
+ CGColorSpace * space = CGColorSpaceCreateDeviceRGB();
+ currentFrames[i] = [CIImage imageWithBitmapData:data bytesPerRow:w*4 size:CGSizeMake(w, h) format:kCIFormatARGB8 colorSpace:space];
+
+ [data release];
+ data = nil;
+
}
}
- if(recordMovie){
+/* if(recordMovie){
if(millisAtLastFrameRecord < ofGetElapsedTimeMillis() - 40){
millisAtLastFrameRecord = ofGetElapsedTimeMillis();
ofImage * img = [self imageForSelector:outSelector];
@@ -121,7 +147,7 @@ -(void)update:(NSDictionary *)drawingInformation{
}
}
- }
+ }*/
}
@@ -139,9 +165,38 @@ -(CIImage*) createCIImageFromTexture:(GLint)tex size:(NSSize)size{
-(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"];
+
+ CIImage * _outputImage = inputImage;
+
+ if(PropB(@"deinterlace")){
+ [deinterlaceFilter setInputImage:_outputImage];
+ _outputImage = [deinterlaceFilter valueForKey:@"outputImage"];
+ }
+
+// [blurFilter setValue:[NSNumber numberWithFloat:PropF(@"blur")] forKey:@"inputRadius"];
+// [blurFilter setValue:_outputImage forKey:@"inputImage"];
+// _outputImage = [blurFilter valueForKey:@"outputImage"];
+//
+ [colorControlsFilter setValue:[NSNumber numberWithFloat:PropF(@"saturation")] forKey:@"inputSaturation"];
+ [colorControlsFilter setValue:[NSNumber numberWithFloat:PropF(@"contrast")] forKey:@"inputContrast"];
+ [colorControlsFilter setValue:[NSNumber numberWithFloat:PropF(@"brightness")] forKey:@"inputBrightness"];
+ [colorControlsFilter setValue:_outputImage forKey:@"inputImage"];
+ _outputImage = [colorControlsFilter valueForKey:@"outputImage"];
+
+
+ [gammaAdjustFilter setValue:[NSNumber numberWithFloat:PropF(@"gamma")] forKey:@"inputPower"];
+ [gammaAdjustFilter setValue:_outputImage forKey:@"inputImage"];
+ _outputImage = [gammaAdjustFilter valueForKey:@"outputImage"];
+
+ /* [toneCurveFilter setValue:[NSNumber numberWithFloat:PropF(@"curvep1")] forKey:@"inputPoint0"];
+ [toneCurveFilter setValue:[NSNumber numberWithFloat:PropF(@"curvep2")] forKey:@"inputPoint1"];
+ [toneCurveFilter setValue:[NSNumber numberWithFloat:PropF(@"curvep3")] forKey:@"inputPoint2"];
+ [toneCurveFilter setValue:[NSNumber numberWithFloat:PropF(@"curvep4")] forKey:@"inputPoint3"];
+ [toneCurveFilter setValue:[CIVector numberWithFloat:PropF(@"curvep5")] forKey:@"inputPoint4"];
+ [toneCurveFilter setValue:_outputImage forKey:@"inputImage"];
+ _outputImage = [toneCurveFilter valueForKey:@"outputImage"];*/
+
+
return _outputImage;
}
@@ -161,31 +216,37 @@ -(void) render{
// deinterlace->begin();
// deinterlace->setUniform("texcoord0", ofGetFrameNum()%2, 0);
- // deinterlace->setUniform("texdim0", 720, 576);
+ // deinterlace->setUniform("texdim0", 720, 576);
if(outSelector == 0){
ofSetColor(0, 0, 0);
ofRect(0, 0, 1, 1);
}
- /* if(outSelector == 2){
- glScaled(1.333,1,1);
- [self imageForSelector:outSelector]->draw(0,0,1,1);
- }
- else */
+ /* 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())];
+ // 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]];
+ CIImage * outputImage = [self imageForSelector:outSelector];
+ if(outputImage){
+ outputImage = [self filterCIImage:outputImage];
+
+ float h = [outputImage extent].size.height;
+ glScaled(1.0/[outputImage extent].size.width, -1.0/h, 1);
+ //glScaled(1.0/720, 10/576.0, 1);
+ [ciContext drawImage:outputImage
+ atPoint:CGPointMake(0,-h) // use integer coordinates to avoid interpolation
+ fromRect:[outputImage extent]];
+ }
+ outputImage = nil;
- //[self imageForSelector:outSelector]->draw(0,0,1,1);
+ //[self imageForSelector:outSelector]->draw(0,0,1,1);
}
-// bwShader->end();
- // deinterlace->end();
+ // bwShader->end();
+ // deinterlace->end();
}
-(void)draw:(NSDictionary *)drawingInformation{
@@ -222,12 +283,12 @@ -(void)controlDraw:(NSDictionary *)drawingInformation{
float mH = mW * 3.0/4.0;
for(int i=0;i<3;i++){
- currentFrames[i].draw(i*mW,0,mW,mH);
+ // currentFrames[i].draw(i*mW,0,mW,mH);
}
ofTranslate(0,mH+30);
ofScale(mW*3,mH*3);
- [self render];
+ // [self render];
}
View
4 ViljensTriumf/Plugins/BlackMagicController.h
@@ -16,7 +16,11 @@
std::vector<IDeckLink*> deviceList;
IDeckLinkInput * deckLinkInputs[3];
+ IDeckLinkOutput * deckLinkOutputs[3];
DecklinkCallback * callbacks[3];
+
+@public
+ IDeckLinkGLScreenPreviewHelper* glhelper;
}
View
12 ViljensTriumf/Plugins/BlackMagicController.mm
@@ -36,14 +36,22 @@ -(void) initDecklink {
}
+ glhelper = CreateOpenGLScreenPreviewHelper();
+
for(int index=0;index<deviceList.size();index++){
// Get the IDeckLinkInput for the selected device
if ((deviceList[index]->QueryInterface(IID_IDeckLinkInput, (void**)&deckLinkInputs[index]) != S_OK))
{
NSLog(@"This application was unable to obtain IDeckLinkInput for the selected device.");
}
-
-
+ /*
+ if ((deviceList[index]->QueryInterface(IID_IDeckLinkOutput, (void**)&deckLinkOutputs[index]) != S_OK))
+ {
+ NSLog(@"This application was unable to obtain IDeckLinkOutput for the selected device.");
+ }
+ callbacks[index]->output = deckLinkOutputs[index];
+ */
+
//
// Retrieve and cache mode list
View
9 ViljensTriumf/Plugins/DecklinkCallback.h
@@ -35,11 +35,14 @@ class DecklinkCallback : public IDeckLinkInputCallback{
unsigned char Clamp(int value);
void CreateLookupTables();
- void YuvToRgbChunk(unsigned char *yuv, unsigned char * rgb, unsigned int offset, unsigned int chunk_size);
- unsigned char * YuvToRgb(IDeckLinkVideoInputFrame* pArrivedFrame);
+ void YuvToARgbChunk(unsigned char *yuv, unsigned char * argb, unsigned int offset, unsigned int chunk_size);
+ unsigned char * YuvToARgb(IDeckLinkVideoInputFrame* pArrivedFrame);
pthread_mutex_t mutex;
- unsigned char * rgb;
+ unsigned char * argb;
+
+ IDeckLinkOutput * output;
+ IDeckLinkVideoConversion * converter;
};
View
67 ViljensTriumf/Plugins/DecklinkCallback.mm
@@ -82,27 +82,33 @@
-void DecklinkCallback::YuvToRgbChunk(unsigned char *yuv, unsigned char * rgb, unsigned int offset, unsigned int chunk_size)
+void DecklinkCallback::YuvToARgbChunk(unsigned char *yuv, unsigned char * __argb, unsigned int offset, unsigned int chunk_size)
{
- // convert 4 YUV macropixels to 6 RGB pixels
+ // convert 4 YUV macropixels to 8 ARGB pixels
unsigned int i, j;
unsigned int boundry = offset + chunk_size;
int y, u, v;
- for(i=offset, j=(offset/4)*6; i<boundry; i+=4, j+=6){
+ for(i=offset, j=(offset/4)*8; i<boundry; i+=4, j+=8){
y = yuv[i+1];
u = yuv[i];
v = yuv[i+2];
- rgb[j] = red[y][v];
- rgb[j+1] = green[y][u][v];
- rgb[j+2] = blue[y][u];
+ unsigned char * _rgb = __argb+j;
- y = yuv[i+3];
+ // *(_rgb++) = 255;
+ _rgb++;
+ *(_rgb++) = red[y][v];
+ *(_rgb++) = green[y][u][v];
+ *(_rgb++) = blue[y][u];
- rgb[j+3] = red[y][v];
- rgb[j+4] = green[y][u][v];
- rgb[j+5] = blue[y][u];
+ y = yuv[i+3];
+
+ // *(_rgb++) = 255;
+ _rgb++;
+ *(_rgb++) = red[y][v];
+ *(_rgb++) = green[y][u][v];
+ *(_rgb) = blue[y][u];
}
/*
@@ -136,22 +142,24 @@
}
-unsigned char * DecklinkCallback::YuvToRgb(IDeckLinkVideoInputFrame* pArrivedFrame)
+unsigned char * DecklinkCallback::YuvToARgb(IDeckLinkVideoInputFrame* pArrivedFrame)
{
+
+
unsigned char * yuv;
pArrivedFrame->GetBytes((void**)&yuv);
// allocate space for the rgb image
- if(rgb == nil){
- int size = pArrivedFrame->GetWidth() * pArrivedFrame->GetHeight()*3*sizeof(unsigned char);
- rgb = (unsigned char *) malloc(size);
+ if(argb == nil){
+ int size = pArrivedFrame->GetWidth() * pArrivedFrame->GetHeight()*4*sizeof(unsigned char);
+ argb = (unsigned char *) malloc(size);
+ memset(argb, 255, size);
}
// shared_ptr<DLFrame> rgb(new DLFrame(mCaptureWidth, mCaptureHeight, mRgbRowBytes, DLFrame::DL_RGB));
- int num_workers = 8;
+ int num_workers = 16;
- int a;
- unsigned t0=clock(),t1;
+ //unsigned t0=clock(),t1;
// split up the image into memory-aligned chunks so they take advantage of
// the CPU cache
@@ -163,17 +171,17 @@
for(int i=0;i<num_workers;i++){
dispatch_group_async(group,queue,^{
- YuvToRgbChunk(yuv,rgb, mConversionChunkSize*i, mConversionChunkSize);
+ YuvToARgbChunk(yuv,argb, mConversionChunkSize*i, mConversionChunkSize);
});
}
dispatch_group_wait(group, sizeof(int));
- t1=clock()-t0;
+ // t1=clock()-t0;
//printf("%i\n",t1);
- return rgb;
+ return argb;
}
-
+/*
void bwFrames(unsigned char * bytes, int size){
for(int i=0;i<size;i++){
unsigned char * r = bytes + i*3;
@@ -184,7 +192,7 @@ void bwFrames(unsigned char * bytes, int size){
}
}
-
+*/
DecklinkCallback::DecklinkCallback(){
@@ -193,7 +201,7 @@ void bwFrames(unsigned char * bytes, int size){
pthread_mutex_init(&mutex, NULL);
-
+ converter = CreateVideoConversionInstance();
};
@@ -253,13 +261,22 @@ void bwFrames(unsigned char * bytes, int size){
w = videoFrame->GetWidth();
h = videoFrame->GetHeight();
- size = w * h * 3;
+ size = w * h * 4;
+ // IDeckLinkMutableVideoFrame * outFrame;
+ // output->CreateVideoFrame(w, h, w*4, bmdFormat8BitARGB, bmdFrameFlagDefault, &outFrame);
+
+ // int result = converter->ConvertFrame(videoFrame, outFrame);
+// E_FAIL
+ // printf("%i",result);
/* if(bytes){
delete bytes;
}*/
- bytes = YuvToRgb(videoFrame);
+ bytes = YuvToARgb(videoFrame);
+
+
+ //videoFrame->GetBytes((void**)&bytes);
// bwFrames(bytes,w*h);
newFrame = true;
View
6 ViljensTriumf/Plugins/filters/DeinterlaceFilter.h
@@ -6,9 +6,11 @@
//
//
-#import <CoreImage/CoreImage.h>
+#import <QuartzCore/QuartzCore.h>
@interface DeinterlaceFilter : CIFilter{
- CIImage *inputImage;
+ CIImage * _inputImage;
}
+
+@property (strong) CIImage *inputImage;
@end
View
3  ViljensTriumf/Plugins/filters/DeinterlaceFilter.m
@@ -11,6 +11,7 @@
static CIKernel *deinterlaceKernel = nil;
@implementation DeinterlaceFilter
+@synthesize inputImage = _inputImage;
- (id)init
{
@@ -28,7 +29,7 @@ - (id)init
- (CIImage *)outputImage
{
- CISampler *src = [CISampler samplerWithImage: inputImage];
+ CISampler *src = [CISampler samplerWithImage: self.inputImage];
return [self apply: deinterlaceKernel, src, kCIApplyOptionDefinition, [src definition], nil];
}
View
9 ViljensTriumf/Plugins/filters/deinterlaceFilter.cikernel
@@ -22,13 +22,14 @@ kernel vec4 v002SimpleDeinterlace(sampler image)
// 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);
+ vec4 oddresult = mix(oddevenfield, oddoddfield, 0.5);
// our even sampling
- vec4 evenevenfield = sample(image, texcoord0);
+ /* 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);
+ return oddresult;
+ // return mix(oddresult, evenresult, isodd);
}

No commit comments for this range

Something went wrong with that request. Please try again.