Displaying custom video (RGB bitmap data) within a Mac OS X Window
bitmap, cocoa, macos, rgb, window
Solution
I would recommend either creating `NSImage`s or `CGImage`s with your data and then drawing them to the current context.
If you use `NSImage`, you'll need to create an `NSBitmapImageRep` with the data of your image. You don't need to copy the data, just pass the pointer to it as one of the parameters to the initializer.
If you use `CGImage`, you can create a `CGBitmapContextRef` using `CGBitmapContextCreate()`, and as above, just pass a pointer to the existing image data. Then you can create a `CGImage` from it by calling `CGBitmapContextCreateImage()`.
Problem
I'm looking for the best way to quickly and repeatedly "blit" RGB bitmap data to a specific area within a Mac OS X window, for the purpose of displaying video frames coming from a custom video engine in real time. The data is in a simple C-style array containing a 32-BPP bitmap. On Win32, I'd setup HWND and HDC's, copy the raw data into its memory space, and then use BitBlt(). On iOS, I've done it via UIImageView, although I didn't fully assess the performance of that approach (really didn't need to in that particular limited case). I have neither available to me on Mac OS X with Cocoa, so what should I do? I know there are several bad or convoluted ways for me to accomplish this, but I'm hoping someone with experience can point me to something that's actually meant for this use and/or is performance efficient while being reasonably straightforward and reliable. Thanks!