Permalink
Browse files

Output doesn't work in control view due to ciimage bug

  • Loading branch information...
1 parent 8050ac1 commit a61a7a681dc8ad4d7d1999d023111652f3c91072 @HalfdanJ committed Oct 5, 2012
@@ -12,7 +12,7 @@ class DeckLinkController;
int outSelector;
- ofImage currentFrames[3];
+ CIImage * currentFrames[3];
ofImage movieRecording[MOVIE_LENGTH];
int playbackIndex;
@@ -27,7 +27,7 @@ class DeckLinkController;
ofxShader * deinterlace;
*/
-
+
CIContext * ciContextMain; //Context for main output
CIContext * ciContextControl; //Context for control gl view
CIContext * ciContext; //Dynamic switched context (main/control)
@@ -83,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++;
@@ -99,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){
+ callback->newFrame = false;
+ int w = callback->w;
+ int h = callback->h;
+
+
+
+ if(currentFrames[i]){
+ [currentFrames[i] release];
+ }
+
pthread_mutex_lock(&callback->mutex);
- callback->newFrame = false;
- int w = callback->w;
- int h = callback->h;
+ 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 = callback->bytes;
- currentFrames[i].setFromPixels(bytes, w, h, OF_IMAGE_COLOR);
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];
@@ -136,7 +147,7 @@ -(void)update:(NSDictionary *)drawingInformation{
}
}
- }
+ }*/
}
@@ -162,10 +173,10 @@ -(CIImage*) filterCIImage:(CIImage*)inputImage{
_outputImage = [deinterlaceFilter valueForKey:@"outputImage"];
}
- /* [blurFilter setValue:[NSNumber numberWithFloat:PropF(@"blur")] forKey:@"inputRadius"];
- [blurFilter setValue:_outputImage forKey:@"inputImage"];
- _outputImage = [blurFilter 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"];
@@ -205,33 +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{
@@ -268,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];
}
@@ -16,6 +16,7 @@
std::vector<IDeckLink*> deviceList;
IDeckLinkInput * deckLinkInputs[3];
+ IDeckLinkOutput * deckLinkOutputs[3];
DecklinkCallback * callbacks[3];
@public
@@ -44,8 +44,14 @@ -(void) initDecklink {
{
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
@@ -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;
};
@@ -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;

0 comments on commit a61a7a6

Please sign in to comment.