image conversion, a better way to CGImageRef

  • Hello List :-)

    I'm curious to know if there is a fast way to convert a QT visual
    context based frame into a CGImageRef.

    Presently I think I'm doing it in a rather expensive way, namely:

    CVImageBufferRef imageBuffer = 0;

    QTVisualContextCopyImageForTime(_textureContext,
      kCFAllocatorDefault,
      0,
      &imageBuffer);

    CGImageRef _imageRef = 0;

    float w = self.frame.size.width;
    float h = self.frame.size.height;

    NSRect rect = NSMakeRect(0, 0, w, h);
    CIImage* theImage = [CIImage imageWithCVImageBuffer:imageBuffer];
    CGSize cgTexSize = CVImageBufferGetDisplaySize(imageBuffer);

    rect = rectAdjustedToAspectRatio(NSMakeRect(0, 0, w, h),
                            NSMakeSize(cgTexSize.width, cgTexSize.height));

    CGRect theImageRect = CGRectMake(rect.origin.x, rect.origin.y,
    rect.size.width, rect.size.height);

    // this bit is pretty expensive I believe...
    [_ciContext drawImage: theImage  inRect: theImageRect  fromRect:
    [theImage extent]];
    _imageRef = [_ciContext createCGImage:theImage fromRect:theImageRect];

    The CIContext (_ciContext) was initialised using a glContext and
    pixelFormat from within prepareOpenGL of an NSOpenGLView.

    Does anyone know of a faster way to obtain a CGImageRef from the QT
    visual context?  Thanks in advance, have a good day.

    --
    John Clayton
    http://www.coderage-software.com/
previous month november 2007 next month
MTWTFSS
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30    
Go to today