How to make an NSImage from a PixMapHandle ?

I have some Carbon code of my own returning PixMapHandle, I want to use it in my new Cocoa app…

PixMap internal format (especially the indexed pixel format):
rendering the PixelMap into a NSQuickDrawView (starting by
lockFocus on the NSQuickDrawView, then gets the quickdraw port by calling the qdPort method and use the classic carbon calls to render the pixmap: LockPixels, CopyBits), UnlockPixels followed by creating a NSBitmapImageRep with its initWithFocusedViewRect method.
Then you can add the
NSBitmapImageRep to a NSImage instance.
Note that if I your code is fully controlling the creation of the pixmap and the pixelType is
RGBDirect, you could share the pixels of the pixmap with the NSBitmapRep, creating the latest one with initWithBitmapDataPlanes.
Other point to care of: if you plan to use Cocoa calls to further draw on the
NSImage wrapping the newly created NSBitmapImageRep, you will encounter the following problem: calling lockFocus creates a new NSCachedImageRep for this image, replacing your NSBitmapImageRep. To achieve the desired result you have to create yet a new NSImage, draw the one containing the bitmap in this new image, and then do your Cocoa drawing. After that you can get rid of the image containing the bitmap unless you need it for caching purpose.
Several strategies may be envisaged but we will look at the simplest one that will avoid any worrying about the