IronPython supported in GIMP#January 16, 2007 at 8:01 pm | Posted in C#, GIMP, Programming | 3 Comments
A few days ago I already blogged on my initial experiments with IronPython. Today I actually implemented the first plug-in written in Python for GIMP#. Currently it’s only available in CVS, but it will be part of GIMP# 0.12. This plug-in does a very straightforward calculation: it calculates the average color of an image and sets the complete image to this average value. I already wrote such a plug-in in C#. Massimo Perga has ported the plug-in to Java to show that we can support Java as well, using IKVM. And now we also support Python as a third language in GIMP#. Some observations:
- I haven’t figured out yet how a Python class can inherit from an abstract C# base class. A quick and dirty solution is to introduce a non-abstract C# class in between to solve this. For the moment this works.
- One has to do explicitly convert Python lists (for example the list with commandline arguments: sys.argv) to an Array in the .NET namespace. I hope that in future IronPython versions there will be implicit conversions.
- I haven’t figured out yet if you can use anonymous delegates in IronPython. For the moment this is solved by introducing a couple of extra member functions
- I still have to find out how you can compile a .py file without actually executing it!
- One thing very annoying: somehow IronPython couldn’t see the difference between multiple overloads in one of my GIMP# functions. I had to give them explicit names in order to solve this😦
The best (or worst) bit I kept for the last: I did some performance measurements on the same plug-in written in C# and IronPython. Since they are so similar and they are both run on top of the CLI I would expect similar performance. However for this (micro) benchmark the C# implementation is 4 times as fast as the IronPython version (using Mono on Linux). I don’t have an explanation for this yet, apart from the obvious conclusion that the C# compiler does a much better job than IronPython. Also the size of the IronPython executable is about twice the size of the C# version which I find remarkable as well.
Last remark: since Max already ported this plug-in to Java I finally need to install IKVM so I can compare the results of the three versions. I wonder if there will be more suprises…