Hi scriptaholics
It is becoming increasingly evident that scripting support in PixInsight has tremendous possibilities that surpass by far my initial expectations, when I embedded the Mozilla JavaScript engine (SpiderMonkey) in late 2006.
As we devise more applications of scripts on the PixInsight platform, we see that scripts are now addressing problems that go far beyond simple batch processing, trying to solve complex image processing tasks.
However, scripts in their current form suffer from a severe bottleneck: when we have to process millions of pixel samples, interpreted code is too slow as to represent a feasible solution in real-world cases.
So, an idea came to my mind a few days ago. Why not allow scripts lo load and execute (in a reasonably secure way) small modules compiled to native code? The idea is quite simple:
1. Consider small shared objects (.so files under Linux/UNIX/OSX; .dll files under Windows) that implement relatively small routines written in C (or C++ with a C front-end). These routines implement the bottlenecks of our scripts. For example, the typical loop that iterates through every pixel in an image. Nothing prevents us from parallelizing these routines, of course.
2. Define a standard protocol to communicate these small shared objects with the JavaScript runtime and the calling script. More specifically, define a collection of C function prototypes to solve common pixel mass-processing tasks, so that the JS runtime can look for them into the shared objects.
3. Define a standard way to load and unload these shared objects, to know if a given standard routine is available (as defined in point 2), and to run standard routines from JavaScript code. Of course, the script would "call" these routines with parameters that specialize them for a particular image. Easy example. Let's say that one of these routines is:
void forEachSample( float* samples, int width, int height );
Then the script could call it with samples = the beginning of a channel of a particular image, and width, height = the dimensions of the image.
That's the idea, basically. Come on, expose your thoughts here. I think that if we manage to implement something like this well, then scripts can be real solutions to real problems in PixInsight. With purely interpreted code, we are very limited.
By the way, how these small native objects could be called? The words "script" and "gadget" come to my mind (because I tend to think that the name should end with the -let suffix), but I don't know how to link them. Any ideas as for the name of these little beasts?