Backdrop - Hackdrop

cwright's picture

Recently I've been poking around with a project that makes use of the Private Backdrops patch. This is the patch used by iChat and PhotoBooth. Using it in an application, it seems, is not quite so straight forward.

Somewhat surprisingly, this patch uses the unofficial API (hopefully this means that they'll be keeping this api around a bit, I hope ;). The file, however, is located in a somewhat strange location: /System/Library/Graphics/Quartz\ Composer\ Patches/ -- it's called "Backdrops.plugin".

Compositions that use these patches don't work when launched in an external application though. This is where it gets tricky.

Loading this plugin manually isn't difficult. It's been discussed here before. However, the problem isn't that this plugin isn't loaded -- quite the contrary, plugins are Also loaded from this secret location automatically. The problem begins with a tiny setting in this plugin's Info.plist:

   * <key>GFPlugInExclusiveHosts</key>
   * <array>
      * <string>com.apple.iChat</string>
      * <string>com.apple.PhotoBooth</string>
      * <string>com.apple.QuartzComposer.editor</string>
   * </array>

What this chunk of code does is rather simple: it prevents the plugin from registering unless the host is on the Exclusive List. In this case, the plugin will only successfully load in iChat, PhotoBooth, and QuartzComposer.

There are two possible work-arounds for this exclusion: modify the plist, removing this chunk so that all hosts can load them, or modifying your application to identify as one of Apple's applications. Since I was working on a one-off application, I chose the latter, though the former may be necessary in some cases. Alternatively, a wrapper plugin might possibly be created which works around this; I'm not familiar with the intricate details of plugin loading, so I'm not at liberty to say how possible this is.

Identifying your application is fairly simple: you'll need to set its bundle identifier to one of the above strings. However, some more magic happens at that point: Setting your application's bundle ident to "com.apple.iChat" results in an exciting error message about the application not working in this version of OS X -- but only when launched from Finder. Launching it from within Xcode still works. setting it to "com.apple.PhotoBooth" appears to work for both Xcode launches and Finder launches though.

Fun! :)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

itsthejayj's picture
backdrop pain

Hi all, i've been trying to make a composition that copies the photobooth ichat background removal process, but with better quality (hoping Apple knocked the quality down to allow faster transmission in ichat).

the thing is i quickly hacked together the composition (from bits inside of the backdrop.plugin), played around with the 'resolution' structure this morning hoping to tweak the quality, everything was working fine. Then it seems when more light entered my office the whole foreground detection stopped working. Quick check backin photobooth and everything works fine there!

Oh what trickery is Apple using now.

Has anyone managed to get this working in QC. i've attached the comp if anyone fancies telling me what foolish thing i'm doing wrong here i would be much appreciative!

PreviewAttachmentSize
backdrop_test.qtz1.36 MB

cwright's picture
Lying, tricksy, false

This patch set is extraordinarily difficult to work with -- I did one project that used it, and I don't plan on doing any more any time soon :)

I don't remember all the details now, but if the camera iris is changing (i.e. the light level changes radically), you absolutely should not have it learn at that point. You also need to leave various inputs high and low to reset it/retrain it, and those are neither obvious nor documented. Keep playing with it, and you might figure something out.

I'm swamped this week, but if I get a moment I'll try to dig up the composition I made that used if, and send it your way if you'd like.

itsthejayj's picture
Honestly this one does seem

Honestly this one does seem to have got the better of me. I'm starting to imagine that Apple are using some control to stop the iris once the background is captured.

Its a relief to hear you were finding it a tad hard yourself chris. If you do find a moment i would love to see how you managed build this in QC.

Did manage to grab the sunglasses and shoot of one screengrab on beach before everything broke though! (see attach.. see my worried expression as i know everything about to go wrong)

PreviewAttachmentSize
Picture 29.png
Picture 29.png1.21 MB

cwright's picture
intermediate

There's a program called "iGlasses" that allows you to lock the iris -- I think this can help with irising issues, if that's all you're up against. I'm not sure how it works exactly (and thus, I'm not sure how to make it into a QC Patch), but this might be a shorter-term solution.

Are you using the compositions available from photobooth, or did you whip something up yourself? I remember having a much easier time just building the composition myself, rather than reverse engineering Apple's composition (which was mostly useless outside of the app designed to use it).

ahoeben's picture
Re: Backdrop - Hackdrop

A little hint that may save someone some time later on:

At least in 10.6.2, you are not going to get the backdrops stuff do much unless you run Quartz Composer as a 32bit app.

A way to get a constant exposure (no autoexposre, no autogain, fixed whitebalance), consider using a firewire camcorder instead of a webcam. Most semi-decent camcorders can lock the exposure, focus and whitebalance, and have less noise than webcams to boot (due to a larger sensor).

gtoledo3's picture
Re: Backdrop - Hackdrop

How did I miss this...? Geez.