Home › Forums › Syphon › Syphon Development – Developer › Syphon -> CoreImage › Reply To: Syphon -> CoreImage
July 3, 2011 at 1:41 am
#5168
Participant
well, actually what I am trying to do is to copy syphonimages in CPU memory space (i.e. in a NSBitmapImageRep). Since I am making some processing in realtime I need to do this in the fastest possible way. I tried to reuse some of the code that I wrote for a simple QTKit stream ( where CIImages were created with [CIImage imageWithCVImageBuffer:pixelBuffer] method), but the result now is: black images. Why? Here is the pseudo code:
CGLContextObj cgl_ctx = [[openGLRenderContext CGLContextObj]; // openGLRenderContext is a previously created openGL context
SyphonImage *image = [[syClient newFrameImageForContext:cgl_ctx] autorelease];
GLuint texture = [image textureName];
NSSize imageSize = [image textureSize];
const CGRect r = {.origin = {0, 0}, .size = {imageSize.width, imageSize.height}};
CIImage *ciImage = [CIImage imageWithTexture:texture
size:r.size
flipped:YES
colorSpace:cs];
NSBitmapImageRep* bitmap=[[[NSBitmapImageRep alloc]
initWithBitmapDataPlanes: nil
pixelsWide: [ciImage extent].size.width
pixelsHigh: [ciImage extent].size.height
bitsPerSample:8
samplesPerPixel:4
hasAlpha: YES
isPlanar: NO
colorSpaceName: NSCalibratedRGBColorSpace
bytesPerRow: 0
bitsPerPixel:32] autorelease] ;
NSGraphicsContext * graphicsContext = [NSGraphicsContext
graphicsContextWithBitmapImageRep: bitmap] ;
CGRect rect = [ciImage extent];
[[graphicsContext CIContext] drawImage: ciImage
atPoint: CGPointZero
fromRect: rect];
I suppose that it is not working because [graphicsContext CIContext] is not shared with cgl_ctx. So, how to proceed? Which is the “best practice”??