Log in

No account? Create an account


About Recent Entries

Password requirements WTF Nov. 23rd, 2009 @ 12:16 pm
Just trying to change my password for $COLLABORATOR's network. Does anyone have any idea what sort of password would satisfy this? I've tried many, many different things :).

Your new password does not meet the following password policy requirements:
  • The password must contain: 0 lowercase characters, 0 uppercase characters, 2 alphabetic characters, 8 unique characters, at least 2 digits, digits in positions: 0, 0 ending digits, at least 2 special characters, special characters in positions: 0, 0 ending special characters. The check is case sensitive.

Update: I found the following command somehow generated a valid password:
$ dd if=/dev/urandom bs=10 count=1 2>/dev/null | uuencode - | head -2 | tail -1

Using Firtree from Python (part 2) Oct. 6th, 2009 @ 04:30 pm
Update: It appears the wordpress/LJ cross poster can't handle indentation. I suggest you just download the full source from the link at the bottom.

Update 2: Fixed it (whit a bit of a hack).

This time we'll learn how to use one of Firtree's most powerful features: kernels. Firtree includes a little C-like language which can be used to specify image processing operations. In essence, it is a function that is called once per output pixel and is asked to compute the colour of that pixel. The kernel can, itself, make use of samplers just like a rendering engine.

