Skip to main content.

Saturday, July 04, 2009

GD2 is a very cute library, and a must have for site developers (very used in PHP and perl....). As it is a very clean C library, with a very object-oriented spirit (despite it's plain C), It's the first target for the new Falcon automatic binding generator. The only problem is that it uses ANSI C FILE* streams to read and save images. It has actually also the ability to load from buffers, but providing a direct mapping is definitely a plus.

On Unices, that's not a problem. dup() + fdopen() provide a direct way to form an ANSI C FILE stream out of the system stream ID which I use in Falcon::Streams. On windows, I use System HANDLE (CreateHandle &c) to drive the Falcon::Streams.

But I found this snippet:


#include
#include
#include

HANDLE hFile = CreateFile(...);
int handle = _open_osfhandle((LONG)hFile, _mode);
FILE* f = fdopen(handle, szMode);


With this, I can virtualize a function down in the Stream falcon class returning an integer system stream or raising an error if the stream isn't mapping a system file (i.e. streams can be net-bound or memory bound). The GD binding will have to wait the next version of falcon to use Stream oriented load/save functions, but I should release that next version quite soon.

Comments

No comments yet

Add Comment

This item is closed, it's not possible to add new comments to it or to vote on it