GDI+ Pixbuf Loader: The art of getting native

One of the biggest problems that I’ve run into during the work of getting a sane building/release process for Gtk+ on windows, is the fact that it has a very Unix tied dependency tree:

  • Gtk+ depends on libjpeg, libpng, libtiff, pango, cairo and Glib.
  • Glib depends on gettext.
  • libtiff depends on libjpeg
  • libjpeg and libpng depends on zlib
  • pango depends on cairo

Now, zlib and libjpeg are specially problematic to build for a Win32 target, and even more problematic if they’re built on a cross compilation environment. So we wrote a few patches to workaround the issue, but the patches are ugly and not suitable for mainstream inclusion at all. So we were kind of screwed.

Until dom and tml had a great idea: why not write a pixbuf loader using the native win32 api to load images?



GDI+ is the imaging API for Windows XP (installable on 2000 and 98/Me), its antecessor, GDI,
would only load jpeg and non transparent png (remember the IE transparency problem? blame old GDI).

Now, GDI+ has some shortcomings, the most important being that it’s not included on MinGW 32, so cross compilation is not an option at a first glance. Another one is that it’s not included on Windows 2000 or below, not a big deal since there is an installation package for 2000 and 98/Me, and Gtk 2.12 is not supporting 98 anymore.

So, what do we do? Dom enlightened me with the wonders of LoadLibrary (dlload) and the work he did with Jordi Mas on GDI+ support for AbiWord. So we can load the functions pointers with their prototypes on runtime by doing LoadLibrary("gdiplus.dll"); take that lack of linking information!!! I borrowed some code from wine (which is LGPL as well) so I could figure out the structs and the function prototypes.

Some msdn research, some help from dom and there we go:

io-gdip_alpha1.tar.gz
$ git clone http://www.gnome.org/~aruiz/gtk+/io-gdip.git

It doesn’t work yet really, all the Win32 api pieces are already there (I get the information and all the ARGB pixels of the images), but for some reason the Gdk.Pixbuf I create is not properly received by the application, I’m gonna need some help from dom or other pixbuf hero to finish it.


The result so far (there is supposed to go a background)

If I get this into a good shape, doing something similar for Mac OS X wouldn’t be a big issue I guess.

If you want to help or just support the cause morally, just hang around #win32 at irc.gimp.org, where all the cross platform lovers are!

Update: I forgot Cairo and Pango dependencies, oops.

Advertisements

8 thoughts on “GDI+ Pixbuf Loader: The art of getting native

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s