Under the covers Firtree compiles all of your kernel functions (and it's the samplers it uses) into one optimised machine code routine.

Firstly, we'll write a Python function which can help us compile kernels. It takes a string containing some kernel source and returns a kernel and a sampler for that kernel. It also prints out an error log if you made a mistake in the syntax:

def compile_kernel(source):
        A simple function which compiles a kernel, checks that the
        compilation succeeded and returns a pair containing the kernel and a
        sampler for it. 

        kernel = ft.Kernel()
        if not kernel.get_compile_status():
                print("Error compiling kernel:")
        kernel_sampler = ft.KernelSampler()

        return (kernel, kernel_sampler)

Now let's actually create a kernel. I'm going to use the example of a desaturate kernel, essentially converting a colour image into a black and white one:

# Create a desaturate kernel.
(desat, desat_sampler) = compile_kernel("""
        kernel vec4 desaturate(sampler src)
                vec4 src_colour = unpremultiply( sample(src, samplerCoord(src)) );
                float luminance = dot(src_colour, vec4(0.299,0.587,0.114,0));
                return premultiply(

The kernel language itself should be familiar to anyone who has programmed in C, GLSL or CoreImage. I'll explain some of the functions we use:

  • [un]premultiply – Firtree uses a pre-multiplied representation internally. That is to say that the red, green and blue components of a colour are pre-multiplied by the alpha value. These functions can be used to undo and redo this operation.

  • sample – Call a sampler. It takes two parameters: one is the sampler to sample from and the second is a 2d vector specifying where to do so.

  • samplerCoord – Samplers have associated with them a co-ordinate transform. This function returns the co-ordinate in the sampler's co-ordinate system of the current pixel.

  • dot – Perform a dot-product between two vectors. In this case, it takes the right combination of red, green and blue components to return a luminance value.

We now need to tell the kernel what sampler to use for 'src'. We do this with one line of Python:

# Wire the lena sampler into the desaturate kernel.
desat['src'] = lena_sampler

Finally we need to tell the CPU renderer to use the desat_sampler sampler instead of the Lena one:

# Use the engine to render the output.
        lena_sampler.get_extent(),         # what area of the input to render
        output_surface                     # into what

The output image is what we wanted, a desaturated version of Lena.

If one wanted to check that Firtree is indeed doing some work behind the scenes, we can get it to print out the compiled assembler for the function. Simply add the following line:

print(ft.debug_dump_cpu_renderer_asm(engine, ft.FORMAT_RGBA32))

Compating the resulting output to the kernel language input clearly shows how much easier it is writing image processing kernels in Firtree! :)

Next time, we'll see how to chain kernels together and let Firtree worry about the details.

The full source code is available.


Using Firtree from Python (part 1) Oct. 6th, 2009 @ 04:05 pm
I'm going to write a set of blog posts all about how to use Firtree from Python. This post is about the simplest thing that you can do with Firtree, load an image and write it back out again.

To get Firtree on Ubuntu Karmic, you can add the Firtree PPA to your system and install the python-firtree package.

Firtree is based around the concept of a sampler. A sampler in essence knows how to get the colour of a pixel given it's location. The location is specified as a 2d vector of floats and the colour is a 4d vector of floats. The colour is made up of the red, green, blue and alpha components scaled into the rage zero to one.

Our first example will load our input, the ubiquitous Lena, into a Cairo surface and create a sampler which knows how to get data out of that surface:

import cairo
import pyfirtree as ft

# Firstly, load the lena image
lena_surface = cairo.ImageSurface.create_from_png('lena.png')

# Create a sampler for the surface
lena_sampler = ft.CairoSurfaceSampler()

So far, so easy. Firtree also has the concept of a renderer which knows how to run over each pixel in an output, ask the sampler for the appropriate pixel colour and write it out. Firtree ships with a CPU based renderer which uses LLVM to compile your pipeline down into efficient code and run it over all the CPUs in your machine. Let's make use of that:

# Create an output surface similar to the input
output_surface = cairo.ImageSurface(
lena_surface.get_height() )

# Create a CPU render engine.
engine = ft.CpuRenderer()

# Use the engine to write the input to the output.
lena_sampler.get_extent(), # what area of the input to render
output_surface # into what

# Write the output

And that is it, you have written some code that loads an input file and writes it back out to another file. Next time you'll learn how to make use of the main feature of Firtree: image processing kernels.

The source code for this example is available.


Tomorrow's World Sep. 14th, 2009 @ 10:09 pm
The BBC Archive have released a number of old Tomorrow's World episodes. One particular episode has the infamous 'beachball' opening sequence. The moment I saw that I was immediately transported back to my childhood, having just got out of the bath (Tomorrow's World day was bath day) and sitting downstairs freshly washed in a dressing gown.

Tomorrow's World is one of my happy recollections of a time when the BBC's science output actually excited and engaged me. The pre-Peter Snow and Phillipa Forrester Tomorrow's World was an excellent programme that celebrated the innovation and optimism about technology before the cynical 90s killed it all. Similarly I remember the two-programme Horizon special on the Voyager space probes as an excellent high point before the 'single scientist against the world with strange camera angles and visual metaphors' rot that has reduced the once proud flagship science programme into the stupid dumbed down claptrap is is now.

Blog moved server Sep. 14th, 2009 @ 10:03 pm
The canonical source for this blog has moved server. Hopefully all the cross-posting magic has retained its power. This post acts as a test for this :).

Other entries
» Second night in Edinburgh

The second night in Edinburgh is about to begin. The first one doesn’t really count given that the entire day was pretty much lost to travelling. The train trip up was fun though. Having people to talk to, and space to breathe really does make a hell of a difference. The second leg (Stevenage to Edinburgh) took around 6 hours but I hardly noticed.

Today we had a bit of a practise in the morning followed by a relaxing day to prepare us for the stress to come. Laila, Alex, Jon and I went to the seaside. Photos of which can be seen on the Project Steve blog. After the beach, there was a well deserved pub.

I really love Edinburgh. The quality of the air up here is always so crisp and refreshing. Just breathing makes me feel like I’m cleaning my insides out.

Tomorrow is our get in. Luckily it is at the civilised time of 2pm but before that I have a publicity meeting with TSOB at 12pm and a Steve meeting at 10am. This, coupled with the inevitable flyering, means I should be pretty busy tomorrow.

The Internet connection here can be described as ’spotty at best’. My phone, when it has 3G + HSPDA is absolutely wonderful. When it has 2G, it sucks donkey balls. Luckily I have found a magic location within my room where 3G goodness can be had. One bar of goodness, but goodness nonetheless.

» Problem solved: PyGObject versions on OS X

If you, like me, are trying to port a big GObject-based codebase with Python bindings over to OS X you may have run into the problem that the py-gobject port links agains Python 2.4. If, like me, you use CMake as a build system you’ll know that it is tricky to persuade CMake to do the same. The solution is to install the py25-gobject port.

» Seen in the lab

Someone left an anagram on the whiteboard at work that we had to solve. As everyone knows, anagrams only have a single unique solution and we found it.

You should've seen what it replaced

We also added a picture of Nick the Filthy Pencil. We work hard. Honest.

» Once Upon a Time Trailer

Here is a trailer for Once Upon a Time that I’m in for a bit of. It is terribly fine and Cat did an amazing job of learning all her Final Cut Pro and Blender-fu to do all the CG.

Once you’ve seen An Improvised History of Absolutely Everything, make sure to check this out too!

Update: The original script is also available if you want to compare the final product to it/discover some in-jokes :)

» This time last year

tl;dr; I just need to bloody well cheer up.

It has been said by a wiser sage than I, I think perhaps it was Kenny Everett[1], that there are two sorts of comedians: those with some mental illness and those that are dead. It is undoubtedly true that comedy is bad for the mental health; the yearly trip to Edinburgh neatly shines a light on this fact for me.

This time last year I faced down a rather severe depressive meltdown. The proper sitting-in-the-corner-rocking-back-and-forth sort. It is funny seeing the blog posts leading up to that moment. In retrospect the explosion was obvious; the undirected low-level anger at people, the growing levels of frustration and impotence at the world and the feelings of self-doubt all all important indicators. It is most telling, I think, that there are no posts between the 1st August 2008 and 28th September 2008. Two months which were hell for me.

I am hoping that this year will be better all around. Last year I very nearly exploded all over my friends in a very nasty way that would almost certainly be bridge burning. The incredible stress of Edinburgh didn’t help here. Indeed, in the last few days of rehearsal week I was convinced that I would make people far happier if I just went away; I truly believed that everyone I knew hated me. Certainly my hazy recollection of the month of August is alternating between rage and weeping in corners.

In fact my brain was so broken that I have only two clear memories of the entire rehearsal week. One is the audio book of 2001: A Space Odyssey, which I played on continual loop to and from the rehearsal venue. The other is a small rock. This rock sits by the entrance to the Long Room in New College, Oxford. It is a small, unremarkable, rock about the size of a clenched fist. It sits roughly where one might expect to find a stop or wedge for the main door into the building.

This rock was my companion in the dark times. The entrance to the Long Room is a small, shaded corner deep in the heart of New which is ideal to hide in. When I was steeling myself against the vicissitudes of my own brain, I would fixate on it and give it my full attention. Even now I think I could draw a reasonable picture of this rock. If there were such a thing as telekinesis, this rock would long ago have been propelled into orbit.

I went on a Project Steve weekend a few weeks ago. We practised in New College. The rock was still there. In some strange way I felt as if I had come to see an old friend.

So why am I prattling on about this? Some form of catharsis? An attempt to exorcise demons by shouting into the black void of the Internet? No, not really. Consider it more a belated apology to anyone I might have pissed off last year at around this time.

And perhaps it is some form of advanced apology. Depression can take many forms, as I’m sure anyone who’s dipped their toe into it’s murky waters can attest. For me, it is most definitely directed at complete dissatisfaction with society and a low-level hatred to those who I should probably view as closest.

Ironically, it is not this that proves problematic. I can deal with my own brain. We’ve been close bedfellows for almost three decades now so I should know how to knock it into shape. It is harder to deal with the guilt my behaviour towards those around me provokes. For you see, dear anonymous Internet hoards, I am not actually someone who enjoys being snappy and aggressive to people. I most certainly don’t want to load people up with my own emotional baggage. It isn’t their problem, why should they have to deal with it? Thus I am stuck in the awkward position of being absolutely indefensibly horrible to people and then not feeling able to excuse myself for the fear that they’ll resent having to ‘deal with the madman’.

Like it or not, mental illness makes people feel uncomfortable. If I am in a mood, I think it is fairly justifiable for people to be of the opinion I should just bloody well cheer up. I am, almost by definition, being unreasonable, both in behaviour and the implicit requirement that people accept that behaviour because of some nebulous ’sad disease’ I profess to have. It is people’s reticence to do this that makes me feel worse. If the boot were on the other foot, so to speak, I’d worry about whether I should try to fix the stupid, paranoid problem the other person has or whether to ignore their behaviour and hope they go away. I would certainly wish that they would just sort their own brain out and stop burdening me[2].

In fact, if I appear hostile, cynical, angry, combative, sarcastic or snide, it may surprise you to know that what I’d probably really like is someone to take me into another room, give me a cup of tea, a gentle cuddle and talk about something pointless for a bit. I really am that much of a soppy git. I don’t want you to sort out any stupid problem I might have; it is not yours to sort out. Instead I am probably just scabbing over my own fears that everyone hates me :).

The good news is that in no sense has the cloud descended as much as it did last year. But it is hovering over the horizon. Should it rear it’s ugly head for this year’s festival, I know that I just need to get away. I’ll just go away for a bit. Maybe an afternoon, perhaps overnight. Perhaps all I need is to be taken away from people and be brought a beer (you know who you were last year…).

All in all the lesson learned from last year: cheer up and stop being a grumpy bastard. The sub-lesson is ‘find someone willing to snuggle up and cuddle the stress away’. This year, those people will be a bit thin on the ground!

[1] I can find no reference, but he seems to have been chatty about such things.
[2] With the exception of those I love. I’d view an acceptable definition of love as ‘being as selfish for another person as yourself’. Certainly being willing to recognise someone else’s problem as your problem satisfies that.

Top of Page Powered by LiveJournal.com