Render natively

I would like to render natively i.e. via a C dll that I have wrapped
using SWIK.

So I want my c code to receive a buffer that it can render to, and then
have WXruby display this memory buffer/bitmap.

Can anyone advise me what would be the best method for doing this, to
save me having to find out the hard way.

Many thanks,
Jim.

Jim flip wrote:

I would like to render natively i.e. via a C dll that I have wrapped
using SWIK.

So I want my c code to receive a buffer that it can render to, and then
have WXruby display this memory buffer/bitmap.

A drawing context (whether an in-memory buffer, an on-screen canvas, or
a printout) is represented by a DC [1] instance in wxRuby. MemoryDC is
the specific class for in-memory buffers.

However the API and class is cross-platform and specific to WxRuby, so
you’re not going to be able to pass this in directly to your dll. You
don’t give a lot of info about the way your API works, but I’d think
probably the easiest way would be to have your dll render to a ruby
String in a recognised image format (wxRuby understands PNG, TIF, JPG,
BMP, TGA) then wrap this in a ruby StringIO object.

Call Wx::Image.read [2] to load this image into an object, then do
Wx::Bitmap.from_image to convert it to a windows bitmap that can be
rendered on screen. Lastly, simple draw this onto a window surface using
its paint method. Have a look at the example in samples/drawing/image.rb
to see the basics of writing an image to screen.

Can anyone advise me what would be the best method for doing this, to
save me having to find out the hard way.

This should probably work, but there’s a few other options should this
not be suitable. Also have a search through the archives as there have
been a few threads about rendering images from external libraries (eg
ImageMagick).

cheers
alex

[1] http://wxruby.rubyforge.org/doc/dc.html
[2] http://wxruby.rubyforge.org/doc/image.html#Image_read

Thanks for the pointers, I think I will try using a bitmap and it’s
set_data method as this should be simple to try out but may be a bit
slow.

Thanks,
Jim.

Jim flip wrote:

Thanks for the pointers, I think I will try using a bitmap and it’s
set_data method as this should be simple to try out but may be a bit
slow.

If you can avoid composing or decomposing the image data in Ruby (using
pack etc) this will be pretty fast - for example, if you can get your
extension to emit image data in that format. Then it’s just a C-level
memcpy going on.

Similarly Image.read should be fast if you can get your extension to
produce a known image format. These wxRuby methods are not particularly
far off the native C library functions in libtiff, libpng etc

alex