toxicsoftware.com

RANDOMIZE USR 0

toxicsoftware.com header image 2

AcornImage

February 19th, 2008 · 7 Comments · Default

It was just your typical InterfaceBuilder 3 window…

AcornImageIB3.png

with your vanilla NSImageView…

AcornImageView.png

referring to an image file within an Xcode project…

AcornInXcode.png

Holy Cow! An Acorn file? Does that mean I can use Acorn files directly in Interface Builder 3? Does that mean you’ve written an NSCustomImageRep that understands the Acorn file format? Does that mean I can use Acorn files directly in my Cocoa projects? And that means I no longer have to keep exporting these bloody files as pngs so I can use them in Cocoa, right? Will this give rixstep some ammunition to go apeshit insane about?

Yes! Yes!! Yes!!! Yes!!!! Yes!!!!! Almost certainly.

Not only does Gus Mueller generously provide details about the Acorn file format, he has even released the source code to his Acorn Quicklook plugin. This gives me everything I need to convince NSImage to load Acorn files.

You might well be asking yourself why. I was getting annoyed with having to constantly keep exporting original Acorn images as pngs or TIFFs so I could use them in Xcode. I’m prototyping a new application that uses a lot of custom UI elements. These elements are made up of one or more pngs, some of which needed a lot of tweaking and attention to detail to get right. Acorn is perfect for UI work (although it needs more than 2000% zoom! cough) but having to export as png (or another format that Cocoa understands natively) and manage two sets of images (original Acorn, exported png) was turning into a pain.

I’ve taken Gus’ QuickLook code and wrapped a small NSCustomImageRep around it. Very small. I’ve repackaged it up as a Framework so you can refer to it from an Interface Builder 3 plugin. This gives you the ability to do this:

[NSImage imageNamed:@"IAmAnAcornFile"];

You should be able to use Acorn files anywhere an NSImage is used. Just embed your Acorn files in your XCode project resources and refer to them by name in your NIBs or in code.

I’ve put the code on my public googlecode.com subversion repository.

I’m currently on the fence about whether it is a good idea or not to ship your application with Acorn images. It certainly makes sense to me to use them during the interface design stage of application development. Once the user interface churn settles down I should be able to finalize the images and convert them to pngs or whatever (keeping the originals of course).

A best of both worlds solution might be to make a little command line tool that can convert Acorn files:

#!/usr/bin/python
from AcornImage import *
# Everything else is an exercise for the reader.

And then automatically convert from Acorn to whatever during the Xcode build process. I might investigate this technique at a later date. But for now - have at it.

Tags: ····

7 responses so far ↓

  • 1 Christopher Humphries // Feb 19, 2008 at 12:28 pm

    Wow, awesome! Great job man, helps with workflows with Acorn.

  • 2 Manton Reece // Feb 20, 2008 at 10:01 pm

    This is very cool. Well done.

  • 3 jcburns // Feb 20, 2008 at 10:18 pm

    I didn’t even know that Acorn had a QuickLook plugin until you posted this framework…thanks!

    Works great with f-script, my favorite informally-screw-around-with-cocoa tool.

  • 4 Dan Weeks // Feb 20, 2008 at 10:45 pm

    This. Is. Awesome. Great work man.

  • 5 schwa // Feb 20, 2008 at 11:24 pm

    Enough with the awesomeness. Gus did all the real work. I just had the idea and adapted an existing class.

    You should all go to flyingmeat.com and tell Gus just how wonderful Acorn is.

  • 6 ken // Mar 7, 2008 at 12:36 am

    Cool beans, but the class hierarchy makes me a bit nervous..

    NSCustomImageRep isn’t a class you typically subclass - it’s a concrete class whose purpose in life is to _delegate_ drawing.

    This image rep should be a subclass of NSImageRep. Cool though. :-)

  • 7 schwa // Mar 7, 2008 at 12:38 am

    ken, typically yes. but nothing prevents you from doing it like this. :-)