Wednesday, April 06, 2005

Free JPEG API on Windows Mobile 2003

Have you been shopping around for JPEG support on CE 4.2?. There is some JPEG support in .NETCF but if you need to rotate or actually encode from a bitmap, you find yourself wanting more.

Microsoft's public answer to this gap seems to be CF2. This sort of begs the question "what does Microsoft use now in their own products?" We were wondering about that and noticed a DLL with the suspicious name of JPEG.DLL on Windows Mobile 2003 devices (it wasn’t there on PPC 2002). Like any normal undocumented API scavenger, we immediately ran dumpbin to see the function list. This doesn’t tell you much about the arguments you need to pass, but a quick check with Google found a match on the function names.

It turns out that JPEG.DLL is a compilation of free routines from the Independent JPEG Group. Self described as "an informal group that writes and distributes a widely used free library," IPG provides a lot of interesting JPEG information including FAQs, example implementations and complete source. And the best part -- the library is already there in ROM. It will cost you exactly $0 and 0 bytes of precious mobile memory to add full JPEG support to your apps! We whipped up a C++ wrapper (and with a bit of pinvoking, a .NET wrapper), and had the JPEG library working like a charm.

The IPG library is free though it does require some basic acknowledgement in your distribution. If you plan to distribute software that encodes and decodes JPEG, be sure to do your homework on the issue of royalties and patents. See this JPEG patent article from The Register based in the UK.