Search code examples
macosgraphicscore-graphicsquartz-graphicsquartz-2d

Is it possible to inject a CIBumpDistortion filter to a specific area of the screen on Mac OS X (Snow Leopard)?


I want to temporarily distort the area under the mouse using a CIBumpDistortion to increase the visibility of the mouse pointer.

At the moment, I have a transparent-background NSWindow that floats around under the pointer and shows a cross-hair that fades in when you move the mouse, and out when you stop. This is working okay, but a Bump Distortion would make my app awesome instead of good enough.

I tried to use CGDisplayCaptureWithOptions(display, kCGCaptureNoFill), but that reduces the performance to a crawl and makes the mouse pointer stutter.

Here's an image of approximately what I'm trying to achieve.

Note, the area I want to distort is not inside my own NSWindow, so I don't think I can just apply a transformation to a CIImage and display that (unless one of you clever folks shows me that you can copy a bitmap from an arbitrary area of the screen?)

Thanks in advance!


Solution

  • Note, the area I want to distort is not inside my own NSWindow, so I don't think I can just apply a transformation to a CIImage and display that (unless one of you clever folks shows me that you can copy a bitmap from an arbitrary area of the screen?)

    Can do!

    Get your window's windowNumber, and use CGWindowList to create a CGImage screenshot of everything under it. Then, create a CIImage from the CGImage, run it through the filter, and set the output image as what your window displays.

    Providing you only do this when the mouse moves or the screen redraws in the area around the cursor (you can register a screen refresh callback for the latter), you can do this quite effficiently.