2. What's the best way to pull a >8bit image out of QC?
Create your own OpenGL context that's configured as you want (bitdepth-wise, specifically), render the composition ([qcrenderer renderAtTime:time arguments:args];), then download the context's contents as a texture. That'll require some opengl code; glReadPixels is easy but slow, async texture downloads are a bit more involved, but documented all over apple's website (or at least it was until the recent change -- I've not looked recently enough to know if it's still there or not). I'm not sure if the QCRenderer snapshotImageOfType:-style messages will preserve the full bitdepth (I've seen some cases where it doesn't preserve normal 8bit-per-channel image is used in the composition as well as for image processing of the composition output, but that could be user-error on my part), but a few lines of tests would let you know that too.

Hmm... only catch there is that the composition might be processing large (as in 4k x 4k) images, and I'd very much like to capture at that resolution. I'm outputting the raw image data from a published port, which is giving me the right data:

4k*4k*16bytes/pixel = 256MB/image. That's nothing. glReadPixels will let you snag all of that in one go (and if it's too large, you can snag subregions, and assemble them manually -- I can't think of any reason why that'd be useful though). The reason I'm a fan of not using QC/NSImage stuff is because all you honestly really care about is getting the raw pixel data to save to disk, and all the junk on top doesn't help you much at all -- NSImage hides the underlying pixels and doesn't let you save them, CIImage hides the underlying pixels and doesn't let you save them, and does filtering to boot. CGImageRef is your best bet, so the remainder of my reply assumes that I've converted you to The Light Side ;)


NSImage 0x13b2490 Size={512, 512} Reps=(
QCNSBitmapImageRep 0x13ae760 Size={512, 512} ColorSpace=NSCalibratedRGBColorSpace BPS=32 BPP=128 Pixels=512x512 Alpha=YES Planar=NO Format=4

If you're hell-bent on using NSImage, TIFFRepresentation will dump out TIFF data. This will consume ungodly amounts of time and memory though. From the TIFF data, you can init a CGImageRef, which is completely ridiculous (you're encoding, duplicating, and decoding, for what really only needs to be a single "write" operation). You can also iterate through the NSImage's representations ([theImage representations]), and find an NSBitmapImageRep -- that'll give you raw pixel data too. However, I think using this will be unsatisfactory as well, since it's still not helping you accomplish your goal. You can make a CGImageRef from an NSBitmapImageRep though, I _think_ (it's been a while since I've mucked about bridging all the various image formats on OS X...)

Question now is how do I write an openexr file? I see it there in supported file types for NSImage ("com.ilm.openexr-image") but I've no idea how to write out anything other than png/tiff - and NSImage only seems to support returning a TIFF representation. Any pointers? :)


Don't use NSImage -- it's too abstract. Use CGImageRef, which has support from ImageIO (we use that in QuartzCrystal when writing out image sequences).
The pertinent code is this:

static int saveCGImage(NSString *filename, CGImageRef img, CFStringRef codec, CFMutableDictionaryRef props)
{
        NSURL *url = [NSURL fileURLWithPath: filename isDirectory:NO];
CGImageDestinationRef dest = CGImageDestinationCreateWithURL((CFURLRef)url, codec, 1, props);
        CGImageDestinationAddImage(dest,img,NULL);
        CGImageDestinationFinalize(dest);
        CFRelease(dest);
        return 0;
}

takes an NSString for a file name (obviously predates snow leopard, as URLs are now the blessed way to access files), a CGImageRef, the codec cgstring ("com.ilm.openexr-image") -- (remember that CFStringRef is tollfree-bridged with NSString, so @"com.ilm.openexr-image" will work), and props, which is some settings dictionary -- we initialize it like this:

props = CFDictionaryCreateMutable(NULL, 1, NULL, NULL);
CFDictionaryAddValue(props, kCGImageDestinationBackgroundColor, CGColorGetConstantColor(kCGColorBlack));

That's about it, regarding writing CGImageRefs.

--
[ christopher wright ]
[email protected]
http://kineme.net/

Attachment: smime.p7s
Description: S/MIME cryptographic signature

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartzcomposer-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartzcomposer-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to