Archive for the 'Programming' Category
Javascript Font Detection
This looks interesting — Browser font capability detection using javascript to check for the rendered size of a string, if it’s the same as the default, then it’s probably not available.
No commentsCompiling PIL with the G4 tiff patch, Encore
I had to compile the Python Imaging Library again (first time), this time on OSX Tiger, and I found that the previous patch that I’d published was missing some bits. In the meantime, PIL had revved to 1.1.6. I also needed to figure out how to compile libjpeg and libtiff in universal form.
The updated PIL Group4 tiff read patch is here. This is a very basic update from this patch, which was for 1.1.4. I don’t vouch for it’s correctness, but it’s working for me. YMMV.
I went back and forth on compiling the libraries in a universal build and trying to make the PIL a ppc-only build, but in the end, the universal libraries were easier to do. This page got me there for both of them.
For libjpeg, run the configure, then edit the makefile to set the c and ld flags:
CFLAGS= -O2 -I$(srcdir) -arch ppc -arch i386 -isysroot /Developer/SDKs/MacOSX10.4u.sdk LDFLAGS= -Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk
Then make as normal.
For libtiff, set the environment variables:
export SDK=/Developer/SDKs/MacOSX10.4u.sdk export CFLAGS="-isysroot ${SDK} -arch ppc -arch i386" export CXXFLAGS="-isysroot ${SDK} -arch ppc -arch i386"
and run the configure command with the following options:
./configure --disable-dependency-tracking \ CXXFLAGS="${CXXFLAGS} -DMACX=1 -DWORDS\_BIGENDIAN=\_\_BIG\_ENDIAN\_\_" \ CFLAGS="${CFLAGS} -DMACX=1 -DWORDS\_BIGENDIAN=\_\_BIG\_ENDIAN\_\_"
PIL needs the private libtiff headers, so you need the build directory around and included in the library pointers section of the setup.py file. The other libraries that PIL uses are included in OSX: freetype is included in the X11 packages and zlib is in the base developer install. My library pointer section looks like:
FREETYPE_ROOT = libinclude('/Developer/SDKs/MacOSX10.4u.sdk/usr/X11R6/') JPEG\_ROOT = '/Users/erics/Sites/wce-trunk/client/depends/jpeg-6b/' TIFF\_ROOT = '/usr/local/lib', '/Users/erics/Sites/wce-trunk/client/depends/tiff-3.8.2/libtiff/' ZLIB\_ROOT = "/usr/lib", "/Developer/SDKs/MacOSX10.4u.sdk/usr/include" TCL\_ROOT = None
(Where I’m ignoring TCL). You’ll need to edit the paths for the tiff and jpeg roots.
Finally, you should be able to build the PIL with the command “python setup.py build\_ext -i”. The selftest.py should run cleanly and not error out. The install is then the standard “sudo python setup.py install”.
No commentsOn Colorspaces
and towards a more color managed workflow.
A while ago I posted about an article that had a lot of detail on colorspaces, profiles, and what works both on the web and in print. One of the takeaways from that was that my workflow was not color managed, except for (possibly) on the mac and probably on my laptop.
Which is a bummer, since the laptop has proved itself to have a really wonky color response profile, at least as compared to what gets printed and any other display I have access to. For example, custom white balance in the camera is better than doing anything by eye on this machine. Print matching was a nightmare. It turns out that there’s a monitor profile from 10.4.7 that is a lot closer to what the prints were producing, so I’m using that for now. But still.
The takeaways were that anything destined for the web or print probably should be in sRGB, that the camera should probably be in AdobeRGB (a wider color space), and everything at every stage should be tagged with the appropriate profile. Finally, I should get a colorimeter and at least get the best profile I can on this monitor.
I’m still using a raw converter that’s using the coregraphics filters to do my first cut at the images. It’s good enough for most of the web destined images, unless I need to do B&W conversion or edits. It turns out that it’s not that hard to hack in support for specific color spaces, instead of the generic ones.
Since I don’t see this well represented in google: Obj-C following:
CGColorSpaceRef cs, default_cs; CGDataProviderRef profile; NSDictionary *options; float ranges[] = {0.0,255.0,0.0,255.0,0.0,255.0}; default_cs = CGColorSpaceCreateDeviceRGB(); profile = CGDataProviderCreateWithURL((CFURLRef) \ [NSURL fileURLWithPath:@"/System/Library/ColorSync/Profiles/sRGB Profile.icc"]); cs = CGColorSpaceCreateICCBased(3, ranges, profile, default_cs); options = [NSDictionary dictionaryWithObject:(id)cs forKey:kCIContextOutputColorSpace]; context = [CIContext contextWithCGContext: [[NSGraphicsContext currentContext] graphicsPort] options: options];
Where previously, I was passing in no options (or more precisely, nil), this time I’m passing in a dictionary specifying an output color space, initialized to a system profile. This will convert anything that is painted into the context into sRGB, and include the profile in the output image. It’s apparently also possible to use a Lab color profile, but I’m unsure how useful that would be since the only other Lab aware app I know of is Photoshop.
Looking at the camera data, the RAW files are tagged with AdobeRGB, 16 bit which is a bit of strangeness, since AdobeRGB is an 8 bit space. But, since it’s RAW, it really doesn’t matter, since the RAW files are open to so much interpretation anyway. If I do switch to JPEG, it should still be in AdobeRGB, so I’ll capture as much of the gamut as possible.
I’m curious how much of a difference this will make. It certainly feels like the right thing to do.
No commentsWebsite Performance Tweaks
A good summary of how to speed up the delivery end of a website, once you’ve got the page generation times under control: Learning the World » Website Performance Tweaks
- Reduce requests, aggregate images using css sprites, reduce the number of style sheets and javascript.
- Compress css and javascript
- Move the javascript to near the closing body tag, if possible, to allow for the page to render before requiring that all the javascript be loaded.
Making bash work correctly
The Non-Annoying Terminal Mini How-To & Fun with shopt
shopt -s checkwinsize
Makes bash check the window size after every command, so that it never wraps the command line in a completely messed up manner.
Makes you wonder why there isn’t a ‘just act sanely’ option somewhere, but I’m sure that this was originally a backwards compatibility thing.
No commentsOpenID – quickly
How to turn your blog in to an OpenID
A quick run through on how to use your blog, 2 lines of html, and an authentication server to use OpenID.
No commentsStill more….
How to add an AFP/Appleshare server export using netinfo: osxfaq. And automounting. And for good measure, another link.
No commentsMore Techie Stuff
The Hardened-PHP Project looks quite interesting. I’m going to have to test some of this out and see if it might be of use for deployment. (via Tim Bray)
The Dojo charting engine looks like something that I could use in place of some of the php/libgd stuff that I’m doing to generate sparklines. The downside, it’s everything but Safari. And it’s probably even bigger than the total of all of the sparkline graphics that I’m downloading.
And in the same vein, there’s the more generalized dojo vector drawing engine for doing vector graphics in everything but Safari.
No commentsBookmarklet for Amazon Associates
Backup Brain gives us a bookmarklet that lets you credit your amazon purchases to a specific associates account.
No comments