[fxruby-users] Extending fxruby with c++ operating on an FXImage?

Lyle Johnson lyle at knology.net
Fri May 13 09:01:31 EDT 2005

On May 3, 2005, at 7:58 AM, Paul Melis wrote:

> Hello,
> I'm currently doing a little app that works on images and corrects 
> lens distortion. It is fully written in c++ using fox (1.4), but I'm 
> interested in converting it to ruby+fxruby. However, the c++ code that 
> does the actual work on the images will need to stay c++, for 
> performance reasons. It currently isn't too speedy, so converting that 
> part to ruby too will make it to slow to use.
> The image processing actually works on an input FXImage object and 
> outputs a new processed one. I'm wondering how easy it would be to 
> create a ruby extension that interfaces with the processing code while 
> still allowing the newly created FXImage's to be used by fxruby (as I 
> want to display the results obviously). Will a simple swig interface 
> definition for a c++ function like
> FXImage* processImage(const FXImage* img, <processing parameters>);
> be enough or does fxruby do more tricks underwater that I would need 
> to duplicate?

Unfortunately, there's a lot more to it than that and it's not 
something that can be easily simplified at this point. What I am 
wondering, however, is you could compromise by still doing all of the 
compute-intensive image processing in your C++ extension code and then 
construct the new FXImage object back in the Ruby layer. I haven't put 
as much thought into this as you have, obviously, but I'm thinking of 
something long these lines:

	memBuffer = inputImage.data
	colorArray = memBuffer.data # an array of FXColor values
	newColorArray = processImageData(colorArray, ... other parameters ...)
	newImage = FXImage.new(app, newColorArray, ...)

In in approach like this, your extension code (that implements the 
processImageData method) doesn't know anything about FOX or FXRuby per 
se, it's just manipulating a Ruby Array of color values (32-bit 
unsigned longs).

Hope this helps,


More information about the fxruby-users mailing list