[Image-SIG] Support for RLE8/4 MS BMP files

John Popplewell john at johnnypops.co.uk
Thu Aug 18 01:48:40 CEST 2011

Hi all,

my first post to this list. I'm a fairly long-time Python user, mostly
on Windows systems (sigh), and use PIL extensively.

Recently, an application of mine, used by one of my customers,
encountered a series of MS BMP files masquerading as JPEG images. Most
of them loaded OK, but about 50 of them (out of ~10,000) wouldn't - they
turned out to be RLE8 encoded. We have no control over what we are sent,
and a possible work-round, using wxPython, didn't work-out as it's also
a really old version.

As I've come across a few RLE BMP images over the years, and I really
needed it to work for my customer, I decided to add the functionality to

For various practical reasons, the application is stuck using
Python-2.3, PIL-1.1.4 and wxPython-2.4, so I had fun re-installing
Visual Studio 6, building zlib and libjpeg and getting PIL to compile.

I got a basic RLE8 decoder working quite quickly, and looked around for
test-images, finding these:


I also noticed that the Mozilla Firefox project had added extensive BMP


and turned out to handle all the test images.

Anyway, lets just say I got a bit carried away and added support for
RLE8 and RLE4 compression as well for a few oddities, finding a couple
of (fixed) bugs in PIL-1.1.4 in the process. One of the test images,
'width-times-height-overflow.bmp', still causes a nasty seg-fault in

I've got a current HG version of PIL and I'm building with MSVC on XP,
but I can test on Linux too.

My question is, how do I go about contibuting my new 'BmpRleDecode.c'
and associated changes?

best regards,
John Popplewell.

More information about the Image-SIG mailing list